Cod sursa(job #1740535)
| Utilizator | Data | 11 august 2016 18:17:58 | |
|---|---|---|---|
| Problema | Ridicare la putere in timp logaritmic | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva educationala | Marime | 0.5 kb |
#include<stdio.h>
using namespace std;
FILE *f1=fopen("lgput.in","r");
FILE *f2=fopen("lgput.out","w");
int n,p;
unsigned long long m=1999999973;
int putere(int a,int b){
int val;
if (b==0) return 1;
if (b%2==0){
val=putere(a,b/2)%m;
return ((val%m) * (val%m))%m;
}
val=putere(a,b-1)%1999999973;
return ((a%m)*val)%m;
}
int main(){
fscanf(f1,"%d%d",&n,&p);
fclose(f1);
fprintf(f2,"%d",putere(n,p));
fclose(f2);
return 0;
}
