Cod sursa(job #1656821)
| Utilizator | Data | 19 martie 2016 20:38:57 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 10 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.51 kb |
#include <iostream>
#include <stdio.h>
using namespace std;
long long int N,P;
const int m = 1999999973;
long long int lg(long long int N , long long int P){
if(P==0) return 1;
if(P==1) return N;
if(P%2==0) return (lg(N*N,P/2))%m;
else return (N*lg(N*N,(P-1)/2))%m;
}
int main()
{
FILE *f1,*f2;
f1=fopen("lgput.in","r");
f2=fopen("lgput.out","w");
fscanf(f1,"%lld",&N);
fscanf(f1,"%lld",&P);
fprintf(f2,"%lld",lg(N,P));
fclose(f1);
fclose(f2);
}
