UVA Solution 374 - Big Mod - Solution in C, C++ | Volume 3 - Online Judge Solution

Latest

It is a free Online judges problems solution list. Here you can find UVA online Judge Solution, URI Online Judge Solution, Code Marshal Online Judge Solution, Spoz Online Judge Problems Solution

Friday, May 5, 2017

UVA Solution 374 - Big Mod - Solution in C, C++ | Volume 3

UVA Solution 374 - Big Mod - Solution in C, C++ | Volume 3


UVA Online Judge Solution 374 - Big Mod | Volume 3
UVA Problem Link - https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=5&page=show_problem&problem=310

Problem Name: 374 - Big Mod
Problem Number : UVA - 374 - Big Mod
Online Judge : UVA Online Judge Solution
Volume: 3
Solution Language : C, C plus plus

UVA Solution 374 - Big Mod - Solution in C, C++ | Volume 3


UVA Solution 374 - Big Mod Code in C, CPP:


#include<stdio.h>
long long Mod(long long x, long long y, long long m) {
 long long ans = 1, tmp = x;
 while(y) {
  if(y&1) {
   ans *= tmp;
   ans %= m;
  }
  y >>= 1;
  tmp *= tmp, tmp %= m;
 }
 return ans;
}
int main() {
 int B, P, M;
 while(scanf("%d %d %d", &B, &P, &M) == 3) {
  printf("%lld\n", Mod(B, P, M));
 }
    return 0;
}

No comments:

Post a Comment