Python
알고리즘 라이브러리 기록용
kyeongjun-dev
2024. 3. 31. 21:01
최대공약수, 최대공배수 - 관련문제 백준 2609
import math
a, b = map(int, input().split())
print(math.gcd(a,b))
print(math.lcm(a,b))
입력속도 빠르게
import sys
n = int(sys.stdin.readline())
combinations, permutations, product, combinations_with_replacement
from itertools import combinations, permutations
n, m = map(int, input().split())
arr = list(map(int, input().split()))
max_sum = 0
for c in combinations(arr, 3):
sum_c = sum(c)
if sum_c <= m:
max_sum = max(max_sum, sum_c)
print(max_sum)
###
product(arr, repeat=2)
combinations_with_replacement(arr, 2)
개수세기
from collections import Counter
l = [1, 2, 3]
cd = Counter(l)
팩토리얼
from math import factorial
n, k = map(int, input().split())
result = (factorial(n) // factorial(n-k)) // factorial(k)
print(result)
올림, 내림, 반올림
ceil()
floor()
round()
round() = floor(num+0.5)