21
The task is the following. Given an integer x
(such that x
modulo 100000000003
is not equal to 0
) presented to your code in any way you find convenient, output another integer y < 100000000003
so that (x * y) mod 100000000003 = 1
.
You code must take less than 30 minutes to run on a standard desktop machine for any input x
such that |x| < 2^40
.
Test cases
Input: 400000001. Output: 65991902837
Input: 4000000001. Output: 68181818185
Input: 2. Output: 50000000002
Input: 50000000002. Output: 2.
Input: 1000000. Output: 33333300001
Restrictions
You may not use any libraries or builtin functions that perform modulo arithmetic (or this inverse operation). This means you can't even do a % b
without implementing %
yourself. You can use all other non-modulo arithmetic builtin functions however.
Similar question
This is similar to this question although hopefully different enough to still be of interest.
So a-(a/b)*b is fine? – user253751 – 2017-07-04T10:31:18.387
@immibis That looks fine. – None – 2017-07-04T11:03:59.363
tag: restricted code? – Felipe Nardi Batista – 2017-07-04T11:14:56.007
I notice you don't have any restriction that
y<100000000003
. I see at least one answer that could be shortened by dropping a final modulo... – Ørjan Johansen – 2017-07-04T17:53:01.077@ØrjanJohansen I was definitely expecting y<100000000003. – None – 2017-07-04T20:23:41.127
1What's special about
100000000003
? (just wondering) – NoOneIsHere – 2017-07-04T21:19:21.7001@Lembik In that case, could you mention that requirement that y<100000000003 in the question? – isaacg – 2017-07-04T21:25:45.867
@NoOneIsHere It is the first twelve-digit prime number? – Jeppe Stig Nielsen – 2017-07-04T22:19:00.843
@JeppeStigNielsen It believe it is. – None – 2017-07-05T06:51:33.517
Do the restrictions disallow use of python's
– bendl – 2017-07-05T17:24:36.100pow
operator's 3rd argument? https://docs.python.org/3.3/library/functions.html#pow@bendi Yes they do. – None – 2017-07-05T17:28:36.887