博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU1061_Rightmost Digit【高速幂取余】
阅读量:4673 次
发布时间:2019-06-09

本文共 1317 字,大约阅读时间需要 4 分钟。

Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 33161    Accepted Submission(s): 12696
Problem Description
Given a positive integer N, you should output the most right digit of N^N.
 
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
 
Output
For each test case, you should output the rightmost digit of N^N.
 
Sample Input
2
3
4
 
Sample Output
7
6
Hint
In the first case, 3 * 3 * 3 = 27, so the rightmost digit is 7.
In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6.
 
Author

Ignatius.L

题目大意:给你一个N,计算N^N个位上的数字是多少

思路:普通方法超时,利用高速幂取余计算N^N%10,这里贴一个二进制

高速幂取余的代码

#include
#include
__int64 QuickPow(__int64 a,__int64 p){ __int64 r = 1,base = a; __int64 m = 10; while(p!=0) { if(p & 1) r = r * base % m; base = base * base % m; p >>= 1; } return r;}int main(){ __int64 N; int T; scanf("%d",&T); while(T--) { scanf("%I64d",&N); __int64 ans = QuickPow(N,N); printf("%I64d\n",ans); } return 0;}

转载于:https://www.cnblogs.com/cxchanpin/p/6951791.html

你可能感兴趣的文章
二维数组中最大连通子数组
查看>>
java 正则表达式-忽略大小写与多行匹配
查看>>
mac 上亚马逊密钥登录
查看>>
css选择器中:first-child与:first-of-type的区别
查看>>
nopcommerce 二次开发
查看>>
NHibernate入门实例
查看>>
IBM_DS5020磁盘阵列做raid、热备并把盘阵挂在服务器上的步骤
查看>>
svg制作风车旋转
查看>>
《软件工程》课堂作业:返回一个整数数组中最大字数组的和
查看>>
ACM 美素数 (没AC)
查看>>
Sqlserver学习研究
查看>>
VTK图形模型主要对象
查看>>
c# Linq实现 获得某一个路径下所有文件的名(不含扩展名)
查看>>
动静态广播的区别
查看>>
前缀式计算(前缀表达式)
查看>>
Linux常用命令大全
查看>>
添加删除tag
查看>>
ARM学习篇 中断定时理解
查看>>
卷积神经网络在tenserflow的实现
查看>>
[STL]用法
查看>>