HDU 1097 a hard puzzle
2016-03-12 20:23
363 查看
[align=left]Problem Description[/align]
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.
[align=left]Input[/align]
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
[align=left]Output[/align]
For each test case, you should output the a^b's last digit number.
[align=left]Sample Input[/align]
7 66
8 800
[align=left]Sample Output[/align]
9
6
简单来说,就是求前一个数的最后一个数的b次方的问题,很容易就看出来有规律,四个一循环,所以很容易就解决了。#include<stdio.h>
#include<math.h>
int main()
{
int a,b,a1,b1,sum;
while(scanf("%d%d",&a,&b)!=EOF)
{
a1=a%10;
b1=b%4;
if(b1==0){
sum=((int)pow(a1,4))%10;
printf("%d\n",sum);
}
else{
sum=((int)pow(a1,b1))%10;
printf("%d\n",sum);
}
}
}
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.
[align=left]Input[/align]
There are mutiple test cases. Each test cases consists of two numbers a and b(0<a,b<=2^30)
[align=left]Output[/align]
For each test case, you should output the a^b's last digit number.
[align=left]Sample Input[/align]
7 66
8 800
[align=left]Sample Output[/align]
9
6
简单来说,就是求前一个数的最后一个数的b次方的问题,很容易就看出来有规律,四个一循环,所以很容易就解决了。#include<stdio.h>
#include<math.h>
int main()
{
int a,b,a1,b1,sum;
while(scanf("%d%d",&a,&b)!=EOF)
{
a1=a%10;
b1=b%4;
if(b1==0){
sum=((int)pow(a1,4))%10;
printf("%d\n",sum);
}
else{
sum=((int)pow(a1,b1))%10;
printf("%d\n",sum);
}
}
}
相关文章推荐
- android 以追加形式写文件并把文件保存到SD卡中
- 李世石三比零败于AlphaGo,AlphaGo获胜已无悬念
- sum累加方式,python3.3,20160312
- python爬虫之BeautifulSoup
- Tomcat发布Maven项目遇到的种种异常
- 单例模式在JDBC数据库连接操作里的应用
- iOS面试试题(一)
- UICollectionView
- 韩服LOL
- 蓝桥杯 ALGO-108 最大体积 (动态规划)
- [置顶] 利用python实现批量插入打印信息的方法
- 状态栏通知
- SSH学习之路-前言
- 壹分贰分伍分换一元 有多少种换法
- cocos2dx3.X项目重写(四)添加地板,障碍物和碰撞检测
- 斯坦福大学深度学习笔记:逻辑回归
- C++求任意正数平方根
- jfinal 发布到tomcat使用共享目录中的jar问题
- 面试题目一
- 两个队列实现一个栈,要求实现Push以及Pop等方法