当前位置:网站首页>HDU 1097 A hard puzzle
HDU 1097 A hard puzzle
2022-07-04 19:37:00 【Acacia moon tower】
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.
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
Answer key : This is a regular problem , The last number of each number changes periodically .
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
ll a, b;
int ans[][5] = {
{0},{1},{2,4,8,6},{3,9,7,1},{4,6},{5},{6},{7,9,3,1},{8,4,2,6},{9,1}};
while(cin>>a>>b) {
a %= 10;
if(a==0||a==1||a==5||a==6) {
cout<<ans[a][0]<<endl;
} else if(a==4||a==9) {
if(b%2==0) {
cout<<ans[a][1]<<endl;
} else {
cout<<ans[a][(b%2)-1]<<endl;
}
} else if(a==2||a==3||a==7||a==8) {
if(b%4==0) {
cout<<ans[a][3]<<endl;
} else {
cout<<ans[a][(b%4)-1]<<endl;
}
}
}
return 0;
}
边栏推荐
- Explore the contour drawing function drawcontours() of OpenCV in detail with practical examples
- Summary and sorting of 8 pits of redis distributed lock
- English语法_名词 - 使用
- .NET ORM框架HiSql实战-第二章-使用Hisql实现菜单管理(增删改查)
- Pytorch学习(四)
- Matrix flip (array simulation)
- 升级智能开关,“零火版”、“单火”接线方式差异有多大?
- Wechat reading notes of "work, consumerism and the new poor"
- MySQL数据库基本操作-DDL | 黑马程序员
- The 15th youth informatics competition in Shushan District in 2019
猜你喜欢
BCG 使用之新建向导效果
Pythagorean number law (any three numbers can meet the conditions of Pythagorean theorem)
The 300th weekly match of leetcode (20220703)
【问题】druid报异常sql injection violation, part alway true condition not allow 解决方案
LM10丨余弦波动顺势网格策略
黑马程序员-软件测试--09阶段2-linux和数据库-31-43修改文件权限字母发的说明,-查找链接修改文件,查找文件命令,链接文件,压缩解压方式,vi编辑器基本使用,
"Only one trip", active recommendation and exploration of community installation and maintenance tasks
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
Swagger突然发癫
Some thoughts on whether the judgment point is located in the contour
随机推荐
Use canal and rocketmq to listen to MySQL binlog logs
Educational Codeforces Round 22 E. Army Creation
Online data migration scheme encountered in the project 1 - general idea sorting and technical sorting
26. Delete the duplicate item C solution in the ordered array
黑马程序员-软件测试--08阶段2-linux和数据库-23-30-进程端口相关,修改文件权限,端口号信息的获取,程序和进程相关操作,linux命令案例
求2的n次方
Leetcode ransom letter C # answer
牛客小白月赛7 谁是神箭手
1009 Product of Polynomials(25 分)(PAT甲级)
MySQL数据库基本操作-DDL | 黑马程序员
The CDC of sqlserver can read the data for the first time, but it can't read the data after adding, deleting and modifying. What's the reason
Shell 编程核心技术《四》
How test engineers "attack the city" (Part 2)
在线文本行固定长度填充工具
Hough transform Hough transform principle
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
双冒号作用运算符以及命名空间详解
Lm10 cosine wave homeopathic grid strategy
2021 Hefei informatics competition primary school group
安徽 中安在线文旅频道推出“跟着小编游安徽”系列融媒体产品