nyoj473 A^B 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。
来源
hdu
上传者
ACM_丁国强

#include <stdio.h>
int main()
{
	int a,b,_a,s;
	while(scanf("%d %d",&a,&b)!=EOF)
	{
		if(a==0&&b==0)
		break;
		s=1;
		while(b)
		{
			if(s>=10)
			s=s%10;
			if(a>=10)
			a=a%10;
			if(b%2==1)
			s=s*a;
			a=a*a;
			b=b/2;
		}
		if(s>=10)
		s=s%10;
		printf("%d\n",s);
	}
	return 0;
}                
时间: 2024-11-03 22:01:30

nyoj473 A^B Problem (高速幂)的相关文章

LightOJ 1070 Algebraic Problem (推导+矩阵高速幂)

题目链接:problem=1070">LightOJ 1070 Algebraic Problem 题意:已知a+b和ab的值求a^n+b^n.结果模2^64. 思路: 1.找递推式 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" > 得到递推式之后就是矩阵高速幂了 注意:模2^64,定

NYOJ127 星际之门(一)(最小生成数的个数+高速幂)

题目描写叙述: http://acm.nyist.net/JudgeOnline/problem.php?pid=127 能够证明.修建N-1条虫洞就能够把这N个星系连结起来. 如今.问题来了.皇帝想知道有多少种修建方案能够把这N个星系用N-1条虫洞连结起来? 输入 第一行输入一个整数T,表示測试数据的组数(T<=100) 每组測试数据仅仅有一行.该行仅仅有一个整数N.表示有N个星系. (2<=N<=1000000) 输出 对于每组測试数据输出一个整数.表示满足题意的修建的方案的个数.

HDOJ 4686 Arc of Dream 矩阵高速幂

矩阵高速幂: 依据关系够建矩阵 , 高速幂解决. Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) Total Submission(s): 2164    Accepted Submission(s): 680 Problem Description An Arc of Dream is a curve defined by following fun

hdu 5318 The Goddess Of The Moon 矩阵高速幂

链接:http://acm.hdu.edu.cn/showproblem.php?pid=5318 The Goddess Of The Moon Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 438    Accepted Submission(s): 150 Problem Description Chang'e (嫦娥) is

HDU 5411 CRB and puzzle (Dp + 矩阵高速幂)

CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 483    Accepted Submission(s): 198 Problem Description CRB is now playing Jigsaw Puzzle. There are  kinds of pieces with infinite

HDU 2604 Queuing 矩阵高速幂

QueuingTime Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2483    Accepted Submission(s): 1169 Problem Description Queues and Priority Queues are data structures which are known to most computer s

HDOJ 5411 CRB and Puzzle 矩阵高速幂

直接构造矩阵,最上面一行加一排1.高速幂计算矩阵的m次方,统计第一行的和 CRB and Puzzle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 133    Accepted Submission(s): 63 Problem Description CRB is now playing Jigsaw Puzzle. There

hdu 5187 高速幂高速乘法

http://acm.hdu.edu.cn/showproblem.php?pid=5187 Problem Description As one of the most powerful brushes, zhx is required to give his juniors n problems. zhx thinks the ith problem's difficulty is i. He wants to arrange these problems in a beautiful wa

HDU 4965 Fast Matrix Calculation(矩阵高速幂)

题目大意:给你两个数字n和k,然后给你两个矩阵a是n*k的和b是k*n的,矩阵c = a*b,让你求c^(n*n). 直接求的话c是n*n的矩阵所以是1000*1000.会超时的啊. 能够转化一下:(a*b)^(n*n)=a*(b*a)^(n*n-1)*b.b*a能够得到一个k*k的矩阵,k非常小所以不会超时.高速幂一下就能够了啊. Fast Matrix Calculation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 13

HDU4869:Turn the pokers(费马小定理+高速幂)

Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. She went out and bought m pokers, tending to play poker. But she hated the traditional gameplay. She wants to change. She puts these pokers face down,