当前位置:网站首页>HDU-1097-A hard puzzle(快速幂)
HDU-1097-A hard puzzle(快速幂)
2022-07-28 05:28:00 【__Simon】
A hard puzzle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 39822 Accepted Submission(s): 14354
Problem Description
lcy gives a hard puzzle to feng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^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 a^b's the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.
this puzzle describes that: gave a and b,how to know the a^b's the last digit number.But everybody is too lazy to slove this problem,so they remit to you who is wise.
Input
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
Output
For each test case, you should output the a^b's last digit number.
Sample Input
7 66 8 800
Sample Output
9 6
Author
eddy
快速幂模板。
#include<iostream>
using namespace std;
typedef long long ll;
void ksm(int a,int b){
int r=1;
int base=a%10;
while(b){
if(b&1){
r=r*base%10;
}
base=base*base%10;
b>>=1;
}
cout<<r%10<<endl;
}
int main(){
int a,b;
while(cin>>a>>b){
ksm(a,b);
}
return 0;
}边栏推荐
猜你喜欢
随机推荐
Array solution script
AQS之CyclicBarrier源码解析
Dynamic memory management function of C language
Dynamic programming -- simple question type of climbing stairs
AQS之ReentrantLock源码解析
OJ 1507 删数问题
mysql-8.0.17-winx64(附加navicat)手动配置版安装
OJ 1129 fraction matrix
Water bottle effect production
Implementation of simple address book in [c language]
rancher部署实战
技术分享 | 使用postman发送请求
[queue, simple application of stack ---- packaging machine]
New Selenium
Graphic pipeline foundation (I)
Analysis of the semaphore source code of AQS
Execjs call
OJ 1284 counting problem
网络——数据链路层
C language memcpy library functions and the role of memmove









