ACM水题系列 HDOJ 1061
来源:互联网 发布:交通大数据应用 编辑:程序博客网 时间:2024/05/18 03:13
Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6526 Accepted Submission(s): 1688Problem 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.
题意,求N^N最右边的数。
思想:因为相同数相乘的个位数是有周期性规律的,周期不大于10,我们可以先求到N相乘的周期T,同时记录下不同的个位数存在数组r[]里,然后再用(N-1)%T得到该数的下标。
#include <iostream>#include <string.h>using namespace std;int main(){ int t; int r[10]; bool l[10]; cin>>t; while(t--){ memset(r,0,sizeof(r)); memset(l,0,sizeof(l)); int a,b,n=1; unsigned long m; cin>>m; a=m%10; b=a; r[0]=b; l[b]=true; b = (b*a)%10; while(!l[b]){ l[b] = true; r[n++]=b; b = (b*a)%10; } cout<<r[(m-1)%n]<<endl; } return 0;}
0 0
- ACM水题系列 HDOJ 1061
- ACM水题系列 HDOJ 1064
- ACM水题系列 HDOJ 1326
- ACM水题系列 HDOJ1038
- ACM水题系列 HDOJ2393
- ACM水题系列 HDOJ2629
- ACM水题系列 HDOJ2550
- ACM水题系列 HDOJ2673
- ACM水题系列 HDOJ2093
- HDOJ acm 1022 火车进站出站(栈系列)
- ACM--快速幂--HDOJ 1061--Rightmost Digit
- ACM--数学--HDOJ 1141--Factstone Benchmark--水
- ACM--百分比求值--HDOJ 1701--ACMer--水
- ACM--模拟--HDOJ 1008--Elevator--水
- ACM--HDOJ 2072--单词数--字符串--水
- ACM HDOJ 汉诺塔II
- ACM HDOJ 汉诺塔III
- ACM HDOJ 汉诺塔IV
- fashion clothing//
- Oracle中Integer类型/DBNull的处理方法
- 遍历目录并将目录下所有文件放到列表中-Python
- JVM-内存管理和内存回收
- ubuntu 12.04(64位)下搭建android5.0开发环境
- ACM水题系列 HDOJ 1061
- 检测Python程序执行效率及内存和CPU使用的7种方法
- Apache与tomcat简介
- 基础练习二
- Hope is a good thing, maybe the best of things and no good thing ever dies !
- Max Points on a Line
- 离散数学实验课中有趣的题目
- 学习shader之前必须知道的东西之计算机图形学(一)渲染管线
- ACM水题系列 HDOJ2393