GCD of exponents
Clash Royale CLAN TAG#URR8PPP
up vote
0
down vote
favorite
I have been trying to determine a shorter method for calculating $gcd(a^n + b^n, |a-b|).$ I noticed that, if I were to calculate (using the above formula) say $a = 100$ and $b = 4,$ starting from $1$ and ending at $n$ (a loop), at a certain point, the answer becomes constant. For $a = 100, b = 4, n = 100,$ I create a loop from $1$ to $n,$ and at each point, I apply the formula, the first answer $(n = 1)$ is $8,$ thereafter it is $32$ till when $n$ becomes $100.$ For optimization, I break out of the loop once two equal consecutive numbers are found and the latest number ($32$ here), becomes the answer. Does anyone know a straightforward formula for calculating $gcd(a^n + b^n, a-b),$ or better still, my primary concern, a global formula for finding $a^n + b^n$
Note: 1<=a,b,n<=10^12
My Python Code for the above explanation follows suite
from functools import reduce
from fractions import gcd
a, b, n = map(int, raw_input().split()); ans = -1
if a == b:
ans = (a**n) + (b**n)#a-b will give 0 and gcd(x,0) == x
else:
for j in xrange(n):
x = gcd((a**n)+(b**n),abs(a-b))
if x != ans:
ans = x
else:
break
print ans
exponentiation greatest-common-divisor
 |Â
show 2 more comments
up vote
0
down vote
favorite
I have been trying to determine a shorter method for calculating $gcd(a^n + b^n, |a-b|).$ I noticed that, if I were to calculate (using the above formula) say $a = 100$ and $b = 4,$ starting from $1$ and ending at $n$ (a loop), at a certain point, the answer becomes constant. For $a = 100, b = 4, n = 100,$ I create a loop from $1$ to $n,$ and at each point, I apply the formula, the first answer $(n = 1)$ is $8,$ thereafter it is $32$ till when $n$ becomes $100.$ For optimization, I break out of the loop once two equal consecutive numbers are found and the latest number ($32$ here), becomes the answer. Does anyone know a straightforward formula for calculating $gcd(a^n + b^n, a-b),$ or better still, my primary concern, a global formula for finding $a^n + b^n$
Note: 1<=a,b,n<=10^12
My Python Code for the above explanation follows suite
from functools import reduce
from fractions import gcd
a, b, n = map(int, raw_input().split()); ans = -1
if a == b:
ans = (a**n) + (b**n)#a-b will give 0 and gcd(x,0) == x
else:
for j in xrange(n):
x = gcd((a**n)+(b**n),abs(a-b))
if x != ans:
ans = x
else:
break
print ans
exponentiation greatest-common-divisor
1
Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
2 days ago
2
What do you mean by "a global formula for $a^n+b^n?$" Why isn't $a^n+b^n$ a "global formula?"
– saulspatz
2 days ago
If you are using python, you won't be able to beat the built-in methods of integer arithmetic in source code. Have a look here for starters.
– saulspatz
2 days ago
"What do you mean by "a global formula for an+bn?" Why isn't an+bn a "global formula?" Take for example, a^n - b^n can be sipmlified as math.stackexchange.com/questions/406703/how-to-simplify-an-bn do u know anything for a^n + b^n??
– Carlson Bimbuh
2 days ago
1
Knowing the size of $n$ you're interested in is pretty relevant :) Thanks for editing it into your question :)
– postmortes
2 days ago
 |Â
show 2 more comments
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I have been trying to determine a shorter method for calculating $gcd(a^n + b^n, |a-b|).$ I noticed that, if I were to calculate (using the above formula) say $a = 100$ and $b = 4,$ starting from $1$ and ending at $n$ (a loop), at a certain point, the answer becomes constant. For $a = 100, b = 4, n = 100,$ I create a loop from $1$ to $n,$ and at each point, I apply the formula, the first answer $(n = 1)$ is $8,$ thereafter it is $32$ till when $n$ becomes $100.$ For optimization, I break out of the loop once two equal consecutive numbers are found and the latest number ($32$ here), becomes the answer. Does anyone know a straightforward formula for calculating $gcd(a^n + b^n, a-b),$ or better still, my primary concern, a global formula for finding $a^n + b^n$
Note: 1<=a,b,n<=10^12
My Python Code for the above explanation follows suite
from functools import reduce
from fractions import gcd
a, b, n = map(int, raw_input().split()); ans = -1
if a == b:
ans = (a**n) + (b**n)#a-b will give 0 and gcd(x,0) == x
else:
for j in xrange(n):
x = gcd((a**n)+(b**n),abs(a-b))
if x != ans:
ans = x
else:
break
print ans
exponentiation greatest-common-divisor
I have been trying to determine a shorter method for calculating $gcd(a^n + b^n, |a-b|).$ I noticed that, if I were to calculate (using the above formula) say $a = 100$ and $b = 4,$ starting from $1$ and ending at $n$ (a loop), at a certain point, the answer becomes constant. For $a = 100, b = 4, n = 100,$ I create a loop from $1$ to $n,$ and at each point, I apply the formula, the first answer $(n = 1)$ is $8,$ thereafter it is $32$ till when $n$ becomes $100.$ For optimization, I break out of the loop once two equal consecutive numbers are found and the latest number ($32$ here), becomes the answer. Does anyone know a straightforward formula for calculating $gcd(a^n + b^n, a-b),$ or better still, my primary concern, a global formula for finding $a^n + b^n$
Note: 1<=a,b,n<=10^12
My Python Code for the above explanation follows suite
from functools import reduce
from fractions import gcd
a, b, n = map(int, raw_input().split()); ans = -1
if a == b:
ans = (a**n) + (b**n)#a-b will give 0 and gcd(x,0) == x
else:
for j in xrange(n):
x = gcd((a**n)+(b**n),abs(a-b))
if x != ans:
ans = x
else:
break
print ans
exponentiation greatest-common-divisor
edited 2 days ago


Simply Beautiful Art
49k571169
49k571169
asked 2 days ago
Carlson Bimbuh
11
11
1
Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
2 days ago
2
What do you mean by "a global formula for $a^n+b^n?$" Why isn't $a^n+b^n$ a "global formula?"
– saulspatz
2 days ago
If you are using python, you won't be able to beat the built-in methods of integer arithmetic in source code. Have a look here for starters.
– saulspatz
2 days ago
"What do you mean by "a global formula for an+bn?" Why isn't an+bn a "global formula?" Take for example, a^n - b^n can be sipmlified as math.stackexchange.com/questions/406703/how-to-simplify-an-bn do u know anything for a^n + b^n??
– Carlson Bimbuh
2 days ago
1
Knowing the size of $n$ you're interested in is pretty relevant :) Thanks for editing it into your question :)
– postmortes
2 days ago
 |Â
show 2 more comments
1
Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
2 days ago
2
What do you mean by "a global formula for $a^n+b^n?$" Why isn't $a^n+b^n$ a "global formula?"
– saulspatz
2 days ago
If you are using python, you won't be able to beat the built-in methods of integer arithmetic in source code. Have a look here for starters.
– saulspatz
2 days ago
"What do you mean by "a global formula for an+bn?" Why isn't an+bn a "global formula?" Take for example, a^n - b^n can be sipmlified as math.stackexchange.com/questions/406703/how-to-simplify-an-bn do u know anything for a^n + b^n??
– Carlson Bimbuh
2 days ago
1
Knowing the size of $n$ you're interested in is pretty relevant :) Thanks for editing it into your question :)
– postmortes
2 days ago
1
1
Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
2 days ago
Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
2 days ago
2
2
What do you mean by "a global formula for $a^n+b^n?$" Why isn't $a^n+b^n$ a "global formula?"
– saulspatz
2 days ago
What do you mean by "a global formula for $a^n+b^n?$" Why isn't $a^n+b^n$ a "global formula?"
– saulspatz
2 days ago
If you are using python, you won't be able to beat the built-in methods of integer arithmetic in source code. Have a look here for starters.
– saulspatz
2 days ago
If you are using python, you won't be able to beat the built-in methods of integer arithmetic in source code. Have a look here for starters.
– saulspatz
2 days ago
"What do you mean by "a global formula for an+bn?" Why isn't an+bn a "global formula?" Take for example, a^n - b^n can be sipmlified as math.stackexchange.com/questions/406703/how-to-simplify-an-bn do u know anything for a^n + b^n??
– Carlson Bimbuh
2 days ago
"What do you mean by "a global formula for an+bn?" Why isn't an+bn a "global formula?" Take for example, a^n - b^n can be sipmlified as math.stackexchange.com/questions/406703/how-to-simplify-an-bn do u know anything for a^n + b^n??
– Carlson Bimbuh
2 days ago
1
1
Knowing the size of $n$ you're interested in is pretty relevant :) Thanks for editing it into your question :)
– postmortes
2 days ago
Knowing the size of $n$ you're interested in is pretty relevant :) Thanks for editing it into your question :)
– postmortes
2 days ago
 |Â
show 2 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f2871942%2fgcd-of-exponents%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
Welcome to MSE. For some basic information about writing mathematics at this site see, e.g., basic help on mathjax notation, mathjax tutorial and quick reference, main meta site math tutorial and equation editing how-to.
– José Carlos Santos
2 days ago
2
What do you mean by "a global formula for $a^n+b^n?$" Why isn't $a^n+b^n$ a "global formula?"
– saulspatz
2 days ago
If you are using python, you won't be able to beat the built-in methods of integer arithmetic in source code. Have a look here for starters.
– saulspatz
2 days ago
"What do you mean by "a global formula for an+bn?" Why isn't an+bn a "global formula?" Take for example, a^n - b^n can be sipmlified as math.stackexchange.com/questions/406703/how-to-simplify-an-bn do u know anything for a^n + b^n??
– Carlson Bimbuh
2 days ago
1
Knowing the size of $n$ you're interested in is pretty relevant :) Thanks for editing it into your question :)
– postmortes
2 days ago