Cod sursa(job #914488)
| Utilizator | Data | 14 martie 2013 10:37:49 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 30 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include<fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
int n, p;
int power(int n, int p){
if(p == 0)
return 1;
int x = power(n, p/2);
if(p%2 == 0)
return (long long) x*x%1999999973;
else
return (long long) x*x*(long long)n%1999999973;
}
int main(){
fin >> n >> p;
fout << power(n, p);
fin.close();
fout.close();
return 0;
}
