当前位置:网站首页>HDU 1097 A hard puzzle
HDU 1097 A hard puzzle
2022-07-04 17:58:00 【相思明月楼】
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
题解:这是一道规律题,每个数的最后一个数按周期变化。
#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;
}
边栏推荐
猜你喜欢
Lex and yacc based lexical analyzer + parser
Upgrade the smart switch, how much is the difference between the "zero fire version" and "single fire" wiring methods?
There are multiple divs in the large div, which are displayed on the same line. After overflow, scroll bars are generated without line breaks
读写关闭的channel是啥后果?
神经网络物联网应用技术学什么
Rookie post station management system based on C language
2022CoCa: Contrastive Captioners are Image-Text Fountion Models
【uniapp】uniapp开发app在线预览pdf文件
小发猫物联网平台搭建与应用模型
FPGA时序约束分享01_四大步骤简述
随机推荐
Detailed explanation of issues related to SSL certificate renewal
DeFi生态NFT流动性挖矿系统开发搭建
26. 删除有序数组中的重复项 C#解答
2022养生展,健康展,北京大健康展,健康产业展11月举办
How test engineers "attack the city" (Part 2)
2022-07-04: what is the output of the following go language code? A:true; B:false; C: Compilation error. package main import 'fmt' func
Qt实现界面滑动切换效果
读写关闭的channel是啥后果?
Guys, for help, I use MySQL CDC 2.2.1 (Flink 1.14.5) to write Kafka and set
LeetCode第300场周赛(20220703)
Using FTP
The page element is vertically and horizontally centered, realizing the vertical and horizontal centering of known or unknown width.
奥迪AUDI EDI INVOIC发票报文详解
启牛开的证券账户安全吗?
. Net ORM framework hisql practice - Chapter 2 - using hisql to realize menu management (add, delete, modify and check)
《工作、消费主义和新穷人》的微信读书笔记
Nebula importer data import practice
IBM WebSphere MQ retrieving messages
Is the securities account opened by qiniu safe?
发送和接收IBM WebSphere MQ消息