Cod sursa(job #2358137)
| Utilizator | Data | 27 februarie 2019 21:37:19 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <iostream>
#include <fstream>
#define Mod 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
long long x,y,sol=1;
long long putere(int x,int y)
{
if(y==1)
{
return x;
}
if(y==0)
{
return 1;
}
if(y%2==0)
{
sol=putere(x,y/2)%Mod;
sol=(sol*sol)%Mod;
}
else
{
sol=(putere(x,y-1))%Mod;
sol=(sol*x)%Mod;
}
}
int main()
{
f>>x>>y;
g<<putere(x,y)%Mod;
return 0;
}
