a^b modulus k Question: Write a program that calculates bth power of a modulus k. For example, if you are asked to calculate 2^6 mod 7; 6th power of 2 is 64 thus 64 modulus 7 is 1.
Input specification You will be given 3 integers, a, b, and k where b represents the power and k represents the modulus operand and 0 ≤ b ≤ 1000 and 1 < (a and k) ≤ 1000.
Output specification Show just one integer number which is between 0 and k-1.
Sample Input I
2 6 5
Sample Output I
4
#include <iostream>
#include <math.h>
using namespace std;
int main(){
int a, b, k, d;
cin >> a >> b >> k;
int poew = pow(a, b);
d = poew % k;
cout << d;
}
It works well but it fails at test case 5;
Test Case 5:
---------- input.txt ----------
50 34 31
---------- pattern.txt ----------
28