HDU 1061-Rightmost Digit(快速幂)
来源:互联网 发布:nginx log 时间格式 编辑:程序博客网 时间:2024/04/30 18:41
Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 32258 Accepted Submission(s): 12403
Problem Description
Given a positive integer N, you should output the most right digit of N^N.
Input
The input contains several test cases. The first line of the input is a single integer T which is the number of test cases. T test cases follow.
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Each test case contains a single positive integer N(1<=N<=1,000,000,000).
Output
For each test case, you should output the rightmost digit of N^N.
Sample Input
234O(logn)的复杂度就是快QAQ题意 :求n^n%10 n<1000000000#include <iostream>#include <cstring>#include <cstdio>#include <cctype>#include <cstdlib>#include <algorithm>#include <set>#include <vector>#include <string>#include <map>#include <queue>using namespace std;#define LL long longLL multimod(LL a,LL n,LL m){ LL ans=1,tem=a; while(n) { if(n&1) ans=ans*tem%m; tem=tem*tem%m; n/=2; } return ans;}int main(){ LL a,b;int T; cin>>T; while(T--) { cin>>a; cout<<multimod(a,a,10)<<endl; } return 0;}
1 4
- HDU 1061 Rightmost Digit 【快速求幂】
- HDU 1061-Rightmost Digit(快速幂)
- hdu 1061 Rightmost Digit 快速幂
- hdu 1061 Rightmost Digit(快速幂)
- HDU 1061 Rightmost Digit(快速幂)
- HDU 1061 Rightmost Digit(快速幂)
- HDU 1061 Rightmost Digit (快速幂)
- 【HDU】1061 - Rightmost Digit(快速幂)
- Rightmost Digit 【hdu-1061】【快速幂】
- 【hdu 1061】Rightmost Digit(快速幂)
- HDU-1061-Rightmost Digit【快速幂】
- HDU Rightmost Digit (快速幂)
- hdu 1061 Rightmost Digit(快速幂入门)
- HDU 1061 Rightmost Digit (四则运算求余,快速幂)
- hdu oj 1061 Rightmost Digit (快速幂算法)
- 快速幂模m HDU——1061 Rightmost Digit
- HDU 1061 Rightmost Digit(简单快速幂)
- HDU 1061 Rightmost Digit(快速幂入门)
- 结合mahout的数据挖掘算法介绍
- vim查看二进制文件
- Chrome浏览器开发调试系列(一)
- 使用draggable插件实现对象的拖曳操作8-1
- Spring声明式事务管理与配置介绍
- HDU 1061-Rightmost Digit(快速幂)
- Cvbox2D(RotatedRect)的解析与应用
- Java坦克大战 (五) 之产生敌方坦克和爆炸效果
- SAP 名词解释
- 原生CSS动画回调事件
- Spring声明式事务配置管理方法
- 20140903 调试日记 主 板 ip 47变为50
- WoSign 新根证书与新证书颁发系统有什么特别优势?
- 在Java中算出1加到10的结果