解决本题使用数学中的快速幂取余:

该方法总结挺好的:具体参考http://www.cnblogs.com/PegasusWang/archive/2013/03/13/2958150.html

#include<iostream>
#include<cmath>
using namespace std;
int PowerMod(__int64 a,__int64 b,int c)//快速幂取余
{
int ans=;
a=a%c;
while(b>)
{
if(b%==)//如果为奇数时,要多求一步,可以提前放到ans中
ans=(ans*a)%c;
b=b/;//不断迭代
a=(a*a)%c;//把(a^2)%c看成一个整体
}
return ans;
}
int main()
{
int n;
cin>>n;
__int64 m;
while(n--)
{
cin>>m;
cout<<PowerMod(m,m,)<<endl;
}
return ;
}

还有其他的方法比如数学规律等 但个人觉得这种方法稍难:

#include<stdio.h>
int main()
{
__int64 n;
int a[][]={{},{},{,,,},{,,,},{,},{},{},{,,,},{,,,},{,}},d,t;//找规律
scanf("%d",&t);
while(t--)
{
scanf("%I64d",&n);
d=n%;
if(d==||d==||d==||d==)
printf("%d\n",d);
else if(d==||d==)
printf("%d\n",a[d][n%]);
else
printf("%d\n",a[d][n%]);
}
return ;
}

hdu 1061 Rightmost Digit的更多相关文章

  1. HDU 1061 Rightmost Digit --- 快速幂取模

    HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...

  2. 题解报告:hdu 1061 Rightmost Digit(快速幂取模)

    Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...

  3. 快速幂 HDU 1061 Rightmost Digit *

    Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  4. HDU 1061 Rightmost Digit解决问题的方法

    求大量N^N的值最右边的数字,即最低位. 它将能够解决一个简单二分法. 只是要注意溢出,只要把N % 10之后.我不会溢出,代替使用的long long. #include <stdio.h&g ...

  5. HDU 1061 Rightmost Digit (快速幂取模)

    题意:给定一个数,求n^n的个位数. 析:很简单么,不就是快速幂么,取余10,所以不用说了,如果不会快速幂,这个题肯定是周期的, 找一下就OK了. 代码如下: #include <iostrea ...

  6. HDU 1061 Rightmost Digit( 快速幂水 )

    链接:传送门 题意:求 N^N 的个位 思路:快速幂水题 /********************************************************************** ...

  7. hdoj 1061 Rightmost Digit【快速幂求模】

    Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  8. HDOJ 1061 Rightmost Digit(循环问题)

    Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...

  9. 杭电 1061 Rightmost Digit计算N^N次方的最后一位

    Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...

随机推荐

  1. 什么是cookie

    cookie是在用户浏览网页时,从服务器发出,保存到浏览器的一小块数据.

  2. Greenplum:学习资料

    Greenplum技术浅析:http://www.cnblogs.com/end/archive/2012/08/17/2644290.html Greenplum 数据库架构分析:http://ww ...

  3. SQL百分比

    百分比=cast(cast(count(ProvinceName)*100./ (select count(Id) from  dbo.TopicCurrent   where boardId=316 ...

  4. 初始化 Gradle 工程目录(转自: 隔叶黄莺 Unmi Blog)

    最近重新在 Eclipse 中打开旧的 Maven 项目,总有些什么错误,备受折磨.期间试手了 Ant+Ivy, 现今试用了下 Gradle,感觉不错,它应该才是我真想要的,Maven 差不多该扔到一 ...

  5. SQL 过滤 having

    select * from emp --having 对分组之后使用 --输出部门号 和 部门的平均工资 并且 平均工资 > 2000 select deptno, avg(sal) as &q ...

  6. windows 计算机 管理 命令

    compmgmt.msc

  7. [摘录] 关于 java 并发包

    1.http://www.raychase.net/698 Java多线程发展简史

  8. 通过JavaScript设置样式和jQuey设置样式,还有随机数抛出水果的习题

    一:通过JavaScript的方式设置样式(:拿习题为例): var shuiguo = document.getElementById('fruit');     shuiguo.style.bac ...

  9. hdu4609 3-idiots

    FFT 代码 #include<iostream> #include<cstring> #include<cstdio> #include<cmath> ...

  10. 反射认识_03_改变成员变量Fields

    包01:package ReflectionChange; public class ReflectionPoint_AB { String str1="access"; Stri ...