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.
#define ll long long //a^b % modllpower(lla,llb,llmod){intans=1;while(b){if(b&1)ans=(ans*a)%mod;b/=2;a=a*a%mod;}returnans;}intsolve(stringstr1,stringstr2){llmod=1e9+7;longlonga=0,b=0;//reduce b using Euler's theorem ---> a^(m-1) = 1 mod mfor(lli=0;i<str2.length();++i){b=(b*10+(str2[i]-'0'))%(mod-1);}//reduce a using mod for(lli=0;i<str1.length();++i){a=(a*10+(str1[i]-'0'))%mod;}returnpower(a,b,mod);}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Power of large numbers
You are viewing a single comment's thread. Return to all comments →