Created
November 30, 2011 21:55
-
-
Save jakedobkin/1411151 to your computer and use it in GitHub Desktop.
Euler 26
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # we know the period of a repeating decimal p is always less than p | |
| # so we can count down- when we find a big repeater, we save it | |
| # and stop counting when i is less than biggest period | |
| i = 1000 | |
| biggest_period = 0 | |
| while (i > 0): | |
| #compute the order of 10 modulo p | |
| j = 1 | |
| while j < 1000: | |
| order = (10**j)%i | |
| if (order == 1): | |
| # print "1/%r terminates in %r digits" % (i,j) | |
| if biggest_period < j: | |
| biggest_i = i | |
| biggest_period = j | |
| break | |
| j = j + 1 | |
| if i < biggest_period: | |
| break | |
| i = i - 1 | |
| print "for p<1000, 1/%d the longest period, which is %d digits long" % (biggest_i, biggest_period) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment