Friday, March 25, 2016

UVa 374-Big Mod

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<bits/stdc++.h>
using namespace std;
long long m, a, b;

long long bigmod(long long b)
{
    if(b==0) return 1;
    else if(b%2==1) return (bigmod(b/2)*a*bigmod(b/2))%m;
    else return (bigmod(b/2)*bigmod(b/2))%m;
}

int main()
{
    while(scanf("%lld%lld%lld", &a,&b,&m)!=EOF) cout<<bigmod(b)<<endl;
    return 0;
}

1 comment:

  1. http://mahfuziu.blogspot.com/2016/03/modulo-of-big-number.html

    ReplyDelete