Rightmost Digit(找规律)
来源:互联网 发布:幼儿教育软件哪个好 编辑:程序博客网 时间:2024/06/06 14:03
Rightmost Digit
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 47773 Accepted Submission(s): 18090
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.
#include<cstdio> int wei(__int64 p) { return p%10; } int wei2(__int64 q) { return q%100; } int main() { int t; scanf("%d",&t); while(t--) { __int64 n; scanf("%I64d",&n); int m=wei(n); int k=wei2(n); int yu=k%4;//一个数的后两位是4的倍数这个数就是4的倍数 int sum=1; if(m==0||m==1||m==5||m==6|m==9) { printf("%d\n",m); } else { if(m==4) { printf("6\n"); } else { if(yu==0) { printf("%d\n",m*m*m*m%10); } else { for(int i=1;i<=yu;i++) { sum=sum*m; } printf("%d\n",sum%10); } } } } return 0; }
0 0
- Rightmost Digit(找规律)
- Rightmost Digit(找规律)
- HDU——1061Rightmost Digit(高次方,找规律)
- 【杭电1061】Rightmost Digit 求n^n,找规律!!
- HDOJ 题目1061Rightmost Digit(规律)
- HDU:1061 Rightmost Digit(规律)
- ACM课-Rightmost Digit-规律
- HDU-#1061 Rightmost Digit(规律、分治、快速幂取模)
- HDU - 1061 Rightmost Digit (数学打表)规律
- HDU 1061 Rightmost Digit 【快速幂 Or 规律(瞎搞)】
- hdoj Rightmost Digit 1061 (数学转换&&找循环节)
- 5710 Digit-Sum(找规律)
- DIgit 找规律
- Rightmost Digit(HDU1061)
- Rightmost Digit(hdu1061)
- hdu1061-Rightmost Digit(附20循环的规律解法和附快速幂简单原理)
- HDU1597 - find the nth digit (找规律)
- POJ 1597 find the nth digit (找规律)
- Docker的安装与部署
- [模版]Java 文件读入(字符流) GZip压缩、解压缩String
- 自定义View
- N皇后问题(经典DFS)
- 操作系统——中断机制(trap, interrupts)
- Rightmost Digit(找规律)
- 深入理解拉格朗日乘子法(Lagrange Multiplier) 和KKT条件
- linphone-PresenceNote.java文件分析
- raspbian 默认从控制台启动
- Yarn设计思想
- 如何让HorizonScrollView中的子控件居中
- css盒子模型的简单应用
- 自定义Adapter填充listview
- mysql的函数