fork download
  1. n = 8827
  2.  
  3. # Use something to factorise (e.g. YAFU, available on SourceForge, for the big
  4. # number):
  5. prime_factors = [7, 13, 97]
  6.  
  7. # There's no repeated prime in the above, so totient(n) is the product of
  8. # (prime-1).
  9. totient = 1
  10. for p in prime_factors:
  11. totient *= p-1
  12.  
  13. # Euler's theorem says a^totient(n) = 1 (mod n) if a and n have no common
  14. # divisors. Substitute 10 for a and that means we need to make sure 2 and 5
  15. # don't divide n, which it doesn't.
  16.  
  17. # Check Euler's theorem (should print 1). Normally you'd use pow here, but
  18. # I'm making the mod % more explicit.
  19. print(10**totient % n)
  20.  
  21. # 10^totient-1 is some number 9999.....9999 divisible by n, and (10^totient-1)/9
  22. # is some number 1111...1111. Note that 9 doesn't divide n, so we can divide by
  23. # 9 knowing that (10^totient-1)/9 will still be divisible by n.
  24. repunit = (10**totient - 1) // 9
  25. answer = repunit // n
  26. print('{0} * {1} = {2}'.format(n, answer, answer*n))
  27.  
  28. # This is clearly suboptimal, and if you look closely at the printed "answer" var
  29. # you'll see that it's repeating. We can take out the repeating chunk and try
  30. # just that:
  31. answer2 = 12587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693
  32. print('{0} * {1} = {2}'.format(n, answer2, answer2*n))
Success #stdin #stdout 0.01s 9992KB
stdin
Standard input is empty
stdout
1
8827 * 12587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693000012587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693 = 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
8827 * 12587641453620835064134033206198154651762899185579597950731971350528051558979394030940422693 = 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111