Professional Documents
Culture Documents
if(exp==1)
return base;
else
if(exp%2 == 0)
return base1%1000000007;
else
return base1;
else
return ans%1000000007;
else
return ans;
}
}
ll res=1;
while(exp>0) {
if(exp%2==1) res=(res*base)%MOD;
base=(base*base)%MOD;
exp/=2;
return res%MOD;
To Find Prime
If you do not find a factor less than x−−√, then x is prime for the following reason. Consider the
opposite, you find two factors larger than x−−√, say a and b. But then a⋅b>x−−√x−−√=x.
Therefore, if there is a factor larger than x−−√, there must also exist a factor smaller than x−
−√, otherwise their product would exceed the value of x.