Would somebody help me with this exercice?
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 < (a and k) ≤ 1000.
Output specification
Show just one integer number which is between 0 and k-1.
I know that you don't do homeworks.I wrote this code to solve this exercice.So I need some help to find the mistake..
#include <iostream>
#include <stdio.h>
using namespace std;
int main()
{
int m,n,k,result,remainder;
cin >> n >> m >> k;
result=1;
int cnt=1;
while (cnt<=m)
{
cnt=cnt+1;
result=result*n;
remainder=result%k;
}
printf ("%d",remainder);
return 0;
}