码迷,mamicode.com
首页 > 其他好文 > 详细

NYOJA^B Problem

时间:2015-02-04 16:49:28      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:nyojab problem

A^B Problem

时间限制:1000 ms  |  内存限制:65535 KB
难度:2
描述
Give you two numbers a and b,how to know the a^b‘s the last digit number.It looks so easy,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
提示

There is no such case in which a = 0 && b = 0。

#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
int main()
{
	int i,n,m,k,ans,t,vis[15],a[15];
	while(scanf("%d%d",&n,&m)==2){
		k=n%10;ans=1;t=0;
		memset(vis,0,sizeof(vis));
		if(m==0){
			printf("1\n");continue;
		}
		else if(n==0){
			printf("0\n");continue;
		}
		for(i=0;i<m;++i){
			ans=ans*k%10;
			if(vis[ans]==0){
				vis[ans]=1;
				a[t]=ans;
				t++;
			}
			else break;
		}
		if(i==m)printf("%d\n",ans);
		else
		 printf("%d\n",a[(m-1)%t]);
	}
	return 0;
}        

NYOJA^B Problem

标签:nyojab problem

原文地址:http://blog.csdn.net/r1986799047/article/details/43485971

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!