Cod sursa(job #293850)

Utilizator ScrazyRobert Szasz Scrazy Data 2 aprilie 2009 09:16:36
Problema Ridicare la putere in timp logaritmic Scor 0
Compilator cpp Status done
Runda Arhiva educationala Marime 0.46 kb
#include <cstdio>

#define ll long long

inline ll mod(ll a)
{ 
    ll res = a % 1999999973;
    while (res < 0) res += 1999999973;
}
ll a, b;

ll put(ll a, ll b)
{
    if (b == 0) return 1;
    ll aux = mod(put(a, b>>1));
    ll res = mod(aux * aux);
    if (b&1) res = mod(res * a);
    return mod(res);
}

int main()
{ 
    freopen("lgput.in","r",stdin);
    freopen("lgput.out","w",stdout);
    scanf("%lld%lld", &a, &b); 
    printf("%lld\n", put(a,b));
    return 0;
}