Cod sursa(job #883197)
Utilizator | UBB Bora Dan DaNutZ2UuU | Data | 19 februarie 2013 20:11:39 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <fstream>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
long long int x=1,A,B;
long long int modulo(long long int a,long long int b)
{
while(b > 0)
if(b % 2 != 0)
{
x = (x * a) % 1999999973;
b--;
}
else
{
a = (a * a) % 1999999973;
b /= 2;
}
return x;
}
int main ()
{
fin >> A >> B;
fout << modulo(A,B);
fin.close(); fout.close();
return 0;
}