Cod sursa(job #127446)

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