Rightmost Digit (求n^n最后一位)
Description
Input
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Output
Sample Input
3
4
Sample Output
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.
n^n最后一位,等价于(n%100)^(n%100)的最后一位。
#include<cstdio>
int main()
{
__int64 t,l,b;
scanf("%I64d",&t);
while(t--)
{
__int64 n;
scanf("%I64d",&n);
l=n%;
b=l;
for(__int64 i=;i<l;i++)
{
b=b*l;
b%=;
}
b%=;
printf("%I64d\n",b);
}
}
快速幂
快速幂求n^n;
1 int f1(int a,int b)
2 {
3 int t=1;
4 while(b)
5 {
6 if(b % 2 != 0)
7 {
8 t*=a;
9 b--;
10 }
11 a*=a;
12 b/=2;
13 }
14 return t;
15 }
快速幂求n^n后y位;
1 int f2(int a,int b)
2 {
3 int t=1;
4 while(b)
5 {
6 if(b % 2 != 0)
7 {
8 t=(t*a)%x; //x控制要求的位数
9 b--;
10 }
11 a=(a*a)%x;
12 b/=2;
13 }
14 return t;
15 }
代码
#include<cstdio>
__int64 f(__int64 a)
{
__int64 b=a;
__int64 t=;
while(b)
{
if(b%!=)
{
t=(t*a)%;
b--;
}
a=a*a%;
b/=;
}
return t;
}
int main()
{
__int64 t,a;
scanf("%I64d",&t);
while(t--)
{
scanf("%I64d",&a);
printf("%I64d\n",f(a));
}
}
Rightmost Digit (求n^n最后一位)的更多相关文章
- 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. Input The ...
- <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 (Java/Others)T ...
- HDU1061 - Rightmost Digit
Given a positive integer N, you should output the most right digit of N^N. Input The input contains ...
- 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再求模肯定是不可取的, 因为会超出数据范围, ...
- Rightmost Digit(快速幂)
Description Given a positive integer N, you should output the most right digit of N^N. ...
随机推荐
- iOS APNs远程推送流程精简版
1.去Apple Developer Center里创建应用的信息,指定APP ID(Bundle ID),配置里开启推送功能(Push Notifications). 后续步骤需要用到这个应用的包名 ...
- Python圈中的符号计算库-Sympy(转载)
<本文来自公众号“大邓带你玩python”,转载> import math math.sqrt(8) 2.8284271247461903 我们看看Python中结果 math.sqrt( ...
- 逆序数 UVALive 6508 Permutation Graphs
题目传送门 /* 题意:给了两行的数字,相同的数字连线,问中间交点的个数 逆序数:第一行保存每个数字的位置,第二行保存该数字在第一行的位置,接下来就是对它求逆序数 用归并排序或线段树求.想到了就简单了 ...
- ORA-01144_表空间数据文件超出最大限制
Oracle11gR2扩展表空间报ORA-01144错误. 数据块大小为8K的数据库,单个数据文件大小限制在32GB内. 解决办法: 1.增加表空间数据文件的方式: 2.创建BIGFILE表空间:
- HTTP协议 之 缓存
转自: http://www.cnblogs.com/TankXiao/archive/2012/11/28/2793365.html HTTP协议提供了非常强大的缓存机制, 了解这些缓存机制,对提 ...
- 转【Python】Python-skier游戏[摘自.与孩子一起学编程]
http://www.cnblogs.com/zhaoxd07/p/4914818.html 我遇到的问题 问题1 self.image=pygame.image.load("skier_d ...
- solr 管理页面详解
solr 服务器管理界面可以查看系统状态.solr设置.分词检测.查询索引.增减core.查看日志等 1.Dashboard(仪表盘) 访问http://localhost:8080/solr时,出现 ...
- [转]ASP.NET MVC 3 Application Upgrader
本文转自:http://aspnet.codeplex.com/releases/view/59008 Recommended Download ASP.NET MVC 3 Applicat ...
- SharePoint2013升级SP1后,运行配置向导报错:未注册sharepoint服务
SharePoint Server 2013 升级SP1后,需要重新运行配置向导,但是运行过程中报错:未注册sharepoint服务. 日志详细错误信息: 已引发类型为 Microsoft.Share ...
- 外文翻译 《How we decide》 Introduction
书籍PDF版地址:How we decide 本文为书籍导言部分的拙劣翻译. 当我驾驶着波音737驶向东京成田国际机场时,飞机的引擎突然起火了.此时我们正处于7000英尺的高空,机场的跑道就在不远的前 ...