Cod sursa(job #929660)
Utilizator | Data | 27 martie 2013 10:22:12 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.46 kb |
#include<fstream>
using namespace std;
const long mod = 1999999973;
long long n,p;
long long expBySquaring(long long x,long long n)
{
if (n==1) return x;
else if (n%2) return (x%mod*expBySquaring (x%mod*x%mod,(n-1)/2))%mod;
else return (expBySquaring(x%mod*x%mod,n/2))%mod;
}
ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{
f>>n>>p;
f.close();
g<<expBySquaring(n,p);
g.close();
return 0;
}