GDUFE ACM-1010

题目:http://acm.gdufe.edu.cn/Problem/read/id/1010

A hard puzzle(简单题)

Time Limit: 2000/1000ms (Java/Others)

Problem Description:

        GOJ gives a hard puzzle to C_Shit_Hu, super13, TestN,LOP: gave a and b,how to know the a^b.Everybody objects to this BT problem,so GOJ 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

思路:找规律,0 1 5 6每次的末位数都是自己本身,4 9是两次一循环,剩下的都是四次一循环,我直接用b%4看看应该用哪个末位数……超级暴力==

难度:如果像我这样取巧。。。还是比较简单的,但是。。还是用正常办法比较好,使用快速幂,我还没有学会,有时间再去看看。。

代码:
 1 #include<stdio.h>
 2 int main()
 3 {
 4     long long int a,b,c,i;
 5     while(~scanf("%lld %lld",&a,&b))
 6     {
 7         c=1;
 8         if(b%4==0)
 9             c=a*a*a*a;
10         else for(i=0;i<(b%4);i++)
11         {
12             c=c*a;
13         }
14         c=c%10;
15         printf("%lld
",c);
16     }
17     return 0;
18 }
原文地址:https://www.cnblogs.com/ruo786828164/p/6005132.html