Pagini recente » Cod sursa (job #1352069) | Cod sursa (job #54853) | Cod sursa (job #496424) | Cod sursa (job #39721) | Cod sursa (job #127450)
Cod sursa(job #127450)
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int modulo(int a,int b,int c){
unsigned long long div,suma=0;
unsigned 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()
{
unsigned long long a,b,div=0;
FILE *i;
FILE *o;
i=fopen("sumdiv.in","r");
o=fopen("sumdiv.out","w");
fscanf(i,"%llu%llu",&a,&b);
div=modulo(a,b,9901);
fprintf(o,"%d",div);
return 0;
}