Cod sursa(job #492621)

Utilizator cristian9Cristian Zloteanu cristian9 Data 15 octombrie 2010 12:57:19
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.62 kb
#include<stdio.h>

int modulo(long a, long b, long c){
    long aux;
    if(b==0)
        return 1;
    if(b==1)
        return a;
    else
        if(b%2==0){
            aux=modulo(a, b/2, c);
            return  ((aux%c)*(aux%c))%c;
        }
        else{
            aux=modulo(a, b-2, c);
            return ((aux%c)*(aux%c)*(a%c))%c;
        }
}

int main(){
    freopen ("modulo.in", "r", stdin);
    freopen ("modulo.out", "w", stdout);

    long a, b, c;

    scanf("%ld %ld %ld ", &a, &b);
    //printf("%d %d %d ", a, b, c);
    printf("%ld ", modulo (a, b, 1999999973));

    return 0;
}