Uva 1230 - MODEX Soluiton





Problem Link: https://onlinejudge.org/index.php?option=onlinejudge&Itemid=8&page=show_problem&problem=3671 

Solution in C++: 

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll big_mod(ll base, ll power, ll mod)
{
    if(power==0)
        return 1;
    else if(power%2==1)
    {
        ll p1=base%mod;
        ll p2=(big_mod(base,power-1,mod))%mod;
        return (p1*p2)%mod;
    }
    else
    {
        ll p1=(big_mod(base,power/2,mod))%mod;
        return (p1*p1)%mod;
    }
}
int main()
{
    long long x,y,n,t;
    while(cin>>t)
    {
        if(t==0)
            break;
        else
        {
            while(t--)
            {
                cin>>x>>y>>n;
                cout<<big_mod(x,y,n)<<endl;
            }
        }
    }
}







No comments

Most View Post

Recent post

RESTful APIs with CRUD Operations in Laravel 12| (2025)

  RESTful APIs serve as the foundation of modern web development. They follow a set of rules called Representational State Transfer (REST) t...

Powered by Blogger.