์ž๋ฐ”๋กœ๋งŒ ํ’€๋‹ค๊ฐ€ ํŒŒ์ด์ฌ ๊ณต๋ถ€ํ• ๊ฒธ ์ด๋ฒˆ ๋‹จ๊ณ„์—์„œ๋Š” ํŒŒ์ด์ฌ์œผ๋กœ๋งŒ ํ’€์—ˆ์Šต๋‹ˆ๋‹ค.

 

 

1 5086 ๋ฐฐ์ˆ˜์™€ ์•ฝ์ˆ˜ ์„ฑ๊ณต์ถœ์ฒ˜๋‹ค๊ตญ์–ด๋ถ„๋ฅ˜ 7239 10516 70.288%
๋ฐฐ์ˆ˜์™€ ์•ฝ์ˆ˜๋ฅผ ๋ฐฐ์šฐ๋Š” ๋ฌธ์ œ

def test(num01, num02) :
    if num02 % num01 == 0 :
        print("factor")
    elif num01 % num02 == 0:
        print("multiple")
    else :
        print("neither") 
        

while True :
    number01, number02 = map(int, input().split())
    if number02 == 0 and number01==0 :
        break
    test(number01, number02)
    

2 1037 ์•ฝ์ˆ˜ ์„ฑ๊ณต๋ถ„๋ฅ˜ 12488 25527 49.747%
์•ฝ์ˆ˜์˜ ์„ฑ์งˆ์„ ํ™œ์šฉํ•˜๋Š” ๋ฌธ์ œ

testNum = int(input())
array = list(map(int,input().split()))
a_max = max(array)
a_min = min(array)
print(a_max * a_min)

3 2609 ์ตœ๋Œ€๊ณต์•ฝ์ˆ˜์™€ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ ์„ฑ๊ณต์ถœ์ฒ˜๋ถ„๋ฅ˜ 23552 39661 62.096%
์ตœ๋Œ€๊ณต์•ฝ์ˆ˜์™€ ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ

def firstTest(a,b) :
    if a<b :
        temp = a
        for i in range(a) :
            if b%temp == 0 and a%temp == 0:
                break
            else :
                temp -= 1
    else :
        temp = b
        for i in range(b) :
            if b%temp == 0 and a%temp == 0:
                break
            else :
                temp -= 1
    return temp

def secondTest(a,b,x) :
    print((a//x)*(b//x)*x)


a, b = map(int,input().split())
x=firstTest(a,b)
print(x)
secondTest(a,b,x)

4 1934 ์ตœ์†Œ๊ณต๋ฐฐ์ˆ˜ ์„ฑ๊ณต๋ถ„๋ฅ˜ 15809 27243 59.910%
์œ ํด๋ฆฌ๋“œ ์•Œ๊ณ ๋ฆฌ์ฆ˜์œผ๋กœ ๋” ๋น ๋ฅด๊ฒŒ ํ‘ธ๋Š” ๋ฌธ์ œ

def firstTest(a,b) :
    if a<b :
        temp = a
        for i in range(a) :
            if b%temp == 0 and a%temp == 0:
                break
            else :
                temp -= 1
    else :
        temp = b
        for i in range(b) :
            if b%temp == 0 and a%temp == 0:
                break
            else :
                temp -= 1
    return temp

def secondTest(a,b,x) :
    print(a*b//x)

T = int(input())

for i in range(T) :
    a, b = map(int,input().split())
    secondTest(a,b,firstTest(a,b))


5 2981 ๊ฒ€๋ฌธ ์„ฑ๊ณต์ถœ์ฒ˜๋‹ค๊ตญ์–ด๋ถ„๋ฅ˜ 3473 18733 20.916%
N๊ฐœ์˜ ์ˆ˜๋ฅผ M์œผ๋กœ ๋‚˜๋ˆ„์—ˆ์„ ๋•Œ, ๋‚˜๋จธ์ง€๊ฐ€ ์ „๋ถ€ ๊ฐ™์€ M์„ ์ฐพ๋Š” ๋ฌธ์ œ

from math import gcd, sqrt

T = int(input())
array = [input() for i in range(T)]
array= list(map(int, array))
array.sort(reverse=True)

answer = list()
for i in range(1, len(array)) :
  x = array[i] - array[i-1]
  answer += [(gcd(x))]

for i in range(1,len(answer)):
      answer[i] = gcd(answer[i], answer[i-1])

x = int(answer[-1])

a=[]
for i in range(2, int(sqrt(x)) + 1):
    if x % i == 0:
        a.append(i)
        a.append(x // i)
a.append(x)
a = list(set(a))
a.sort()
#a.remove(1)
for i in a:
    print(i, end = ' ')

6 3036 ๋ง ์„ฑ๊ณต์ถœ์ฒ˜๋‹ค๊ตญ์–ด๋ถ„๋ฅ˜ 5051 6542 79.385%
์ฒซ๋ฒˆ์งธ ๋ง์„ ํ•œ ๋ฐ”ํ€ด ๋Œ๋ ธ์„ ๋•Œ, ๋‚˜๋จธ์ง€ ๋ง์ด ๋ช‡ ๋ฐ”ํ€ด ๋„๋Š”์ง€ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ

import math
def test(mainNum, subNum) :
    x = math.gcd(mainNum, subNum)
    print("{0}/{1}".format(mainNum//x, subNum//x))

T = int(input())
array = list(map(int, input().split()))
for i in array :
    if i == array[0] : continue
    test(array[0], i)

7 11050 ์ดํ•ญ ๊ณ„์ˆ˜ 1 ์„ฑ๊ณต๋ถ„๋ฅ˜ 13430 20880 64.841%
N๊ฐœ์˜ ๋ฌผ๊ฑด ์ค‘ ์ˆœ์„œ๋ฅผ ๊ณ ๋ คํ•˜์ง€ ์•Š๊ณ  K๊ฐœ๋ฅผ ๊ณ ๋ฅด๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜, ์ดํ•ญ ๊ณ„์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ

def fac1(num) :
    if num==1 : return 1
    return num*fac(num-1)

def fac2(num) :
    temp =1
    for i in range(1,num+1) :
        temp *= i
    return temp

N, K = map(int, input().split())

if K < 0 or K>N :
    print(0)
    
else :
    print(fac2(N) // (fac2(K)*fac2(N-K)))

 

8 11051 ์ดํ•ญ ๊ณ„์ˆ˜ 2 ์„ฑ๊ณต๋ถ„๋ฅ˜ 10763 28608 38.462%
๋” ๋„“์€ ๋ฒ”์œ„์˜ ์ดํ•ญ ๊ณ„์ˆ˜๋ฅผ ๋™์  ๊ณ„ํš๋ฒ•์œผ๋กœ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ

def fac1(num) :
    if num==1 : return 1
    return num*fac1(num-1)

def fac2(num) :
    temp =1
    for i in range(1,num+1) :
        temp *= i
    return temp

N, K = map(int, input().split())

if K < 0 or K>N :
    print(0)
    
else :
    print((fac2(N) // (fac2(K)*fac2(N-K)))%10007)

9 1010 ๋‹ค๋ฆฌ ๋†“๊ธฐ ์„ฑ๊ณต๋ถ„๋ฅ˜ 15752 34705 48.470%
๋‹ค๋ฆฌ๋ฅผ ๋†“๋Š” ๊ฒฝ์šฐ์˜ ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ

def fac(num) :
    temp =1
    for i in range(1,num+1) :
        temp *= i
        
    return temp


def fac1(num) :
    if num==1 : return 1
    return num*fac1(num-1)

T = int(input())
for i in range(T) :
    b, a = map(int, input().split())
    x= fac(a-b)*fac(b)
    y = fac(a) 
    print(y//x)

10 9375 ํŒจ์…˜์™• ์‹ ํ•ด๋นˆ ์„ฑ๊ณต์ถœ์ฒ˜๋‹ค๊ตญ์–ด๋ถ„๋ฅ˜ 4745 8973 54.356%
๊ฒฝ์šฐ์˜ ์ˆ˜ ์—ฐ์Šต๋ฌธ์ œ

from collections import Counter
t = int(input())
for i in range(t):
    n = int(input())
    s = []
    for j in range(n):
        a, b = input().split()
        s.append(b)
    num = 1
    result = Counter(s)
    for key in result:
        num *= result[key] + 1
    print(num - 1)
    
##์ฒ˜์Œ์— ์•„๋ž˜๊ฐ™์ด ์ ‘๊ทผํ–ˆ๋‹ค๊ฐ€ collections ์ƒ๊ฐ๋‚˜์„œ ๋‹ค์‹œํ’€์—ˆ์Œ
# import math

# T = int(input())
# array = []
# for i in range(T) :
#     x = int(input())
#     for j in range(x) :
#         array[i].append(input().split())

#     array[i].sort(key = lambda x: (x[1]))

#     tempStr = array[i][0][1]
#     count = 1
#     subSum = 0
#     for z in range(len(array[0])) :
#         if z == 0 : continue

#         if array[i][z][1] == tempStr :
#             if z == len(array[0])-1 and count !=1 :
#                 subSum += math.factorial(count)
#                 break
#             else : 
#                 count +=1
#                 continue

#         elif count == 1 :
#             tempStr = array[i][z][1]
#             continue
#         else :
#             subSum += math.factorial(count)
#             count = 1
#             tempStr = array[i][z][1]
#             continue
#     max = math.factorial(len(array[0]))
#     print(max - subSum +1)
        
# ##############################
# # def x :
    
# #     for a,b in array[0] :

# #         if firstPass == 0 : 
# #             firstPass +=1
# #             continue
        
# #         if b == tempStr :
# #             count += 1
# #             firstPass +=1
# #             continue
            
# #         elif count == 1 : 
# #             firstPass +=1
# #             continue
        
# #         else :
# #             subSum += math.factorial(count)
# #             firstPass +=1
# #             count = 1
# #             continue
        
# #         if firstPass == len(array[i])-1:
# #             subSum += math.factorial(count)
# #             break

11 1676 ํŒฉํ† ๋ฆฌ์–ผ 0์˜ ๊ฐœ์ˆ˜ ์„ฑ๊ณต๋ถ„๋ฅ˜ 11789 24977 47.672%
์†Œ์ธ์ˆ˜๋ถ„ํ•ด์˜ ์„ฑ์งˆ์„ ํ™œ์šฉํ•˜์—ฌ N!์˜ ๋์— 0์ด ์–ผ๋งˆ๋‚˜ ๋งŽ์ด ์˜ค๋Š”์ง€ ๊ตฌํ•˜๋Š” ๋ฌธ์ œ

x = int(input())
print(x//5 + x//25 + x//125)

12 2004 ์กฐํ•ฉ 0์˜ ๊ฐœ์ˆ˜ ์„ฑ๊ณต๋ถ„๋ฅ˜ 6233 22764 28.769%
์œ„์™€ ๋น„์Šทํ•œ๋ฐ N! ๋Œ€์‹  ์ดํ•ญ๊ณ„์ˆ˜๊ฐ€ ๋“ค์–ด๊ฐ„ ๋ฌธ์ œ

import math
def zero(num, x) :
    temp = x
    sum = 0
    while temp<=2000000000 :
        sum += num//temp
        temp *= x
    return sum

N, K = map(int, input().split())

if K < 0 or K>N :
    print(0)
    
else :
    a = zero(N,5) - zero(K,5) - zero(N-K,5)
    b = zero(N,2) - zero(K,2) - zero(N-K,2)
    print(min(a,b))
    

 

์ด๋ฒˆ ๋‹จ๊ณ„๋Š” ์ข€ ์‰ฝ๋‹ค๊ณ  ๋А๊ปด์ ธ์„œ ํŽธํ•˜๊ฒŒ Github ์ž”๋”” ์ฑ„์šธ ๊ฒธ ํŒŒ์ด์ฌ์œผ๋กœ ํ’€์—ˆ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•
Liky