Cod sursa(job #127449)

Utilizator soriynSorin Rita soriyn Data 23 ianuarie 2008 22:21:54
Problema Suma divizorilor Scor 30
Compilator c Status done
Runda Arhiva de probleme Marime 0.66 kb
#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;
}