Cod sursa(job #1334258)
| Utilizator | Data | 4 februarie 2015 09:42:31 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.45 kb |
#include <iostream>
#include <fstream>
#define mod 1999999973
using namespace std;
int power(int a, int b)
{
if (b==0) return 1;
if (b==1) return a;
if (b%2==0) return power((a*a)%mod , (b/2));
return ((a%mod) * power((a*a)%mod, (b/2)));
}
int main()
{
int n,m;
ifstream f("lgput.in");
ofstream g("lgput.out");
f >> n >> m;
g << power(n, m);
f.close();
g.close();
return 0;
}
