首页 > ACM题库 > HDU-杭电 > HDU 1097 A hard puzzle-快速幂-[解题报告] C++
2013
11-27

HDU 1097 A hard puzzle-快速幂-[解题报告] C++

A hard puzzle

问题描述 :

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.

输入:

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

输出:

For each test case, you should output the a^b’s last digit number.

样例输入:

7 66
8 800

样例输出:

9
6

hdu 1097 A hard puzzle
好吧,这个题我承认我没有快速幂取模,我找的规律通过尾数的的规律你会发现,尾数为0,1,5,6的不管是多少次方尾数依然不变,而尾数为4和9的每2次循环,2,3,7,8为每4次循环,就是这么水过啦~~~~~!!!


#include<iostream>

using namespace std;

int ldigit[10][4]={{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 main()

{

 int a,b;

 int d;

 while(scanf("%d%d",&a,&b)!=EOF)

 {

 d=a;

 if(d==0||d==1||d==5||d==6)

 printf("%d\n",d);

 else if(d==4||d==9) 

cout<<ldigit[d][b%2]<<endl;

 else if(d==2||d==3||d==7||d==8)

 cout<<ldigit[d][b%4]<<endl;

 }

 return 0;

}

  1. 第二个方法挺不错。NewHead代表新的头节点,通过递归找到最后一个节点之后,就把这个节点赋给NewHead,然后一直返回返回,中途这个值是没有变化的,一边返回一边把相应的指针方向颠倒,最后结束时返回新的头节点到主函数。

  2. A猴子认识的所有猴子和B猴子认识的所有猴子都能认识,这句话用《爱屋及乌》描述比较容易理解……

  3. 第2题,TCP不支持多播,多播和广播仅应用于UDP。所以B选项是不对的。第2题,TCP不支持多播,多播和广播仅应用于UDP。所以B选项是不对的。