We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Your point about Devu Vs Police looked me little confusing but no worries I have shared your post with one of my old https://assignmentjunkie.co.uk/do-my-assignment collegue.I shall share the reviews little later.Thanks.
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
long long n1,k1,n2,k2,n,t,i,f,j,l;
cin>>t;
for(i=0;i<t;i++)
{cin>>n1>>k1>>n2>>k2>>n;
if(n1==0 && k1==0)
j=1;
j=pow(n1,k1);
if(n2==0 && k2==0)
l=1;
l=pow(n2,k2);
if (j==0 && l==0)
f=1;
f=pow(j,l);
cout<<f%n<<'\n';
}
giving error in some tests
dont know what is wrong with this code?
No more comments
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Python3 solution
Your point about Devu Vs Police looked me little confusing but no worries I have shared your post with one of my old https://assignmentjunkie.co.uk/do-my-assignment collegue.I shall share the reviews little later.Thanks.
static BigInteger solve(int n1, int k1, int n2, int k2, int n) { String s1 = String.valueOf(n1); String s2 = String.valueOf(n2); String s3 = String.valueOf(n); BigInteger b1, b2, b3; b1 = new BigInteger(s1); b2 = new BigInteger(s2); b3 = new BigInteger(s3); b1 = b1.pow(k1); b2 = b2.pow(k2); int i = b2.intValue(); BigInteger result = b1.pow(i); result = result.mod(b3); return result; }
Hints:
(1) Euler's theorem: if a and n are coprime positive integers, we have
where phi() is Euler's totient function. Fermat's little theorem is a special case of this where n is prime.
(2) What if a and n are not coprime? Try this:
where d=gcd(a,n) is the greatest common divisor of a and n.
These are the main ingredients of this problem. Watch out for boundary cases.