A hard puzzle
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 28814 accepted submission (s): 10315
Problem descriptionlcy gives a hard puzzle to feng5166, LWG, jgshining And Ignatius: gave a and B, how to know the ^ B. everybody objects to this bt problem, so lcy makes the problem easier than begin.
This puzzle describes that: gave a and B, how to know the ^ B's the last digit number. but everybody is too lazy to slove this problem, so they remit to you who is wise.
Inputthere are mutiple test cases. Each test cases consists of two numbers a and B (0 <a, B <= 2 ^ 30)
Outputfor each test case, you should output the ^ B's last digit number.
Sample Input
7 668 800
Sample output
96
#include<iostream>#include<cstring>using namespace std;int q_mod(int a,int b,int c){int s=1;while(b){if(b&1) s=(s%10)*(a%c)%c;b=b>>1;a=(a%c)*(a%c)%c;}return s;}int main(){int n,m;while(cin>>n>>m){cout<<q_mod(n,m,10)<<endl;}return 0;}
Hduj 1097 a hard puzzle