HDU1097

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. 
 

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

 //忽略了b%t==0的边界情况,然后一直wrong。总结:写代码的时候把边界情况考虑清楚 ,经过验证了才提交答案。不要浮躁。


#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
#define maxn 300
__int64 a,b;
__int64 at[10000];
int main()
{
	//freopen("in.txt","r",stdin);
	while(scanf("%I64d%I64d",&a,&b)!=EOF)
	{
		
		__int64 t,w;
		t=0;
		w=a%10;
		for(__int64 i=0;i<b;i++)
		{
			if(i==0) at[t]=w;
			else
			 {
				w=(w*(a%10))%10;
				if(w==a%10) break;
				 at[t]=w;
			}
			t++;
		}
		//if(t==1)
		//{
		//	printf("%I64d\n",a%10);
		//}
		int st=b%t;
		if(st==0) st=t;
	 	else printf("%I64d\n",at[st-1]);
	}


}

你可能感兴趣的:(HDU1097)