A hard puzzle
来源:互联网 发布:淘宝店铺第三方 编辑:程序博客网 时间:2024/06/11 17:01
A hard puzzle
问题描述 :
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.
输入:
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
输出:
For each test case, you should output the a^b’s last digit number.
样例输入:
7 668 800
样例输出:
96
题解:题意是求a^b的最后一位数,这里是用快速幂来解决的,也就是边乘边模,这样可以避免溢出。
#include<stdio.h>#include<string.h>typedef long long LL;LL fun(LL x,LL n){LL res=1;while(n>0){if(n&1){res=(res*x)%10;}x=(x*x)%10;n>>=1;}return res%10;}int main(){LL a,b;while(scanf("%d%d",&a,&b)!=EOF){printf("%d\n",fun(a,b)%10);}return 0;}
0 0
- A hard puzzle
- 1097 A hard puzzle
- hdu1097 A hard puzzle
- 1097A hard puzzle
- 1097 A hard puzzle
- HDU - A hard puzzle
- A hard puzzle(HDU1097)
- A hard puzzle
- A hard puzzle(1097)
- hdu1097 A hard puzzle
- HDU A hard puzzle
- HDU1097 A hard puzzle
- HDU1097 A hard puzzle
- 1097 A hard puzzle
- A hard puzzle
- A hard puzzle
- A hard puzzle
- 1097 A hard puzzle
- Mysql开启远程连接方法
- Android开发艺术探索<Drawable系列之二ShapeDrawable>
- uva 10815 小紫<set>
- Java 8 中 Date与LocalDateTime、LocalDate、LocalTime互转
- DoTween
- A hard puzzle
- ROS图像相关包
- 约翰·卡马克和他的id Software
- 编译器设计:整型立即数支持
- Reorder List ---LeetCode
- php取周的第一天和最后一天
- C语言双重置换加密
- java 初探(五)
- ECSHOP网站程序可以绕过权限上传一句话木马