A hard puzzle
来源:互联网 发布:贵州大数据培训 编辑:程序博客网 时间:2024/06/14 16:06
A hard puzzle
Time Limit : 2000/1000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other)
Total Submission(s) : 5 Accepted Submission(s) : 2
Font: Times New Roman | Verdana | Georgia
Font Size: ← →
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 668 800
Sample Output
96
Author
思路:
题意为求一个数a的n次方的最后一位数是什么。
草稿纸上随便写几个数就会发现 a^n的个位数是有规律的,并且和a的个位有关,比如3^n个位可能是3,9,7,1;8^n的个位可能是8,4,2,6;那么与n 什么关系呢 ?如果n的最后两位数对4求余,余几就是第几个,比如63^13215165,相当于求3^65的个位数65%4=1,那么63^13215165的个位数就是3。其他同理。
下面给出代码:
#include<iostream>#include<cstring>using namespace std;int main(){long long a,b;int c[4];while(cin>>a){cin>>b;int m=b%4;//求n对4的余数c[1]=a%10;for(int i=2;i<4;i++)//求a的个位数的四种可能情况,c[0],c[1],c[2],c[3]c[i]=(c[i-1]*c[1])%10;c[0]=(c[3]*c[1])%10;cout<<c[m]<<endl;}}
阅读全文
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
- CodeVS.1380 没有上司的舞会 (树形DP)
- HDU-2017 多校训练赛8-1011-Killer Names
- epoll服务器
- C#使用Xamarin开发可移植移动应用(3.Xamarin.Views控件)附源码
- 常用数字电路逻辑符号
- A hard puzzle
- Oracle和MySQL在SQL语句方面的区别
- [翻译]多种DLL注入技术原理介绍
- WebStart JNLP参数传递
- 安装kvm创建虚拟机的问题:VNC server running on '::1:5900'
- 处理编译错误"0" is an invalid value for the "DebugInformation" parameter of the "DCC"
- 【腾讯TMQ】这样的测试过程管理让你事半功倍
- 面试题:最常见最有可能考到的C语言面试题汇总
- 22