Rightmost Digit】的更多相关文章

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…
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),若…
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…
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…
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…
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向下取整就是我们要求的数: 所以 按着上面的推导式翻译成代码就可以了(注意:数值的范围和之间的…
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…
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…
                                                 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…
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…
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…
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…
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^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中…
这道题目可以手工打表,也可以机器打表,千万不能暴力解,会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次方的个位数(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=…
题意:给定一个数,求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秒 **************…
题目描述: 源码: /**/ #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…
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 69614    Accepted Submission(s): 25945 Problem Description Given a positive integer N, you should output the most right digit of N…
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: 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…
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) http://acm.hdu.edu.cn/showproblem.php?pid=1061 Problem Description Given a positive integer N, you should output the most right digit of N^N.   Input…
Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 33161    Accepted Submission(s): 12696 Problem Description Given a positive integer N, you should output the most right digit of…
这个分类怎么觉得这么水呢.. 这个分类做到尾的模板集: //gcd int gcd(int a,int b){return b? gcd(b, a % b) : a;} //埃氏筛法 O(nlogn) int prime[MAX_N]; bool is_prime[MAX_N];//i是不是素数 int sieve() { ; ; i <= n; i++) is_prime[i] = true; is_prime[] = is_prime[] = false; ; i <= n; i++) {…