UVA 374 - Big Mod

UVA Sep 1, 2020

Problem PDF

Solution:

//#include
//
//int main()
//{
//    long long t,b,i,p,m,r;
//    while(scanf("%lld %lld %lld",&b,&p,&m)==3)
//    {
//        r=1;
//        while(p)
//        {
//            if(p%2!=0)
//            r=(r*b)%m;
//            b=(b*b)%m;
//            p/=2;
//        }
//        printf("%lld\n",r);
//    }
//    return 0;
//}
/******************************************************************
***   Problem       :                                           ***
***   Author        : Shipu Ahamed (Psycho Timekiller)          ***
***   E-mail        : [email protected]                   ***
***   University    : BUBT,Dept. of CSE                         ***
***   Team          : BUBT_Psycho                               ***
***   My Blog       : http://shipuahamed.blogspot.com           ***
***   Facebook      : http://www.facebook.com/DeesheharaShipu   ***
******************************************************************/

#include 
using namespace std;

#define for0(i,n) for(int i=0;i=0;i--)
#define rfor1(i,n) for(int i=n;i>=1;i--)
#define forse(i,a,b) for(int i=a;i<=b;i++)
#define ll long long
#define pi 2*acos(0.0)
#define all(v) v.begin(),v.end()

#define si(t) scanf("%d",&t)
#define sl(t) scanf("%lld",&t)
#define sf(t) scanf("%f",&t)
#define sdb(t) scanf("%lf",&t)
#define schar(c) scanf("%c",&c)
#define sstring(s) scanf("%s",s)
#define ssi(a,b) scanf("%d%d",&a,&b)
#define ssl(a,b) scanf("%lld%lld",&a,&b)

#define P(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PF(a) printf("%f\n",a)
#define PDB(a) printf("%lf\n",a)
#define PN(a) printf("%d ",a)
#define PLN(a) printf("%lld ",a)
#define PFN(a) printf("%f ",a)
#define PDBN(a) printf("%lf ",a)

#define CP(a) cout< " << (x) << endl;
#define db_sarr(i,a) cout<<#a<<"["< "< "< vi;
typedef  vector vl;
typedef  vector vs;
typedef  pair pii;
typedef  vector vpii;
typedef  set si;
typedef  map mii;
typedef  map msi;

////============ CONSTANT ===============////
#define MAXLL 9223372036854775807
#define MINLL 9223372036854775808
#define MAXL  2147483647
#define MINL  2147483648
#define mx7   10000007
#define mx6   1000006
#define inf   1<<30                                           //infinity value
#define eps   1e-9
#define mx    (100010)
#define mod   1000000007
////=====================================////

template string NumberToString( T Number ){stringstream st;st << Number;return st.str();}

int stringconvert(string s){int p; istringstream st(s); st>>p ; return p;}
int SOD(int n){int sum=0;for(int i=1;i*i<=n;i++)sum+=(n%i)?0:((i*i==n)?i:i+n/i);return sum;}
ll pow(ll a, ll b,ll Mod)
{
    if(b==0) return 1;
    if(b==1) return a;
    ll x=pow(a,b/2,Mod);
    x=(x*x)%Mod;
    if(b%2==1) x=(x*a)%Mod;
        return x;
}
int main()
{
    ll b,p,m;
    while(sl(b))
    {
        ssl(p,m);
        PL(pow(b,p,m));
    }
    return 0;
}
https://github.com/Shipu/OnlineJudgeProblemSolutionWithCPlusPlus/tree/master/uva/374/374.cpp

Tags

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.