HDU1061-Rightmost Digit(高速功率模)
题意:求n^n的个位数的值。
思路:高速幂求值
代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm> using namespace std; typedef __int64 ll;
//typedef long long ll; const int MOD = 1000000000; ll n; ll pow_mod(ll k) {
if (k == 1)
return n % MOD;
ll a = pow_mod(k / 2);
ll ans = a * a % MOD;
if (k % 2 == 1)
ans = ans * n % MOD;
return ans;
} int main() {
int cas;
scanf("%d", &cas);
while (cas--) {
scanf("%I64d", &n);
ll ans = pow_mod(n);
while (ans > 10) {
ans %= 10;
}
printf("%I64d\n", ans);
}
return 0;
}
版权声明:本文博客原创文章,博客,未经同意,不得转载。
HDU1061-Rightmost Digit(高速功率模)的更多相关文章
- HDU1061 - Rightmost Digit
Given a positive integer N, you should output the most right digit of N^N. Input The input contains ...
- 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 ...
- hdoj 1061 Rightmost Digit【快速幂求模】
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...
- Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission( ...
- 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 * ...
随机推荐
- core graphics path
当UIKit无法满足画图需求的时候.就须要用到Core Graphics API.当中最普遍的就是path. 一些重要的概念 graphics context 能够理解成canvas.在ios里相应C ...
- 谈谈Linux内存释放
上上周吧,一个朋友问我说他公司的服务器内存free 为0 是为什么,意思大概是内存去哪了,这引发了一个小小的讨论,也就是内存释放的问题… 首先我们可能会用free 去查看内存的使用率,它应该是这样的 ...
- 这么多的技术,作为一个freshman,什么研究?
科学技术,从哪里学习? 杨问了我几个最近:"如何学习技术?".说实话,其实,我自己只是一个资深兄弟.对于这个答案.这是更难以在本身回答. 可是.既然比师弟们多吃了几年 ...
- Axuer 网页
http://www.webppd.com/axure/
- myEclipse勿删文件怎么恢复
今天码代码的时候项目里有一个jsp文件不小心被删了,又懒得重写,然后发现myEclipse竟然可以恢复被勿删的文件,当然,也仅仅限于最近被删的文件. 具体怎么恢复呢?-------右键点击被删文件所在 ...
- Android SDK 和 Eclipse ADT 离线安装 教程
因为google 被限制,就是FQ后,下载的速度依旧非常慢,让人非常崩溃啊,所以这里就分享一下离线安装android SDK 和eclipse ADT 离线安装方法. 安装之前首先已经确保java s ...
- 最简单的视频编码器:基于libx265(编码YUV为H.265)
===================================================== 最简单的视频编码器系列文章列表: 最简单的视频编码器:编译 最简单的视频编码器:基于libx ...
- Windows Azure应用系列:微软的云部署VPN
本文介绍如何使用OpenVPN微软云计算server既定VPN维修. 过程,如下面: 1.新建Linux或者Ubuntu虚拟机.并设置port.(本文将建立Ubuntu作为演示) 2.利用PuTTY登 ...
- 【C语言】推断一个数的奇偶(位操作)
//推断一个数的奇偶 #include <stdio.h> int is_signal(int num) { if (num & 1) return 1; else return ...
- 《数据结构、算法及应用》9.(C++实施订单)
最近阅读<数据结构.算法及应用>这本书,书中的习题汇总,用自己的方法来实现这些问题.可能效率.等方面存在着非常多的问题,也可能是错误的实现.假设大家在看这本书的时候有更优更好的方法来实现, ...