hdu 1061 Rightmost Digit
解决本题使用数学中的快速幂取余:
该方法总结挺好的:具体参考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的更多相关文章
- HDU 1061 Rightmost Digit --- 快速幂取模
HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围, ...
- 题解报告:hdu 1061 Rightmost Digit(快速幂取模)
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
- 快速幂 HDU 1061 Rightmost Digit *
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- HDU 1061 Rightmost Digit解决问题的方法
求大量N^N的值最右边的数字,即最低位. 它将能够解决一个简单二分法. 只是要注意溢出,只要把N % 10之后.我不会溢出,代替使用的long long. #include <stdio.h&g ...
- HDU 1061 Rightmost Digit (快速幂取模)
题意:给定一个数,求n^n的个位数. 析:很简单么,不就是快速幂么,取余10,所以不用说了,如果不会快速幂,这个题肯定是周期的, 找一下就OK了. 代码如下: #include <iostrea ...
- HDU 1061 Rightmost Digit( 快速幂水 )
链接:传送门 题意:求 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 ...
- 杭电 1061 Rightmost Digit计算N^N次方的最后一位
Problem Description Given a positive integer N, you should output the most right digit of N^N. Input ...
随机推荐
- SmartGit as SVN Bridge
This page provides an introduction to SmartGit from an SVN users perspective and shows how the SVN w ...
- 配置和使用buffer cache
存放从磁盘读取的数据.排序和并行读不会使用buffer cache 可以从v$db_cache_advice或者buffer cache的命中率来检查buffer cache设置是否合理 查看v$db ...
- SQL 面向对象(委托)
委托:也称为代理,事件也是一种委托:定义在类的最外面 1.定义委托关键字:delegate函数签名:签名和函数保持一致定义委托的时候要根据函数来定义public delegate int First( ...
- SharedPreferences 轻型的数据存储方式
//初始化,(名字,隐私或公开) SharedPreferences openTimes=getSharedPreferences("openTimes",0); //提交保存数据 ...
- cocos2d-x游戏开发之动画
MyGame.h中声明动画函数: class MyGame : public cocos2d::Layer{public: static Scene* createScene(); void U ...
- Java泛型01--任意数组中两元素交换
package com.zl.generic; /** * 交换“任意”数组 中两个元素 */ public class GenericSwapArray { public static void m ...
- scala2.10.x case classes cannot have more than 22 parameters
问题 这个错误出现在case class参数超出22个的时候. case classes cannot have more than 22 parameters 在scala 2.11.x版本以下时c ...
- Bootstrap布局设计
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- SIFT算法详解(转)
http://blog.csdn.net/zddblog/article/details/7521424 目录(?)[-] 尺度不变特征变换匹配算法详解 Scale Invariant Feature ...
- Android 屏幕滑动事件
http://blog.csdn.net/iamfafa/article/details/6316062 Android里有两个类 android.view.GestureDetector andro ...