Cod sursa(job #1456243)
Utilizator | Data | 30 iunie 2015 10:48:20 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.38 kb |
#include<iostream>
#include<fstream>
using namespace std;
const int m = 1999999973;
ifstream f("lgput.in");
ofstream g("lgput.out");
int main()
{
int n,p;
long long int x,sol = 1;
f>>n>>p;
x=n;
for(int i = 0 ;(1<<i)<=p;i++)
{
if( ((1<<i) & p)!=0)
sol = (sol * x) % m;
x=(x*x)%m;
}
g<<sol;
return 0;
}