diff options
author | Iru Cai <mytbk920423@gmail.com> | 2021-05-13 20:05:58 +0800 |
---|---|---|
committer | Iru Cai <mytbk920423@gmail.com> | 2021-05-13 20:05:58 +0800 |
commit | 5024901379d4a6bc0d2ecc9338701395f85199ba (patch) | |
tree | 760641de175f008bc782d564738d69d99c40fcfa /euler_686.py | |
parent | e4f94bdaa436533b9f379b2846a64856f5d818b4 (diff) | |
download | project_euler-5024901379d4a6bc0d2ecc9338701395f85199ba.tar.xz |
Diffstat (limited to 'euler_686.py')
-rw-r--r-- | euler_686.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/euler_686.py b/euler_686.py new file mode 100644 index 0000000..01af7b2 --- /dev/null +++ b/euler_686.py @@ -0,0 +1,24 @@ +#!/usr/bin/pypy + +import math + +# calculate the length-l prefix of 2^n +def prefix_power2(n,l): + log = math.log10(2)*n + declog = log - math.floor(log) + return math.floor(pow(10,declog+l-1)) + +def main(): + i = 0 + count = 0 + while count < 678910: + i = i + 1 + if prefix_power2(i, 3) == 123: + count = count + 1 + if count % 1000 == 0: + print("p({},{})={}".format(123,count,i)) + + print("p({},{})={}".format(123,count,i)) + +if __name__ == "__main__": + main() |