Cod sursa(job #1464058)
Utilizator | Data | 22 iulie 2015 11:11:12 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <fstream>
#define M 1999999973
using namespace std;
long long fastexp(long long n, long long p)
{
if ( n == 0 ) return 1;
long long rez = 1;
while ( p != 0 )
{
if ( p % 2 == 1 )
rez = ( rez * n ) % M ;
n = ( n * n ) % M;
p = p / 2;
}
return rez;
}
int main()
{
int n, p;
ifstream fin("lgput.in");
fin>>n>>p;
ofstream fout("lgput.out");
fout<<fastexp(n, p);
return 0;
}