Mai intai trebuie sa te autentifici.
Cod sursa(job #1464071)
Utilizator | Data | 22 iulie 2015 11:33:43 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.47 kb |
#include <iostream>
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n,p,x = 1;
int rid(int n,int p)
{
int x = 1;
while(p > 0)
{
if ( p % 2 == 1 )
{
x = x * n ;
p --;
}
else
{
p = p / 2 ;
n = n * n;
}
}
return x;
}
int main()
{
fin>>n>>p;
fout<<rid(n,p)%1999999973;
return 0;
}