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