Cod sursa(job #1576314)
Utilizator | Data | 22 ianuarie 2016 11:53:52 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.43 kb |
#include <iostream>
#include<fstream>
using namespace std;
int main()
{
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n,p,x,s;
fin>>n>>p;
x=1999999973;
s=1;
while(n>1)
{
if(p%2==1)
{
s=(s*n)%x;
p--;
}
p=p/2;
n=(n*n)%x;
}
fout<<s;
fin.close();
fout.close();
}