Cod sursa(job #1999797)
Utilizator | Data | 12 iulie 2017 09:55:27 | |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.49 kb |
#include <iostream>
#include <fstream>
#define consta 1999999973
using namespace std;
ifstream f("lgput.in");
ofstream g("lgput.out");
int a,b,p=1;
void loga(){
while (b!=1)
{
if (b%2==1)
{
b--;
p*=a;
p=p%consta;
}
else
{
a*=a;
b/=2;
}
}
p*=a;
p=p%consta;
}
int main()
{
f >> a;
f >> b;
loga();
g << p;
return 0;
}