HDOJ 1061 Rightmost Digit
2014-05-17 18:56
323 查看
Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 30543 Accepted Submission(s): 11624
[align=left]Problem Description[/align]
Given a positive integer N, you should output the most right digit of N^N.
[align=left]Input[/align]
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).
[align=left]Output[/align]
For each test case, you should output the rightmost digit of N^N.
[align=left]Sample Input[/align]
2
3
4
[align=left]Sample Output[/align]
7 6
本题的大意是输入一个1到1000000000的整数N,要求输出N^N次方后的最后一个数字.....
解题思路:因为数据很大,只需要输出最后一位,所以对每个数据先求余得到最后一位数字,然后找出其最后一位的周期即可....
/************************************************** HDOJ 1061 已经AC ***************************************************/ #include <iostream> using namespace std; int main() { int N,T; int round=0; int r[100]={0}; int i=0; cin>>T; while(T--) { cin>>N; r[1]=N%10;//一定要对其求余 r[2]=(N%10)*(N%10)%10;//求余后再相乘,然后再求余,因为如果直接相乘时碰到1000000000时会发生错误 for(i=3;;i++) { r[i]=r[i-1]*(N%10)%10; if(r[i]==r[1]) {round=i-1;break;} } if(N%round==0) cout<<r[round]<<endl; else cout<<r[N%round]<<endl; } //while(1); return 0; }
相关文章推荐
- hdoj Rightmost Digit 1061 (数学转换&&找循环节)
- HDOJ 1061 Rightmost Digit
- hdoj-【1061 Rightmost Digit】
- HDOJ 1061 - Rightmost Digit
- HDOJ--1061--Rightmost Digit
- HDOJ 1061 Rightmost Digit
- HDOJ 1061 Rightmost Digit
- HDOJ 1061: Rightmost Digit
- HDOJ1061 Rightmost Digit
- Num 16: HDOJ: 题目1061 : Rightmost Digit [ 求个位数 ] [ 快速幂算法 ]
- HDOJ-1061-Rightmost Digit (求n^n的最低位)
- HDOJ 1061 RightmostDigit (求解 a^n的后 m 位,快速幂)
- HDOJ 1061 Rightmost Digit
- hdoj 1061 Rightmost Digit【快速幂求模】
- HDOJ&nbsp;&nbsp;1061&nbsp;&nbsp;Rightmost&nbsp;Digit
- HDOJ1061 Rightmost Digit
- 5.1 HDOJ 1061--Rightmost Digit
- HDOJ-1061 Rightmost Digit
- Rightmost&nbsp;Digit&nbsp;&nbsp;hdoj&nbsp;&nbsp;&nbsp;1061
- HDOJ HDU 1061 Rightmost Digit