HDU1061 - Rightmost Digit
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
思路:这题是真正的水题,直接套用模板QAQ
#include<bits/stdc++.h>
using namespace std;
long long PowerMod(long long a, long long b, long long c)
{
long long ans = 1;
a = a % c; //对刚进来的a进行取模运算,避免后面第一次求平方运算溢出
while(b)
{
if(b&1) //相当于b % 2 = = 1对二进制下的 b 进行按位与1运算,求二进制下 b 的最低位是否为1
ans = ans * a % c; //对结果进行保存
b>>=1; //相当于b = b/2;二进制下的 b 右移一位,相当于十进制下的 b 除以2
a = a * a % c;
}
return ans;
}
int main()
{
long long t,n,m;
cin>>t;
while(t--)
{
cin>>n;
m=PowerMod(n,n,10);
cout<<m<<endl;
}
return 0;
}
HDU1061 - Rightmost Digit的更多相关文章
- Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- HDU 1061 Rightmost Digit --- 快速幂取模
HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...
- hdoj 1061 Rightmost Digit【快速幂求模】
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDOJ 1061 Rightmost Digit(循环问题)
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- Rightmost Digit(快速幂+数学知识OR位运算) 分类: 数学 2015-07-03 14:56 4人阅读 评论(0) 收藏
C - Rightmost Digit Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- Rightmost Digit(快速幂)
Description Given a positive integer N, you should output the most right digit of N^N. ...
- <hdu - 1600 - 1601> Leftmost Digit && Rightmost Digit 数学方法求取大位数单位数字
1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * ...
- 杭电 1061 Rightmost Digit计算N^N次方的最后一位
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- HDOJ 1061 Rightmost Digit
找出数学规律 原题: Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Ja ...
随机推荐
- iview datepicker 选择的时间少一天
使用iview的datepicker时间选择器发现获取的value值是比实际要少一天,严格来说应该是时间格式不一样,datepicker获取的时间是UTC时间格式,也就是:yyyy-MM-ddTHH: ...
- nyoj56-阶乘因式分解(一)
56-阶乘因式分解(一) 内存限制:64MB时间限制:3000msSpecial Judge: No accepted:6submit:7 题目描述: 给定两个数m,n,其中m是一个素数. 将n(0& ...
- 4.2、Ansible常用模块
1.command:命令模块,默认模块,用于在远程执行命令,不支持变量.ansible 192.168.139.128 -a 'date' 2.cron:计划任务模块:ansible 192.168. ...
- ZooKeeper概念
这可能是把ZooKeeper概念讲的最清楚的一篇文章 相信大家对 ZooKeeper 应该不算陌生,但是你真的了解 ZooKeeper 是什么吗?如果别人/面试官让你讲讲 ZooKeeper 是什么, ...
- MYSQL存储过程初步认知
存储过程(Stored Procedure): 一组可编程的函数,是为了完成特定功能的SQL语句集,经编译创建并保存在数据库中,用户可通过指定存储过程的名字并给定参数(需要时)来调用执行. 优点:将重 ...
- Tensorflow读取文件到队列文件
TensorFlow读取二进制文件数据到队列 2016-11-03 09:30:00 0个评论 来源:diligent_321的博客 收藏 我要投稿 TensorFlow是一种 ...
- Oracle里schema理解
在Oracle中,一个用户就是一个Schema,表都是建立在Schema中的,也可以理解为每个用户拥有不同的表.一个用户想访问另外一个用户,也就是另外一个schema的表的时候,可以用 usernam ...
- ISAM Indexed Sequential Access Method 索引顺序存取方法
ISAM Indexed Sequential Access Method 索引顺序存取方法 学习了:https://baike.baidu.com/item/ISAM/3013855 是IBM发展起 ...
- Unity特殊目录和脚本编译顺序
特殊目录和脚本编译顺序 大多数情况下,您能够选择不论什么你喜欢的目录在您的项目的名称.但unity储备一些名称以指示内容有一个特殊的用途.这些目录中有些会影响脚本编译的顺序.从根本上说,有四个单 ...
- 通过setSystemUiVisibility实现状态栏跟Activity之间的位置关系
曾经说到去除状态栏和标题栏总会用到动态代码的方式实现: getWindow().setFlags(WindowManager.LayoutParams. FLAG_FULLSCREEN , Windo ...