HDOJ 1061 Rightmost Digit
标签:des style blog class code c
Rightmost Digit
Time Limit: 2000/1000 MS
(Java/Others) Memory Limit: 65536/32768 K
(Java/Others)
Total Submission(s): 30543 Accepted
Submission(s): 11624
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
Output
For each test case, you should output the rightmost
digit of N^N.
Sample Input
Sample Output
7 6
本题的大意是输入一个1到1000000000的整数N,要求输出N^N次方后的最后一个数字.....
解题思路:因为数据很大,只需要输出最后一位,所以对每个数据先求余得到最后一位数字,然后找出其最后一位的周期即可....
1 /**************************************************
2 HDOJ 1061 已经AC
3 ***************************************************/
4 #include 5 using namespace std;
6 int main()
7 {
8 int N,T;
9 int round=0;
10 int r[100]={0};
11 int i=0;
12 cin>>T;
13 while(T--)
14 {
15 cin>>N;
16 r[1]=N%10;//一定要对其求余
17 r[2]=(N%10)*(N%10)%10;//求余后再相乘,然后再求余,因为如果直接相乘时碰到1000000000时会发生错误
18 for(i=3;;i++)
19 {
20 r[i]=r[i-1]*(N%10)%10;
21 if(r[i]==r[1])
22 {round=i-1;break;}
23 }
24 if(N%round==0)
25 coutendl;
26 else coutendl;
27 }
28 //while(1);
29 return 0;
30 }
HDOJ 1061 Rightmost Digit,搜素材,soscw.com
HDOJ 1061 Rightmost Digit
标签:des style blog class code c
原文地址:http://www.cnblogs.com/kb342/p/3734416.html
评论