근사 (2) 썸네일형 리스트형 [EP 057] 2의 제곱근의 연분수 표현 #!/usr/bin/env python def jarisu(n): su = 0 while n != 0: su += 1 n //= 10 return su bunja = 3 bunmo = 2 count = 0 for i in range(2, 1001): bunja, bunmo = bunja + 2 * bunmo, bunja + bunmo if jarisu(bunja) > jarisu(bunmo): count += 1 print(count) 오일러 프로젝트 57번 문제. 2의 제곱근을 연분수(continued fraction) 모양으로 근사한 분수들(초기 1000항)의 분자와 분모의 자리수 비교하여 분자의 자리수가 분모의 자리수보다 커지는 것의 갯수를 구하는 것. https://daewonyoon.tistor.. [Euler Project 101] 수열 다항식으로 근사하기 #!/usr/bin/env python # http://projecteuler.net/index.php?section=problems&id=101 coff = [ 0 ] * 11 def OP(ord, n): if ord == 0: return coff[0] r = OP(ord-1, n) term = coff[ord] for j in range(1, ord+1): term*=(n-j) for j in range(1, ord+1): term/= j r += term return r def f(n): return 1 - n + n**2 - n**3 + n**4 - n**5 + n**6 - n**7 + n**8 - n**9 + n**10 a = [ f(n) for n in range(1, 12) ] coff[0.. 이전 1 다음