Cod sursa(job #2174571)
Utilizator | Data | 16 martie 2018 12:36:40 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.45 kb |
#include <fstream>
#define MOD 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
unsigned long long n,p,max1,x,putere;
int main()
{
f>>n>>p;
putere=1;
while(p>0)
{
if(p%2==1)
{
putere = ( putere % MOD ) * (n % MOD);
p--;
}
n = (n % MOD) * (n % MOD);
p >>= 1;
}
g<<putere;
return 0;
}
//1999999973
//4294967296