Cod sursa(job #1223293)
| Utilizator | Data | 26 august 2014 10:52:49 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 0 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.58 kb |
#include <fstream>
#include <cmath>
using namespace std;
ifstream fin("lgput.in");
ofstream fout("lgput.out");
const long long MOD = 1999999973;
long long a, b;
void Putere();
int main()
{
fin >> a >> b;
Putere();
fin.close();
fout.close();
return 0;
}
void Putere()
{
long long p = 1;
while ( b > 0 )
{
if ( b % 2 )
{
p *= a;
p %= MOD;
b--;
}
if ( !b ) break;
p = p * p;
p %= MOD;
b /= 2;
}
fout << p << '\n';
}
