... HAVE U TRIED .... AT LEAST 3 TIMES ... OK U CAN SEE THIS ...

Sunday, January 12, 2014

UVA-374 :: Big Mod

//Problem  link>>http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=310


#include<bits/stdc++.h>
using namespace std ;

long long int b , p ,m , i ,x ;
long long bigmod (long long b , long long p)
{
    if (p==1) return b ;
    if (p==0) return 1 ;

    if (p&1)
    {
       return( bigmod(b,p-1) * (b%m) ) %m ;
    }
    else
    {
        x=bigmod(b,p/2) % m ;
        return (x*x) % m ;
    }

}

int main ()
{
    while (cin>>b>>p>>m)
    {
        cout<<bigmod(b,p)<<endl<<endl ;
    }

    return 0 ;
}

No comments:

Post a Comment