HDOJ 1061 Rightmost Digit】的更多相关文章

Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 39554    Accepted Submission(s): 14930 Problem Description Given a positive integer N, you should output the most right digit of N…
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…
找出数学规律 原题: 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 d…
HDU 1061 题目大意:给定数字n(1<=n<=1,000,000,000),求n^n%10的结果 解题思路:首先n可以很大,直接累积n^n再求模肯定是不可取的, 因为会超出数据范围,即使是long long也无法存储. 因此需要利用 (a*b)%c = (a%c)*(b%c)%c,一直乘下去,即 (a^n)%c = ((a%c)^n)%c; 即每次都对结果取模一次 此外,此题直接使用朴素的O(n)算法会超时,因此需要优化时间复杂度: 一是利用分治法的思想,先算出t = a^(n/2),若…
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…
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…
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 57430    Accepted Submission(s): 21736 Problem Description Given a positive integer N, you should output the most right digit of N…
这道题目可以手工打表,也可以机器打表,千万不能暴力解,会TLE. #include <stdio.h> #define MAXNUM 1000000001 ][]; int main() { int case_n, n; int i, j; ; i<; ++i) { buf[i][] = ; buf[i][] = i; ; j<; ++j) { buf[i][j] = buf[i][j-]*i%; ]) break; buf[i][]++; } } /* for (i=0; i&l…
求大量N^N的值最右边的数字,即最低位. 它将能够解决一个简单二分法. 只是要注意溢出,只要把N % 10之后.我不会溢出,代替使用的long long. #include <stdio.h> int rightMost(int n, int N) { if (n == 0) return 1; int t = rightMost(n / 2, N); t = t * t % 10;; if (n % 2) t *= N; return t % 10; } int main() { int T…
解决本题使用数学中的快速幂取余: 该方法总结挺好的:具体参考http://www.cnblogs.com/PegasusWang/archive/2013/03/13/2958150.html #include<iostream> #include<cmath> using namespace std; int PowerMod(__int64 a,__int64 b,int c)//快速幂取余 { ; a=a%c; ) { ==)//如果为奇数时,要多求一步,可以提前放到ans中…