GCD of exponents

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite
1












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






share|cite|improve this question

















  • 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














up vote
0
down vote

favorite
1












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






share|cite|improve this question

















  • 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












up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





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






share|cite|improve this question













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








share|cite|improve this question












share|cite|improve this question




share|cite|improve this question








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












  • 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















active

oldest

votes











Your Answer




StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "69"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);








 

draft saved


draft discarded


















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



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes










 

draft saved


draft discarded


























 


draft saved


draft discarded














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













































































Comments

Popular posts from this blog

What is the equation of a 3D cone with generalised tilt?

Color the edges and diagonals of a regular polygon

Relationship between determinant of matrix and determinant of adjoint?