Pagini recente » Cod sursa (job #2926374) | Cod sursa (job #558525) | Cod sursa (job #2273427) | Cod sursa (job #2539629) | Cod sursa (job #127446)
Cod sursa(job #127446)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int modulo(int a,int b,int c){
long long x=1,y=a; // long long is taken to avoid overflow of intermediate results
while(b > 0){
if(b%2 == 1){
x=(x*y)%c;
}
y = (y*y)%c; // squaring the base
b /= 2;
}
return x%c;
}
int main()
{
unsigned long int a,b,suma=0,div=0;
FILE *i;
FILE *o;
i=fopen("sumdiv.in","r");
o=fopen("sumdiv.out","w");
fscanf(i,"%lu%lu",&a,&b);
div=modulo(a,b,9901);
fprintf(o,"%lu",div);
return 0;
}