Cod sursa(job #632938)
Utilizator | Iulian spadasino | Data | 12 noiembrie 2011 15:54:07 |
---|---|---|---|
Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
Compilator | cpp | Status | done |
Runda | Arhiva educationala | Marime | 0.41 kb |
#include <iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
#define modulo 1999999973
int f(int N, int P)
{
if(P==0) return 1;
long long x = f(N,P/2) ;
if(P%2==1) return (x * x) % modulo * N % modulo;
else return (x * x) % modulo;
}
int main()
{ int P;
int N;
freopen("lgput.in","r",stdin);
freopen("lgput.out","w",stdout);
cin>>N>>P;
cout<<f(N,P);
}