Rightmost Digit
来源:互联网 发布:mac怎么装office软件 编辑:程序博客网 时间:2024/06/16 05:27
1001
Rightmost Digit
Time Limit: 2000/1000ms (Java/Other) Memory Limit : 65536/32768K(Java/Other)
Total Submission(s) : 129 AcceptedSubmission(s) : 55
Font:Times New Roman | Verdana | Georgia
Font Size:← →
Problem Description
Given apositive integer N, you should output the most right digit of N^N.
Input
The inputcontains several test cases. The first line of the input is a single integer Twhich 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).
Output
For each testcase, you should output the rightmost digit of N^N.
Sample Input
2
3
4
Sample Output
7
6
Hint
In the firstcase, 3 * 3 * 3 = 27, so the rightmost digit is 7.
In the second case, 4 * 4 * 4 * 4 = 256, so the rightmost digit is 6.
、
求一个数的n次方的最后一位数,将每个数的一到九次方写出来,都是四个一组循环。。
#include<iostream>
using namespace std;
int main()
{
int num,n,m,p,i;
cin>>num;
for(i=0;i<num;i++)
{
cin>>n;
p=n%10;//n的个位数
m=n%4;//规律,四位一循环
if(m==0)
cout<<(p*p*p*p)%10<<endl;
elseif(m==3)
cout<<(p*p*p)%10<<endl;
elseif(m==2)
cout<<(p*p)%10<<endl;
else
cout<<p<<endl;
}
return 0;
}
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- Rightmost Digit
- 文件共享
- L23数组指针分析
- 关于android事件分发的总结
- Android网络编程之http发送/请求服务
- 分手后极品留言
- Rightmost Digit
- Add Two Numbers
- 再说MySQL中的 table_id
- speex编解码在android上实现
- 5.2-3
- L24c语言中的字符串
- jquery的$.extend和$.fn.extend作用及区别
- CF#304Div2
- 2015`06`03实习面试收获