test: 5212571064332189696 divided by 31 = 168147453688135151.4838709
Then, 168147453688135151 times 31 = 5212571064332189681
if you subtract 5212571064332189681 from 5212571064332189696, you get 15.
Hi guys,
i am a beginner in c++.
Found this problem:
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.
-------------------------
And this is my solution :
int a , k;
unsigned int b;
cin>>a>>b>>k;
long long int total;
if(b==0)
cout<<1%k<
else if (b>0)
{total=1;
for(int i=1;i<=b;i++)
{
total*=a; }
cout<
----------------------------------------------
it functions well with small numbers but when i try with : 50 34 31 , it outputs 15 when it is supposed to output 28. I can't figure out the problem. please help.