HDU1097
来源:互联网 发布:广电网络 待遇 编辑:程序博客网 时间:2024/05/29 12:52
D - A hard puzzle
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的n次幂 最后一位,(对10取余)
#include<stdio.h>
#include<iostream>
using namespace std;
long long hanshu(long long a,long long n)
{
int b=10;
long long sum=1;
a%=b;
while(n>0)
{
if(n%2!=0)
sum=(sum*a)%b;
n/=2;
a=(a*a)%b;
}
return sum;
}
int main()
{
long long a,b;
while(scanf("%I64d%I64d",&a,&b)!=EOF)
{
printf("%I64d\n",hanshu(a,b));
}
return 0;
}
- hdu1097
- HDU1097
- hdu1097
- hdu1097
- HDU1097
- hdu1097
- HDU1097
- HDU1097
- hdu1097
- HDU1097
- hdu1097
- HDU1097
- HDU1097
- 【HDU1097】John
- hdu1097 A hard puzzle
- A hard puzzle(HDU1097)
- hdu1097 A hard puzzle
- HDU1097 A hard puzzle
- 在网吧写代码是怎样一种体验?
- 机器学习基础02-数理统计与参数估计
- Codeforces 742A. Arpa’s hard exam and Mehrdad’s naive cheat
- Java 反射机制详解
- 算法精解_C语言 链表_单链表(接口定义+类型实现)
- HDU1097
- HDU 1061
- AngularJS中的指令
- HDU 1575
- 前端开发工程师必须关注的几个性能指标
- 记 Vue 大型表单项目的一个性能问题
- MariaDB 5.5 字符集
- spring,structs2,hibernate 整合 xml版
- 如果你的网站没有JavaScript