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

该方法总结挺好的:具体参考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. GTA项目 三, 使用 bootstrap table展示界面,使得data和UI分离

    /** bootstrap-table - v1.5.0 - 2014-12-12* https://github.com/wenzhixin/bootstrap-table* Copyright ( ...

  2. Leetcode: Strobogrammatic Number III

    A strobogrammatic number is a number that looks the same when rotated 180 degrees (looked at upside ...

  3. 成员变量&&局部变量

    一.相同点:1.都遵循变量的声明格式:(修饰符) 数据类型  变量名=初始化值 2.都有各自的作用域 二.不同点:1.声明的位置不同      成员变量:声明在类内,方法外. 局部变量:声明在方法内. ...

  4. curl命令使用(转)

    转自:http://www.cnblogs.com/sunada2005/p/3829772.html curl命令可以用来构造http请求.参数有很多,常用的参数如下: 通用语法:curl [opt ...

  5. javascript浏览器对象

    window对象 1.window对象 window对象是BOM的核心,window对象指当前的浏览器窗口 所有JS全局对象.函数以及变量均自动成为window对象的成员 全局变量是window对象的 ...

  6. start.s 解析(一)

    可以参考 : http://blog.csdn.net/bluesummerg/article/details/5940452 (强大的反汇编) http://www.cnblogs.com/yanh ...

  7. paper 52 :windows7环境下theano安装

    要做卷积神经网络的一些东西,所以要装theano,网上很多Theano安装教程版本较老,而各安装包更新很快,参考价值有限.走了很多弯路才装好,把这个过程记录下来,希望对大家有帮助~ ~ 我的配置:wi ...

  8. Concurrent Assertion

    Concurrent assertion中要求必须有clock,从而保证在每个clock edge都进行触发判断. assertion与design进行同步执行,concurrent assert只能 ...

  9. Bishop的大作《模式识别与机器学习》Ready to read!

    久仰Bishop的大作“Pattern Recognition and Machine Learning”已久,在我的硬盘里已经驻扎一年有余,怎奈惧其页数浩瀚,始终未敢入手.近日看文献,屡屡引用之.不 ...

  10. yii2验证码的使用

    1.控制器中 public function actions()     {         return [             'captcha' => [               ...