A - A hard puzzle解题报告(陈渊)

A - A hard puzzle
Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u
Submit  Status  Practice  HDU 1097

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
 

这个题目要注意两点,一个就是记得要用余数来计算,不能用a直接计算,第二个就是要注意余数的循环,其他的应该没有什么问题了。


#include<iostream>
using namespace std;
int main()
{
	int a,b,i,j=2,num,c[1000];
	while(cin>>a>>b)
	{
		a=a%10;
		c[1]=a;
		num=a;
		for(i=2;i<=b;i++)
		{
			num=num*a%10;
			if(num==a)
				goto next;
			else
				c[i]=num;
		}
next:
		j=b%(i-1);
		if(j==0)
			j=j+i-1;
		cout<<c[j]<<endl;
	}
	return 0;
}




你可能感兴趣的:(input,each,BT,64bit,output,Numbers)