Finding Large Pseudoprimes with a Computer

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











up vote
2
down vote

favorite












I'm reading the book Prime and Programming and I'm stuck on one of the computer exercises.



I'm checking for Fermat Pseudoprimes and I've written a program that works for reasonably small numbers, e.g. $le 10^6$. It just brute-force checks that $b^n-1 equiv 1bmod n$.



Now I'm asked to find the smallest prime or base 2 pseudoprime greater that $10^15$.



Python is unable to calculate $2^10^15-1 bmod 10^15$, never mind check case after case.



I must be missing a piece of Maths that will simplify the calculation massively.



Any suggestions?







share|cite|improve this question




















  • How are you calculating $2^10^15 - 1 pmod10^15$? I'm not having any problems with Python attempting that.
    – B. Mehta
    Aug 9 at 14:56











  • > 2 * * ( ( 10 * * 15 ) -1 ) % 10 * * 15
    – Fly by Night
    Aug 9 at 15:03







  • 1




    Ah, that explains it. Use pow(2, 10**15 - 1, 10**15) instead.
    – B. Mehta
    Aug 9 at 15:03










  • Why is that faster?
    – Fly by Night
    Aug 9 at 15:04










  • It optimises the exponentiation by using the fact that intermediates can be reduced mod $10^15$. I don't know the actual implementation, but a common method is to use exponentiation by squaring.
    – B. Mehta
    Aug 9 at 15:06














up vote
2
down vote

favorite












I'm reading the book Prime and Programming and I'm stuck on one of the computer exercises.



I'm checking for Fermat Pseudoprimes and I've written a program that works for reasonably small numbers, e.g. $le 10^6$. It just brute-force checks that $b^n-1 equiv 1bmod n$.



Now I'm asked to find the smallest prime or base 2 pseudoprime greater that $10^15$.



Python is unable to calculate $2^10^15-1 bmod 10^15$, never mind check case after case.



I must be missing a piece of Maths that will simplify the calculation massively.



Any suggestions?







share|cite|improve this question




















  • How are you calculating $2^10^15 - 1 pmod10^15$? I'm not having any problems with Python attempting that.
    – B. Mehta
    Aug 9 at 14:56











  • > 2 * * ( ( 10 * * 15 ) -1 ) % 10 * * 15
    – Fly by Night
    Aug 9 at 15:03







  • 1




    Ah, that explains it. Use pow(2, 10**15 - 1, 10**15) instead.
    – B. Mehta
    Aug 9 at 15:03










  • Why is that faster?
    – Fly by Night
    Aug 9 at 15:04










  • It optimises the exponentiation by using the fact that intermediates can be reduced mod $10^15$. I don't know the actual implementation, but a common method is to use exponentiation by squaring.
    – B. Mehta
    Aug 9 at 15:06












up vote
2
down vote

favorite









up vote
2
down vote

favorite











I'm reading the book Prime and Programming and I'm stuck on one of the computer exercises.



I'm checking for Fermat Pseudoprimes and I've written a program that works for reasonably small numbers, e.g. $le 10^6$. It just brute-force checks that $b^n-1 equiv 1bmod n$.



Now I'm asked to find the smallest prime or base 2 pseudoprime greater that $10^15$.



Python is unable to calculate $2^10^15-1 bmod 10^15$, never mind check case after case.



I must be missing a piece of Maths that will simplify the calculation massively.



Any suggestions?







share|cite|improve this question












I'm reading the book Prime and Programming and I'm stuck on one of the computer exercises.



I'm checking for Fermat Pseudoprimes and I've written a program that works for reasonably small numbers, e.g. $le 10^6$. It just brute-force checks that $b^n-1 equiv 1bmod n$.



Now I'm asked to find the smallest prime or base 2 pseudoprime greater that $10^15$.



Python is unable to calculate $2^10^15-1 bmod 10^15$, never mind check case after case.



I must be missing a piece of Maths that will simplify the calculation massively.



Any suggestions?









share|cite|improve this question











share|cite|improve this question




share|cite|improve this question










asked Aug 9 at 14:53









Fly by Night

25.2k32973




25.2k32973











  • How are you calculating $2^10^15 - 1 pmod10^15$? I'm not having any problems with Python attempting that.
    – B. Mehta
    Aug 9 at 14:56











  • > 2 * * ( ( 10 * * 15 ) -1 ) % 10 * * 15
    – Fly by Night
    Aug 9 at 15:03







  • 1




    Ah, that explains it. Use pow(2, 10**15 - 1, 10**15) instead.
    – B. Mehta
    Aug 9 at 15:03










  • Why is that faster?
    – Fly by Night
    Aug 9 at 15:04










  • It optimises the exponentiation by using the fact that intermediates can be reduced mod $10^15$. I don't know the actual implementation, but a common method is to use exponentiation by squaring.
    – B. Mehta
    Aug 9 at 15:06
















  • How are you calculating $2^10^15 - 1 pmod10^15$? I'm not having any problems with Python attempting that.
    – B. Mehta
    Aug 9 at 14:56











  • > 2 * * ( ( 10 * * 15 ) -1 ) % 10 * * 15
    – Fly by Night
    Aug 9 at 15:03







  • 1




    Ah, that explains it. Use pow(2, 10**15 - 1, 10**15) instead.
    – B. Mehta
    Aug 9 at 15:03










  • Why is that faster?
    – Fly by Night
    Aug 9 at 15:04










  • It optimises the exponentiation by using the fact that intermediates can be reduced mod $10^15$. I don't know the actual implementation, but a common method is to use exponentiation by squaring.
    – B. Mehta
    Aug 9 at 15:06















How are you calculating $2^10^15 - 1 pmod10^15$? I'm not having any problems with Python attempting that.
– B. Mehta
Aug 9 at 14:56





How are you calculating $2^10^15 - 1 pmod10^15$? I'm not having any problems with Python attempting that.
– B. Mehta
Aug 9 at 14:56













> 2 * * ( ( 10 * * 15 ) -1 ) % 10 * * 15
– Fly by Night
Aug 9 at 15:03





> 2 * * ( ( 10 * * 15 ) -1 ) % 10 * * 15
– Fly by Night
Aug 9 at 15:03





1




1




Ah, that explains it. Use pow(2, 10**15 - 1, 10**15) instead.
– B. Mehta
Aug 9 at 15:03




Ah, that explains it. Use pow(2, 10**15 - 1, 10**15) instead.
– B. Mehta
Aug 9 at 15:03












Why is that faster?
– Fly by Night
Aug 9 at 15:04




Why is that faster?
– Fly by Night
Aug 9 at 15:04












It optimises the exponentiation by using the fact that intermediates can be reduced mod $10^15$. I don't know the actual implementation, but a common method is to use exponentiation by squaring.
– B. Mehta
Aug 9 at 15:06




It optimises the exponentiation by using the fact that intermediates can be reduced mod $10^15$. I don't know the actual implementation, but a common method is to use exponentiation by squaring.
– B. Mehta
Aug 9 at 15:06















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%2f2877279%2ffinding-large-pseudoprimes-with-a-computer%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%2f2877279%2ffinding-large-pseudoprimes-with-a-computer%23new-answer', 'question_page');

);

Post as a guest













































































這個網誌中的熱門文章

tkz-euclide: tkzDrawCircle[R] not working

How to combine Bézier curves to a surface?

1st Magritte Awards