#include<bits/stdc++.h>
#define ll unsigned long long int
using namespace std;
ll mod(ll a, ll b, ll m)
{
ll r = 0;
a = a%m;
while(b > 0)
{
if(b&1) /*** b%2 == 1 ***/
r = (r + a)%m;
b = (b >> 1); /*** b = b/2 ***/
a = (a+a)%m;
}
return r;
}
int main()
{
ll a, b, m;
cout << "Enter First Number :: ";
cin >> a;
cout << "Enter Second Number :: ";
cin >> b;
cout << "Enter Mod Number :: ";
cin >> m;
cout << "After Modulo Operation :: ";
cout << mod(a, b, m) << "\n";
return 0;
}
Comments
Post a Comment