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