HDU1097暴力打表找规律a^b
来源:互联网 发布:淘宝如何设置子账号 编辑:程序博客网 时间:2024/06/06 01:44
A hard puzzle
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 44659 Accepted Submission(s): 16333Problem 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.Output
For each test case, you should output the a^b’s last digit number.Output
For each test case, you should output the a^b’s last digit number.
Sample Input
7 66
8 800Sample Output
9
6
思路
1、还是打表找规律,找a^b值的个位数
打表找规律代码
打表a从1-15,b从1-10找规律
#include <stdio.h>#include <iostream>using namespace std;int main(){ for(int i=1;i<=15;i++) { long int sum=1; for(int j=1;j<=10;j++) { sum*=i; if(sum>100) sum%=100; cout<<sum%10<<" "; } cout<<endl; } return 0;}
可以看出a从1-10顺序规律,b也可以看出每项规律。放入二维数组即可
代码
#include <iostream>#include <math.h>#include <stdio.h>using namespace std;int main(){ long int a,b; int s[10][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=a%10; if(a==0) cout<<s[0][0]<<endl; if(a==1) cout<<s[1][0]<<endl; if(a==2) { int m=(b%4)-1; if(m==-1) m=3; cout<<s[2][m]<<endl; } if(a==3) { int m=(b%4)-1; if(m==-1) m=3; cout<<s[3][m]<<endl; } if(a==4) { int m=(b%2)-1; if(m==-1) m=1; cout<<s[4][m]<<endl; } if(a==5) { cout<<s[5][0]<<endl; } if(a==6) cout<<s[6][0]<<endl; if(a==7) { int m=(b%4)-1; if(m==-1) m=3; cout<<s[7][m]<<endl; } if(a==8) { int m=(b%4)-1; if(m==-1) m=3; cout<<s[8][m]<<endl; } if(a==9) { int m=(b%2)-1; if(m==-1) m=1; cout<<s[9][m]<<endl; } } return 0;}
- HDU1097暴力打表找规律a^b
- 快速幂或找规律求a的b次方的最后一位-HDU1097
- codeforces round#366(div2) A(暴力)B(博弈 找规律)C(模拟 队列)
- hdu1097 A hard puzzle
- A hard puzzle(HDU1097)
- hdu1097 A hard puzzle
- HDU1097 A hard puzzle
- HDU1097 A hard puzzle
- HDU1097 A hard puzzle
- hdu1097 A hard puzzle
- hdu1097 A hard puzzle
- hdu1097 A hard puzzle
- hdu1097 A hard puzzle
- hdu1097 - A hard puzzle
- hdu1097 A hard puzzle
- HDU 1061暴力打表找规律
- hdu1097
- HDU1097
- Request对象的主要方法
- 拓扑
- Java内部类的分类
- 编程实现统计某年某月份的天数。 例如:输入:2017.7 输出:31天
- Asset Store下载的package的位置
- HDU1097暴力打表找规律a^b
- session和cookie
- LeetCode 198 House Robber
- 1的个数
- C语言之数据输出printf( )和putchar( )
- SDPhotoBrowser 非常简单易用的图片浏览
- [LintCode]Longest Common Prefix(Python)
- 练习 2-8 编写一个函数rightrot(x, n),该函数返回将x循环右移(即从最右端移出的位将从最左端移入)n(二进制)位后所得到的值。
- 2017 多校4 1003 Counting Divisors