소수점 뒤에 양의 정수를 차례대로 붙여 나가면 아래와 같은 무리수를 만들 수 있습니다.
0.123456789101112131415161718192021...
이 무리수의 소수점 아래 12번째 자리에는 1이 옵니다 (위에서 붉게 표시된 숫자).
소수점 아래 n번째 숫자를 dn이라고 했을 때, 아래 식의 값은 얼마입니까?
d1 × d10 × d100 × d1000 × d10000 × d100000 × d1000000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | def selectChr(count, length, base): tmp = length - base if tmp >= 0: count %= 10**(tmp+1) count /= 10**(tmp) return count def checkLength(count): length = 0 comp = 1 while count / comp != 0: length +=1 comp *= 10 return length count = 0 length = 0 base = 1 result = 1 while length <=1000000: count+=1 length += checkLength(count) if length >= base: #print "count is %d and length is %d" % (count, length) ret = selectChr(count, length, base) #print "correct answer : %d" % ret result *= ret base *= 10 print "problem's result is %d" % result | cs |
C:\Users\soicem\Desktop\연습용 폴더>python test.py
problem's result is 210
'* Computer Science > Project Euler' 카테고리의 다른 글
Permutation (0) | 2016.09.30 |
---|---|
project euler 42. problem (0) | 2016.09.23 |
project euler 39. problem (0) | 2016.09.20 |
project euler 38. problem (0) | 2016.09.06 |
project euler 36. problem (0) | 2016.09.01 |