Cod sursa(job #492752)

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

long long modulo(long long a, long long b, long long c){
    long long aux;
    if(b==0)
        return 1;
    if(b==1)
        return a%c;
    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 ("lgput.in", "r", stdin);
    freopen ("lgput.out", "w", stdout);

    long long a, b, c;

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

    return 0;
}