HDOJ-1061-Rightmost Digit (求n^n的最低位)
来源:互联网 发布:在线图片合成软件 编辑:程序博客网 时间:2024/05/29 10:54
/*
Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6515 Accepted Submission(s): 2454
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
234
Sample Output
76HintIn the first case, 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.
*/
比求最高位简单多了,任何两个数相乘的最低位一定是它们最低位相乘所得结果的最低位
如9999 可转化为求99个9相乘后最低位是什么,而同一个数连乘结果是具有周期性的,周期不大于10
#include <iostream>
#include <stdio.h>
using namespace std;
bool l[10];
int r[10];
int main()
{
int t;
while(cin>>t)
{
while(t--)
{
memset(l,0,sizeof(l));
memset(r,0,sizeof(r));
unsigned long n;
cin>>n;
int a=n%10;
int b=a;
int i=1;
l[b]=true;r[0]=b;
b=(b*a)%10;
while(!l[b])
{
l[b]=true;
r[i++]=b;
b=(b*a)%10;
}
cout<<r[(n-1)%i]<<endl;
}
}
return 0;
}
- HDOJ-1061-Rightmost Digit (求n^n的最低位)
- HDU 1061 Rightmost Digit (求n^n的最低位)
- Rightmost Digit(杭电1061)(求N^N的最低位)
- hdu 1061 - Rightmost Digit(求N^N末位)
- Rightmost Digit(求N^N的个位)
- 【杭电1061】Rightmost Digit 求n^n,找规律!!
- hdu1061 Rightmost Digit N的N次方
- HDOJ-1060-Leftmost Digit(求n^n的最高位)
- HDOJ-1060-Leftmost Digit(求n^n的最高位)
- HDOJ-1060-Leftmost Digit(求n^n的最高位)
- HDOJ 1060 Leftmost Digit(数学,求n^n的最高位)
- HDOJ 1001:Rightmost Digit(n^n最后一位)
- HDOJ1060 Leftmost Digit(求n^n的最高位)
- 杭电1061 Rightmost Digit(快速幂取余取最低位)
- 求n的阶层二进制最低位1的位置
- HDOJ 1061: Rightmost Digit
- hdoj 1061Rightmost Digit
- HDOJ 1061 Rightmost Digit
- 网页生命周期
- 11.3线程----锁Lock
- Java 之父:再见,老朋友 Sun....
- 远程桌面看到的界面和实际的界面不一样
- 很生气!
- HDOJ-1061-Rightmost Digit (求n^n的最低位)
- 悼念一个伟大的公司——Sun
- Java Application 直接通过jndi连接数据库
- Project Euler - Problem 11
- linux环境变量
- mysql存储过程中参数的in,out,inout区别
- 如何定制bash提示符
- 开始积累小型asp.net项目经验
- MultiByteToWideChar和WideCharToMultiByte用法详解