Cod sursa(job #894525)
| Utilizator | Data | 26 februarie 2013 21:47:54 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.48 kb |
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#define mod 1999999973
using namespace std;
int n, p;
int pow(int exponent) {
int jumatate = exponent / 2;
if(exponent == 0) return 1;
if(exponent == 1) return (n % mod);
int sol;
sol = (pow(jumatate) * pow(jumatate)) % mod;
if(exponent % 2 == 1) sol = (sol * n) % mod;
return sol;
}
int main() {
ifstream f("lgput.in");
ofstream g("lgput.out");
f>>n>>p;
g<<pow(p)<<"\n";
return 0;
}
