목록Algorithm/ProjectEuler (18)
Try
res = '7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720..
CHECK = [False, False] + [True] * 1000000 Primes = [] for i in range(2, 1000000): if CHECK[i]: Primes.append(i) for j in range(2 * i, 1000000, i): CHECK[j] = False print(Primes[10000]) 출처 http://euler.synap.co.kr/prob_detail.php?id=7
A = 0 B = 0 for i in range(1, 101): A += i * i B += i print((B * B) - A) 출처 http://euler.synap.co.kr/prob_detail.php?id=6
def gcd(a, b): while b is not 0: d = a % b a = b b = d return a def lcm(a, b): return a * b // gcd(a, b) ans = 0 SUM = 1 for i in range(1, 20): ans = lcm(i, SUM) SUM = ans print(ans) 출처 http://euler.synap.co.kr/submit_answer.php
ans = [] for i in range(100, 1000): for j in range(100, 1000): flag = 1 com = str(i * j) for k in range(len(com) // 2): if com[k] != com[len(com) - k - 1]: flag = 0 break if flag: ans.append(int(com)) else: continue ans.sort() print(ans) 출처 http://euler.synap.co.kr/prob_detail.php?id=4
ans = 600851475143 a = 2 while 1: if ans % a == 0: print(a) while 1: ans = ans // a if ans % a != 0: break a += 1 출처 http://euler.synap.co.kr/prob_detail.php?id=3
ans = 2 a = 1 b = 2 c = 0 while 1: if c > 4000000: break c = a + b a = b b = c if c % 2 == 0: ans += c print(ans) 출처 http://euler.synap.co.kr/prob_detail.php?id=2