Power of power modulo with non square-free numbers

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











up vote
0
down vote

favorite












Reference https://www.hackerrank.com/challenges/devu-police/problem



I have five numbers a, b, c, d, N and I need to find $(a^b)^c^d$ mod N. N is non square-free number so euler totient theorem or CRT won't work here.



I have tried this way but according to test-cases my program gets timed out. I find $a^b$ mod N then I run power modulo with algorithm https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/ here exponent divided by 2 and I do with c so each computation needs O(d) which should not be rather logarithm solution expected.



Could you please help me to solve?







share|cite|improve this question





















  • Euler's totient theorem does not need a squarefree modulo, it is enough that the base is coprime to the modulo.
    – Peter
    Jul 28 at 11:45










  • This will be useful for your problem : en.wikipedia.org/wiki/Carmichael_function
    – Peter
    Jul 28 at 11:51










  • @Peter if they r not co-prime then what?
    – Debasis Jana
    Jul 28 at 12:08










  • If you know the factorization of $N$, my link should solve the problem.
    – Peter
    Jul 28 at 12:19










  • @Peter thank you ... :) actually I didn't go through your link .. ;)
    – Debasis Jana
    Jul 28 at 12:36














up vote
0
down vote

favorite












Reference https://www.hackerrank.com/challenges/devu-police/problem



I have five numbers a, b, c, d, N and I need to find $(a^b)^c^d$ mod N. N is non square-free number so euler totient theorem or CRT won't work here.



I have tried this way but according to test-cases my program gets timed out. I find $a^b$ mod N then I run power modulo with algorithm https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/ here exponent divided by 2 and I do with c so each computation needs O(d) which should not be rather logarithm solution expected.



Could you please help me to solve?







share|cite|improve this question





















  • Euler's totient theorem does not need a squarefree modulo, it is enough that the base is coprime to the modulo.
    – Peter
    Jul 28 at 11:45










  • This will be useful for your problem : en.wikipedia.org/wiki/Carmichael_function
    – Peter
    Jul 28 at 11:51










  • @Peter if they r not co-prime then what?
    – Debasis Jana
    Jul 28 at 12:08










  • If you know the factorization of $N$, my link should solve the problem.
    – Peter
    Jul 28 at 12:19










  • @Peter thank you ... :) actually I didn't go through your link .. ;)
    – Debasis Jana
    Jul 28 at 12:36












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Reference https://www.hackerrank.com/challenges/devu-police/problem



I have five numbers a, b, c, d, N and I need to find $(a^b)^c^d$ mod N. N is non square-free number so euler totient theorem or CRT won't work here.



I have tried this way but according to test-cases my program gets timed out. I find $a^b$ mod N then I run power modulo with algorithm https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/ here exponent divided by 2 and I do with c so each computation needs O(d) which should not be rather logarithm solution expected.



Could you please help me to solve?







share|cite|improve this question













Reference https://www.hackerrank.com/challenges/devu-police/problem



I have five numbers a, b, c, d, N and I need to find $(a^b)^c^d$ mod N. N is non square-free number so euler totient theorem or CRT won't work here.



I have tried this way but according to test-cases my program gets timed out. I find $a^b$ mod N then I run power modulo with algorithm https://www.geeksforgeeks.org/modular-exponentiation-power-in-modular-arithmetic/ here exponent divided by 2 and I do with c so each computation needs O(d) which should not be rather logarithm solution expected.



Could you please help me to solve?









share|cite|improve this question












share|cite|improve this question




share|cite|improve this question








edited Jul 28 at 8:14
























asked Jul 28 at 7:47









Debasis Jana

63




63











  • Euler's totient theorem does not need a squarefree modulo, it is enough that the base is coprime to the modulo.
    – Peter
    Jul 28 at 11:45










  • This will be useful for your problem : en.wikipedia.org/wiki/Carmichael_function
    – Peter
    Jul 28 at 11:51










  • @Peter if they r not co-prime then what?
    – Debasis Jana
    Jul 28 at 12:08










  • If you know the factorization of $N$, my link should solve the problem.
    – Peter
    Jul 28 at 12:19










  • @Peter thank you ... :) actually I didn't go through your link .. ;)
    – Debasis Jana
    Jul 28 at 12:36
















  • Euler's totient theorem does not need a squarefree modulo, it is enough that the base is coprime to the modulo.
    – Peter
    Jul 28 at 11:45










  • This will be useful for your problem : en.wikipedia.org/wiki/Carmichael_function
    – Peter
    Jul 28 at 11:51










  • @Peter if they r not co-prime then what?
    – Debasis Jana
    Jul 28 at 12:08










  • If you know the factorization of $N$, my link should solve the problem.
    – Peter
    Jul 28 at 12:19










  • @Peter thank you ... :) actually I didn't go through your link .. ;)
    – Debasis Jana
    Jul 28 at 12:36















Euler's totient theorem does not need a squarefree modulo, it is enough that the base is coprime to the modulo.
– Peter
Jul 28 at 11:45




Euler's totient theorem does not need a squarefree modulo, it is enough that the base is coprime to the modulo.
– Peter
Jul 28 at 11:45












This will be useful for your problem : en.wikipedia.org/wiki/Carmichael_function
– Peter
Jul 28 at 11:51




This will be useful for your problem : en.wikipedia.org/wiki/Carmichael_function
– Peter
Jul 28 at 11:51












@Peter if they r not co-prime then what?
– Debasis Jana
Jul 28 at 12:08




@Peter if they r not co-prime then what?
– Debasis Jana
Jul 28 at 12:08












If you know the factorization of $N$, my link should solve the problem.
– Peter
Jul 28 at 12:19




If you know the factorization of $N$, my link should solve the problem.
– Peter
Jul 28 at 12:19












@Peter thank you ... :) actually I didn't go through your link .. ;)
– Debasis Jana
Jul 28 at 12:36




@Peter thank you ... :) actually I didn't go through your link .. ;)
– Debasis Jana
Jul 28 at 12:36















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%2f2865076%2fpower-of-power-modulo-with-non-square-free-numbers%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%2f2865076%2fpower-of-power-modulo-with-non-square-free-numbers%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?