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。
来源

source=hdu" style="text-decoration:none; color:rgb(55,119,188)">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;
}

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

  1. LightOJ 1070 - Algebraic Problem 矩阵高速幂

    题链:http://lightoj.com/volume_showproblem.php?problem=1070 1070 - Algebraic Problem PDF (English) Sta ...

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

    题目链接:problem=1070">LightOJ 1070 Algebraic Problem 题意:已知a+b和ab的值求a^n+b^n.结果模2^64. 思路: 1.找递推式 ...

  3. HDU 2256 Problem of Precision(矩阵高速幂)

    题目地址:HDU 2256 思路: (sqrt(2)+sqrt(3))^2*n=(5+2*sqrt(6))^n; 这时要注意到(5+2*sqrt(6))^n总能够表示成an+bn*sqrt(6); a ...

  4. HDU - 5187 - zhx&#39;s contest (高速幂+高速乘)

    zhx's contest Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

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

    Problem Description During summer vacation,Alice stay at home for a long time, with nothing to do. S ...

  6. hdu 5187 高速幂高速乘法

    http://acm.hdu.edu.cn/showproblem.php?pid=5187 Problem Description As one of the most powerful brush ...

  7. [POJ 3150] Cellular Automaton (矩阵高速幂 + 矩阵乘法优化)

    Cellular Automaton Time Limit: 12000MS   Memory Limit: 65536K Total Submissions: 3048   Accepted: 12 ...

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

    题目描写叙述: http://acm.nyist.net/JudgeOnline/problem.php?pid=127 能够证明.修建N-1条虫洞就能够把这N个星系连结起来. 如今.问题来了.皇帝想 ...

  9. HDOJ 4686 Arc of Dream 矩阵高速幂

    矩阵高速幂: 依据关系够建矩阵 , 高速幂解决. Arc of Dream Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 65535/ ...

  10. poj 2778 AC自己主动机 + 矩阵高速幂

    // poj 2778 AC自己主动机 + 矩阵高速幂 // // 题目链接: // // http://poj.org/problem?id=2778 // // 解题思路: // // 建立AC自 ...

随机推荐

  1. Eclipse的PyDev插件安装及解决安装后找不到的问题

    一.环境 windows 7 64bit eclipse 4.5.2 pydev jdk7u55 二.安装步骤 1. 安装JDK eclipse依赖于Java环境,所以需要安装Java运行环境JRE. ...

  2. SQL Server连接不上本地服务器

    昨天星期一,到公司,如常打开电脑后,上个厕所,吃个早餐,电脑才完全醒来.打开项目后台,发现登不上,用户名或密码错误,认真输入几遍,还是错误,打开本地数据库,sql server连接不上,提示错误: 我 ...

  3. linux下vi修改文件用法

    进入vi的命令 vi filename :打开或新建文件,并将光标置于第一行首 vi +n filename :打开文件,并将光标置于第n行首 vi + filename :打开文件,并将光标置于最后 ...

  4. noi.ac NOIP2018 全国热身赛 第四场 T1 tree

    [题解] 考虑从小到大枚举边权,按顺序加边. 当前树被分成了若干个联通块,若各个块内的点只能跟块外的点匹配,那么最终的min g(i,pi)一定大于等于当前枚举的边. 判断各个联通块内的点是否全部能跟 ...

  5. Relocation(状压DP)

    Description Emma and Eric are moving to their new house they bought after returning from their honey ...

  6. Go切片的操作

    package main import "fmt" //切片的操作 func main() { //创建slice var s []int //zero value for sli ...

  7. [luoguP2577] [ZJOI2005]午餐(DP)

    传送门 显然吃饭时间越长的人排在前面越好,所以先排序. f[i][j]表示前i个人,A队的打饭时间为j的最优解,每个人只有两种选择,去A队或是去B队. #include <cstdio> ...

  8. [luoguP2015] 二叉苹果树(DP)

    传送门 貌似是个树形背包... 好像吧.. f[i][j]表示节点i选条边的最优解 #include <cstdio> #include <cstring> #include ...

  9. 匈牙利游戏(codevs 1269)

    题目描述 Description Welcome to the Hungary Games! The streets of Budapest form a twisted network of one ...

  10. Python()-类命名空间和对象/实例命名空间

    类命名空间和对象/实例命名空间: 创建类, 就会创建一个类的名称空间, 空间:存储类的属性 属性: 静态属性:直接定义在类下面 & 和类名关联 的变量 对象属性:在类内和self关联 & ...