HTML & JS
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll modularExponentiation(ll x,ll n,ll M)
{                  
    if(n==0)        
        return 1; 
    else if(n%2 == 0)        //n is even
        return modularExponentiation((x*x)%M,n/2,M);
    else                             //n is odd
        return (x*modularExponentiation((x*x)%M,(n-1)/2,M))%M;
}
int main()
{       
	 ll x,n,p=1,a,m=1000000007;cin>>x>>n;
	 std::vector<ll> d(100002,0);
	 d[0]=1;
	 d[1]=1;
	 for (int i = 2; i < 1000; ++i)
	 {
	 	if(d[i]==0)
	 	{
	 		for(ll j=i*i;j<100000;j+=i)
	 		{
	 			d[j]=1;
	 		}
	 	}
	 }

	 std::vector<ll> v;
	 ll o=x;
	 for (int i = 2; i <= sqrt(x); ++i)
	 {
	 	if(d[i]==0 && x%i==0){
	 		v.push_back(i);
	 		while(o%i==0){o=o/i;}
	 	}
	 }
	 if(o>sqrt(x))
	 v.push_back(o);
	 for (int i = 0; i < v.size(); ++i)
	 {
	 	ll z=v[i];
	 	for (int j = 1; ; ++j)
	 	{
	 		if(n<pow(z,j)){
	 			a=j-1;
	 			break;
	 		}
	 		else if(pow(z,j)>pow(10,18)/z){
				 a=j;
				 break;
			}

	 	}
	 	for (int j = 1; j <= a; ++j)
	 	{
	 		ll q=(n/pow(z,j));
	 		p=(p*modularExponentiation(z,q,m))%m;
	 	}
	 }
	 cout<<p;
}            
             
             
              

Generated URL:

Output:

886507301
Report Bug