Project Euler 358 cyclic number
Last night, I took a while on Problem 358.
Here’s the approach without the help of matlab or mathmatica or VS.
The main idea of this solution is summed up as below:
1, Cyclic number generated by 1/p, p is a prime number.
2, Prove that SUM(all digits of cyclic number)=(p-1)*9/2
3, the last 5 digits of p can be calculated by hand
Conclusion: All help from outside we need is a list of all prime numbers within 724’000’000 to 729’999’999
Brief Proof:
1, Since what makes cyclic number cyclic is:
[MOD p]: exist a=10
10/p, 100/p, 1000/p, … , 10^(p-2) in {2, 3, … ,p-1} && 10^(p-1) =1
therefore p is prime (Lehmer’s theorem)
Here’s the approach without the help of matlab or mathmatica or VS.
The main idea of this solution is summed up as below:
1, Cyclic number generated by 1/p, p is a prime number.
2, Prove that SUM(all digits of cyclic number)=(p-1)*9/2
3, the last 5 digits of p can be calculated by hand
Conclusion: All help from outside we need is a list of all prime numbers within 724’000’000 to 729’999’999
Brief Proof:
1, Since what makes cyclic number cyclic is:
[MOD p]: exist a=10
10/p, 100/p, 1000/p, … , 10^(p-2) in {2, 3, … ,p-1} && 10^(p-1) =1
therefore p is prime (Lehmer’s theorem)
2, This part is simple, if Sn=a1+a2+…+an
a1a2a3a4…an is cyclic, then
a1a2a3a4…an *1
a1a2a3a4…an *2
…
a1a2a3a4…an *(n-1)
+)
______________
Sn*111111…1(n-1 digit)=a1a2a3a4…an*(1+2+…+(n-1))
a1a2a3a4…an is cyclic, then
a1a2a3a4…an *1
a1a2a3a4…an *2
…
a1a2a3a4…an *(n-1)
+)
______________
Sn*111111…1(n-1 digit)=a1a2a3a4…an*(1+2+…+(n-1))
Therefore, Sn*1111..1(n-1 digit)=999..9(n-1 digit) * (1/n) * (n-1)n/2
=> Sn=9*(n-1)/2
3, The last 5 digit can be calculated as below:
exists N<p, N/p = 0.5678900000000137xxxxx…
=> (N*10^5)/p = 56789+1.37*10^(-9)
=> p*(56789+1.37*10^(-9)) = (N*10^5)
Since p is within (1/0.00000000137, 1/0.00000000138)
=> p is about 7 * 10^9 => p*1.37*10^(-9) is about 1;
Since (N*10^5) can only be an integer, p*1.37*10^(-9) = 1
Therefore we reach a simple conclusion that p * 56789 = N*10^5 – 1 ends with 99999 as the last 5 digits.
The last 5 digits of p can then be calculated simply by hand, that is 09891
Conclusion, with the prime number list http://primes.utm.edu/lists/small/millions/
Altogether 3 hits with last 5 digits as ‘09891’ & within (724’000’000, 729’999’999)
They are 725509891, 726509891, 729809891.
Verify those 3, and we can reach our answer (729809891) :)
=> Sn=9*(n-1)/2
3, The last 5 digit can be calculated as below:
exists N<p, N/p = 0.5678900000000137xxxxx…
=> (N*10^5)/p = 56789+1.37*10^(-9)
=> p*(56789+1.37*10^(-9)) = (N*10^5)
Since p is within (1/0.00000000137, 1/0.00000000138)
=> p is about 7 * 10^9 => p*1.37*10^(-9) is about 1;
Since (N*10^5) can only be an integer, p*1.37*10^(-9) = 1
Therefore we reach a simple conclusion that p * 56789 = N*10^5 – 1 ends with 99999 as the last 5 digits.
The last 5 digits of p can then be calculated simply by hand, that is 09891
Conclusion, with the prime number list http://primes.utm.edu/lists/small/millions/
Altogether 3 hits with last 5 digits as ‘09891’ & within (724’000’000, 729’999’999)
They are 725509891, 726509891, 729809891.
Verify those 3, and we can reach our answer (729809891) :)
Comments
Post a Comment