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