(5086)
while True:
x, y = map(int, input().split())
if x + y > 0:
if x % y == 0:
print("multiple")
elif y % x == 0:
print("factor")
else:
print("neither")
else:
break
(1037)
number = int(input())
a= list(map(int, input().split())) # 꼭 map으로만 안 해도 됨. 리스트로 만들어 버리고 max,min 씀.
a_max = max(a)
a_min = min(a)
N = a_max * a_min
print(N)
(2609)
a, b = map(int, input().split())
x = set(i for i in range(1, a+1) if a % i == 0)
y = set(i for i in range(1, b+1) if b % i == 0)
w = max(set.intersection(x, y))
z = int((a * b) / w)
print(w)
print(z)
최대공약수 : 자기 자신까지의 인자들로 나눈 수 중 나머지가 0인 것
최소공배수 : 구하려는 두 수의 곱에서 최대공약수를 나눈 것. :
유클리드 호제법
(1934) 유클리드 호제법을 함수로 응용했어야 빨랐다.
그 전에 4번의 시간초과는 아래 블로그에 나온 방식을 모두 사용했을 때였다.(첫 번째는 2609번 응용해서 했는데.. 유클리드 호제법이긴 했는데 시간이 너무 오래 걸린 케이스)
number = int(input())
for i in range(number):
a, b = map(int, input().split())
def UC(a, b): # 최대공약수 구하는 함수
while(b):
a, b = b, a%b
return a
def UC2(a, b): # 최대공약수 구한거로 최소공배수 구하기
result = (a*b) // UC(a,b)
return result
print(UC2(a, b))
(3036)
from fractions import Fraction
number = int(input())
a = list(map(int, input().split()))
for i in a[1:]:
answer = Fraction(i, a[0])
print(answer.denominator, '/', answer.numerator, sep = '')
(11050)
이항계수를 파이썬에...일단 이항계수는 고등학교 때 배웠는지 안 배웠는지 기억이 가물가물하다. 일단 공식이므로 위키피디아에서 하나 긁어왔고 그거로 푼 분 풀이로 그대로 풀었다. 팩토리얼을 임포트 하려면 math를 가져와야 한다.
import math
a, b = map(int, input().split())
answer = math.factorial(a) // math.factorial(a-b) // math.factorial(b)
print(answer)