杭电OJ 1097 A hard puzzle(我最后的博客水题报告)

来源:互联网 发布:k60单片机 编辑:程序博客网 时间:2024/05/16 14:07

A hard puzzle
Problem Description

lcy gives a hard puzzle tofeng5166,lwg,JGShining and Ignatius: gave a and b,how to know the a^b.everybodyobjects 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.Buteverybody is too lazy to slove this problem,so they remit to you who is wise.

 

 

Input

There are mutiple test cases. Each test casesconsists of two numbers a and b(0<a,b<=2^30)

 

 

Output

For each test case, you should output thea^b's last digit number.

 

 

Sample Input

7 66

8 800

 

 

Sample Output

9

6

 

这是我最后一次在博客上发水题的解题报告了。我虽然还会在杭电上刷水题,但是不会再做(过于简单的)水题的解题报告了。

当然,如果遇到困住我的水题(~~脸红),我还是会写出详细的解题报告,只不过不会把这道题放在水题的分类中,而是放在经验总结中。

就把这道无耻打表AC题,作为水题报告的终点吧。

</pre><pre>
<pre name="code" class="cpp">/*规律十分明显,但由于取余的关系,对周期T取余的值域为{0, 1, 2,...,T-1}, 末尾数字i的周期T的最后一个数在ans[i][0]中,而不是ans[i][T]中*/ #include <stdio.h>int ans[10][10] = {{0},   {1},   {6, 2, 4, 8},   {1, 3, 9, 7},   {6, 4},   {5},   {6},   {1, 7, 9, 3},   {6, 8, 4, 2},   {1, 9}};int T[10] = {1, 1, 4, 4, 2, 1, 1, 4, 4, 2};/*末尾数字i 对应的周期就是 T[i]*/int main(){int a, b;while (scanf("%d%d", &a, &b) != EOF) {a = a % 10;b = b % T[a];printf("%d\n", ans[a][b]);}return 0;}





0 0
原创粉丝点击