HDOJ 1061 Rightmost Digit(循环问题)】的更多相关文章

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…
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…
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中…
题意:给定一个数,求n^n的个位数. 析:很简单么,不就是快速幂么,取余10,所以不用说了,如果不会快速幂,这个题肯定是周期的, 找一下就OK了. 代码如下: #include <iostream> #include <cstdio> #include <algorithm> #include <queue> #include <vector> #include <cstring> #include <map> using…
链接:传送门 题意:求 N^N 的个位 思路:快速幂水题 /************************************************************************* > File Name: hdu1061.cpp > Author: WArobot > Blog: http://www.cnblogs.com/WArobot/ > Created Time: 2017年05月17日 星期三 22时50分05秒 **************…
C - Rightmost Digit Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit Status Practice HDU 1061 Description Given a positive integer N, you should output the most right digit of N^N. Input The input contains several test case…
1060 - Leftmost Digit 1601 - Rightmost Digit 1060题意很简单,求n的n次方的值的最高位数,我们首先设一个数为a,则可以建立一个等式为n^n = a * 10^x;其中x也是未知的: 两边取log10有:lg(n^n) = lg(a * 10^x); 即:n * lg(n)  - x = lg(a); 现在就剩x一个变量了,我们知道x是值n^n的位数-1,a向下取整就是我们要求的数: 所以 按着上面的推导式翻译成代码就可以了(注意:数值的范围和之间的…
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…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 35848    Accepted Submission(s): 13581 Problem Description Given a positive integer N, you should output the most right digit of N^N.   Input The…
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 foll…
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 55522    Accepted Submission(s): 20987 Problem Description Given a positive integer N, you should output the most right digit of N…
                                                 Rightmost Digit Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u   Description Given a positive integer N, you should output the most right digit of N^N.   Input The input c…
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…
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…
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.Eac…
找规律! 求N!最后非0位的值.比方2是120的最后一个不是0的值. 输入N比較大,要大数保存. 注意到最后0的个数是与5的因数的个数相等.设f(n)为n!的最后非0位. 那么f(n)=((n%5)!* f(n/5) *2^(n/5))%10 因数2的个数始终大于5,从1開始每连续5个划分为1组,当中5的倍数仅仅提取出一个因数5后, 组成一个新的数列1到n/5,我们有1*2*3*4*5=6*7*8*9*5=2(取最后一个非0位),这里就是2^(n/5). 再乘上剩下来的几个数字就可以 (比方n是…
题意:求n的n次方的个位数(1<=N<=1,000,000,000) 第一个最愚蠢的办法就是暴力破解,没什么意义,当然,还是实现来玩玩. 以下是JAVA暴力破解: import java.io.BufferedInputStream; import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = n…
找循环 #include <iostream> #include <cmath> using namespace std; int t,m,p,q; long long n; ],ans; int main() { scanf("%d",&t); while(t--) { scanf("%lld",&n); m=n%; ,i; c[++cnt]=m; p=(m*m)%; while(p!=m) { c[++cnt]=p; p=…
题目描述: 源码: /**/ #include"iostream" using namespace std; int main() { int t, mod; long long n; cin>>t; for(int i = 0; i < t; i++) { cin>>n; mod = n % 10; if(mod == 0 || mod == 1 || mod == 5 || mod == 6) { cout<<mod<<endl…
HDU 1000 A + B Problem  I/O HDU 1001 Sum Problem  数学 HDU 1002 A + B Problem II  高精度加法 HDU 1003 Maxsum  贪心 HDU 1004 Let the Balloon Rise  字典树,map HDU 1005 Number Sequence  求数列循环节 HDU 1007 Quoit Design  最近点对 HDU 1008 Elevator  模拟 HDU 1010 Tempter of th…
HDOJ 题目分类 //分类不是绝对的 //"*" 表示好题,需要多次回味 //"?"表示结论是正确的,但还停留在模块阶 段,需要理解,证明. //简单题看到就可以敲的 1000:    入门用: 1001:    用高斯求和公式要防溢出 1004:1012: 1013:    对9取余好了 1017:1021: 1027:    用STL中的next_permutation() 1029:1032:1037:1039:1040:1056:1064:1065: 10…
HDOJ 题目分类 /* * 一:简单题 */ 1000:    入门用:1001:    用高斯求和公式要防溢出1004:1012:1013:    对9取余好了1017:1021:1027:    用STL中的next_permutation()1029:1032:1037:1039:1040:1056:1064:1065:1076:    闰年 1084:1085:1089,1090,1091,1092,1093,1094, 1095, 1096:全是A+B1108:1157:1196:1…
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 43847    Accepted Submission(s): 16487 Problem Description Given a positive integer N, you should output the most right digit of…