51Nod Problem 1004 n^n的末位数字(规律)
来源:互联网 发布:破解下载软件 编辑:程序博客网 时间:2024/05/22 11:38
此文章可以使用目录功能哟↑(点击上方[+])
51Nod Problem 1004 n^n的末位数字
Accept: 0 Submit: 0
Time Limit: 1 second Memory Limit : 131072 KB
Problem Description
给出一个整数N,输出N^N(N的N次方)的十进制表示的末位数字。
Input
一个数N(1 <= N <= 10^9)
Output
输出N^N的末位数字
Sample Input
13
Sample Output
3
Hint
Problem Idea
解题思路:
【题意】
求N^N(N的N次方)的十进制表示的末位数字
【类型】
规律
【分析】
此题正解方法是快速幂
但是我们完全可以通过找规律来求解
因为只需要N^N的末位数字,所以我们完全可以不用考虑其他位数字是多少,而最后一位只有0~9十种情况,这样就方便了我们去找规律
规律如下:
由上表可见,不管以哪个数字作为末位,至多4次就会出现循环,所以我们只需用数组存下每个数字作为末位时的循环部分,那么结果用O(1)的时间就可以查到答案
【时间复杂度&&优化】
O(1)
题目链接→51Nod Problem 1004 n^n的末位数字
Source Code
/*Sherlock and Watson and Adler*/#pragma comment(linker, "/STACK:1024000000,1024000000")#include<stdio.h>#include<string.h>#include<stdlib.h>#include<queue>#include<stack>#include<math.h>#include<vector>#include<map>#include<set>#include<bitset>#include<cmath>#include<complex>#include<string>#include<algorithm>#include<iostream>#define eps 1e-9#define LL long long#define PI acos(-1.0)#define bitnum(a) __builtin_popcount(a)using namespace std;const int N = 10;const int M = 4;const int inf = 1000000007;const int mod = 7;int s[N][M]={{0,0,0,0},{1,1,1,1},{2,4,8,6},{3,9,7,1},{4,6,4,6},{5,5,5,5},{6,6,6,6},{7,9,3,1},{8,4,2,6},{9,1,9,1}};int main(){ int n; scanf("%d",&n); printf("%d\n",s[n%10][(n-1)%4]); return 0;}菜鸟成长记
1 0
- 51Nod Problem 1004 n^n的末位数字(规律)
- 51nod 1004 n^n的末位数字
- 51nod-【1004 n^n的末位数字】
- 51nod 1004 n^n的末位数字
- 51nod 1004 n^n的末位数字
- 51NOD 1004 n^n的末位数字
- [51NOD] 1004 n^n的末位数字 [数学]
- 51nod 1004 n^n的末位数字
- 51Nod 1004 n^n的末位数字
- 【51Nod】1004 n^n的末位数字
- 51Nod--1004 n^n的末位数字
- 51nod 1004 n^n的末位数字
- 51nod 1004 n^n的末位数字
- 51Nod 1004 n^n的末位数字()
- 51nod 1004:n^n的末位数字
- 51NOD 1004 n^n的末位数字
- HDU 1061 (51Nod 1004 )n^n的末位数字
- 51Nod-1004-n^n的末位数字
- caffe训练网络时loss突然增大并维持在86.3333333的问题解决
- php 正则表达式贪婪模式,非贪婪模式
- JAVASE总结--编码格式
- 一个无脑的FLOYD代码。。。。
- UVA12661
- 51Nod Problem 1004 n^n的末位数字(规律)
- cmd窗口内容如何上下移动查看
- Qt5.5中类反射试验
- 面向对象的lua
- c# winForm 将窗体状态栏StatusStrip 分成左中右三部分
- Objective-C的陷阱与缺陷
- 1、调试会话的可执行文件
- Java学习(3)-可变参数
- UIBezierPath介绍