GCD and exponentiation of large numbers
Clash Royale CLAN TAG#URR8PPP
up vote
-2
down vote
favorite
I am solving a problem involving $gcd$ of two very large numbers. Given three numbers $a,b,n$, I have to find $gcd(a,b^n)$. So for example
$$a,b,n=119929244861828206, 521483382396998375, 4838134431180356$$
I used fast modular exponentiation to find
$$521483382396998375^4838134431180356bmod 1000000007=473264774$$
Then I used python's math.gcd
module to calculate $gcd(119929244861828206,473264774)$ and got the answer as 2 but the answer is given as 83. I am not sure what mistake I did, so please guide me.
exponentiation greatest-common-divisor
add a comment |Â
up vote
-2
down vote
favorite
I am solving a problem involving $gcd$ of two very large numbers. Given three numbers $a,b,n$, I have to find $gcd(a,b^n)$. So for example
$$a,b,n=119929244861828206, 521483382396998375, 4838134431180356$$
I used fast modular exponentiation to find
$$521483382396998375^4838134431180356bmod 1000000007=473264774$$
Then I used python's math.gcd
module to calculate $gcd(119929244861828206,473264774)$ and got the answer as 2 but the answer is given as 83. I am not sure what mistake I did, so please guide me.
exponentiation greatest-common-divisor
1
Why did you reduce it mod $100000000007$?
â ThomasGrubb
Aug 16 at 4:53
@ThomasGrubb Presumably because of codechef.com/AUG18B/problems/GCDMOD
â Lord Shark the Unknown
Aug 16 at 4:56
$n $ is large enough to be irrelevent. If $a $ and $b $ have any prime factor $p $ in common and $p^k $ divides $a $ then $k <n $ and $p^k|b^n $ and the highest power in the gcd has to be whatever the highest power dividing $a $ is.
â fleablood
Aug 16 at 6:00
add a comment |Â
up vote
-2
down vote
favorite
up vote
-2
down vote
favorite
I am solving a problem involving $gcd$ of two very large numbers. Given three numbers $a,b,n$, I have to find $gcd(a,b^n)$. So for example
$$a,b,n=119929244861828206, 521483382396998375, 4838134431180356$$
I used fast modular exponentiation to find
$$521483382396998375^4838134431180356bmod 1000000007=473264774$$
Then I used python's math.gcd
module to calculate $gcd(119929244861828206,473264774)$ and got the answer as 2 but the answer is given as 83. I am not sure what mistake I did, so please guide me.
exponentiation greatest-common-divisor
I am solving a problem involving $gcd$ of two very large numbers. Given three numbers $a,b,n$, I have to find $gcd(a,b^n)$. So for example
$$a,b,n=119929244861828206, 521483382396998375, 4838134431180356$$
I used fast modular exponentiation to find
$$521483382396998375^4838134431180356bmod 1000000007=473264774$$
Then I used python's math.gcd
module to calculate $gcd(119929244861828206,473264774)$ and got the answer as 2 but the answer is given as 83. I am not sure what mistake I did, so please guide me.
exponentiation greatest-common-divisor
edited Aug 16 at 4:48
Parcly Taxel
33.6k136588
33.6k136588
asked Aug 16 at 4:46
Vishal .R
11
11
1
Why did you reduce it mod $100000000007$?
â ThomasGrubb
Aug 16 at 4:53
@ThomasGrubb Presumably because of codechef.com/AUG18B/problems/GCDMOD
â Lord Shark the Unknown
Aug 16 at 4:56
$n $ is large enough to be irrelevent. If $a $ and $b $ have any prime factor $p $ in common and $p^k $ divides $a $ then $k <n $ and $p^k|b^n $ and the highest power in the gcd has to be whatever the highest power dividing $a $ is.
â fleablood
Aug 16 at 6:00
add a comment |Â
1
Why did you reduce it mod $100000000007$?
â ThomasGrubb
Aug 16 at 4:53
@ThomasGrubb Presumably because of codechef.com/AUG18B/problems/GCDMOD
â Lord Shark the Unknown
Aug 16 at 4:56
$n $ is large enough to be irrelevent. If $a $ and $b $ have any prime factor $p $ in common and $p^k $ divides $a $ then $k <n $ and $p^k|b^n $ and the highest power in the gcd has to be whatever the highest power dividing $a $ is.
â fleablood
Aug 16 at 6:00
1
1
Why did you reduce it mod $100000000007$?
â ThomasGrubb
Aug 16 at 4:53
Why did you reduce it mod $100000000007$?
â ThomasGrubb
Aug 16 at 4:53
@ThomasGrubb Presumably because of codechef.com/AUG18B/problems/GCDMOD
â Lord Shark the Unknown
Aug 16 at 4:56
@ThomasGrubb Presumably because of codechef.com/AUG18B/problems/GCDMOD
â Lord Shark the Unknown
Aug 16 at 4:56
$n $ is large enough to be irrelevent. If $a $ and $b $ have any prime factor $p $ in common and $p^k $ divides $a $ then $k <n $ and $p^k|b^n $ and the highest power in the gcd has to be whatever the highest power dividing $a $ is.
â fleablood
Aug 16 at 6:00
$n $ is large enough to be irrelevent. If $a $ and $b $ have any prime factor $p $ in common and $p^k $ divides $a $ then $k <n $ and $p^k|b^n $ and the highest power in the gcd has to be whatever the highest power dividing $a $ is.
â fleablood
Aug 16 at 6:00
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
If you use the Euclidean algorithm, the first step can be chosen to be computing $b^n$ mod $a$, then compute $a$ mod that, etc. until you get 0. Then back up a step to get the actual GCD, then finally mod by 1000000007 at the end.
Modding by the final modulus at the start changes the result compared to doing it at the end. For instance consider that gcd(11,4) mod 3 is 1 but gcd(11 mod 3,4) is 2.
Thank you. Could you also point out the possible cause my solution is not producing the intended result?
â Vishal .R
Aug 16 at 5:11
@Vishal.R Done.
â Ian
Aug 16 at 5:12
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
If you use the Euclidean algorithm, the first step can be chosen to be computing $b^n$ mod $a$, then compute $a$ mod that, etc. until you get 0. Then back up a step to get the actual GCD, then finally mod by 1000000007 at the end.
Modding by the final modulus at the start changes the result compared to doing it at the end. For instance consider that gcd(11,4) mod 3 is 1 but gcd(11 mod 3,4) is 2.
Thank you. Could you also point out the possible cause my solution is not producing the intended result?
â Vishal .R
Aug 16 at 5:11
@Vishal.R Done.
â Ian
Aug 16 at 5:12
add a comment |Â
up vote
0
down vote
accepted
If you use the Euclidean algorithm, the first step can be chosen to be computing $b^n$ mod $a$, then compute $a$ mod that, etc. until you get 0. Then back up a step to get the actual GCD, then finally mod by 1000000007 at the end.
Modding by the final modulus at the start changes the result compared to doing it at the end. For instance consider that gcd(11,4) mod 3 is 1 but gcd(11 mod 3,4) is 2.
Thank you. Could you also point out the possible cause my solution is not producing the intended result?
â Vishal .R
Aug 16 at 5:11
@Vishal.R Done.
â Ian
Aug 16 at 5:12
add a comment |Â
up vote
0
down vote
accepted
up vote
0
down vote
accepted
If you use the Euclidean algorithm, the first step can be chosen to be computing $b^n$ mod $a$, then compute $a$ mod that, etc. until you get 0. Then back up a step to get the actual GCD, then finally mod by 1000000007 at the end.
Modding by the final modulus at the start changes the result compared to doing it at the end. For instance consider that gcd(11,4) mod 3 is 1 but gcd(11 mod 3,4) is 2.
If you use the Euclidean algorithm, the first step can be chosen to be computing $b^n$ mod $a$, then compute $a$ mod that, etc. until you get 0. Then back up a step to get the actual GCD, then finally mod by 1000000007 at the end.
Modding by the final modulus at the start changes the result compared to doing it at the end. For instance consider that gcd(11,4) mod 3 is 1 but gcd(11 mod 3,4) is 2.
edited Aug 16 at 5:11
answered Aug 16 at 5:07
Ian
65.5k24682
65.5k24682
Thank you. Could you also point out the possible cause my solution is not producing the intended result?
â Vishal .R
Aug 16 at 5:11
@Vishal.R Done.
â Ian
Aug 16 at 5:12
add a comment |Â
Thank you. Could you also point out the possible cause my solution is not producing the intended result?
â Vishal .R
Aug 16 at 5:11
@Vishal.R Done.
â Ian
Aug 16 at 5:12
Thank you. Could you also point out the possible cause my solution is not producing the intended result?
â Vishal .R
Aug 16 at 5:11
Thank you. Could you also point out the possible cause my solution is not producing the intended result?
â Vishal .R
Aug 16 at 5:11
@Vishal.R Done.
â Ian
Aug 16 at 5:12
@Vishal.R Done.
â Ian
Aug 16 at 5:12
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2884408%2fgcd-and-exponentiation-of-large-numbers%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Why did you reduce it mod $100000000007$?
â ThomasGrubb
Aug 16 at 4:53
@ThomasGrubb Presumably because of codechef.com/AUG18B/problems/GCDMOD
â Lord Shark the Unknown
Aug 16 at 4:56
$n $ is large enough to be irrelevent. If $a $ and $b $ have any prime factor $p $ in common and $p^k $ divides $a $ then $k <n $ and $p^k|b^n $ and the highest power in the gcd has to be whatever the highest power dividing $a $ is.
â fleablood
Aug 16 at 6:00