Pagini recente » Cod sursa (job #2368122) | Cod sursa (job #3222758) | Cod sursa (job #914360) | Cod sursa (job #2511681) | Cod sursa (job #127449)
Cod sursa(job #127449)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int modulo(int a,int b,int c){
long long div,suma=0;
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;
}
for(div=1;div<=x;div++)
{
if(x%div==0)
suma+=div;
}
return suma;
}
int main()
{
int a,b,div=0;
FILE *i;
FILE *o;
i=fopen("sumdiv.in","r");
o=fopen("sumdiv.out","w");
fscanf(i,"%d%d",&a,&b);
div=modulo(a,b,9901);
fprintf(o,"%d",div);
return 0;
}