51Nod 1004 n^n末尾数字 | 快速幂】的更多相关文章

#include "bits/stdc++.h" using namespace std; #define LL long long #define INF 0x3f3f3f3f3f #define PI acos(-1) #define N 510 #define MOD 10 LL quickPow(LL a,LL b) { LL ans=; ){ ){ ans=ans*a%MOD; } b>>=; a=a*a%MOD; } return ans; } int main…
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1835 基准时间限制:1 秒 空间限制:131072 KB   初始有n个点,任意两个点之间有一条无向边,现在要移除一些无向边(至少一条),问移除后有恰好m个连通块的方案数是多少. 两个方案不同当且仅当存在至少一条无向边在某个方案中被移除,但是在另一个方案中没被移除. 答案可能很大请模一个998,244,353.   Input 第一行读入n,m. 1<=m<…
1004 n^n的末位数字 题目来源: Author Ignatius.L (Hdu 1061) 基准时间限制:1 秒 空间限制:131072 KB 分值: 5 难度:1级算法题 给出一个整数N,输出N^N(N的N次方)的十进制表示的末位数字. Input 一个数N(1 <= N <= 10^9) Output 输出N^N的末位数字 Input示例 13 Output示例 3 题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!pr…
思路: 掐住最后一位,快速幂一发就好了 #include<cstdio> #include <map> #include<iostream> #include<string.h> #include<algorithm> using namespace std; typedef __int64 LL; int cal(int g,int x) { int ans=1; while(g) { if(g%2) ans=(ans*x)%10; x=(x*…
题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; typedef long long ll; ; ; int n, m; struct Mat{//矩阵 ll mat[N][N]; }; Mat operator * (Mat a, Mat b){//一次矩阵乘法…
有一个序列是这样定义的:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 给出A,B和N,求f(n)的值. Input 输入3个数:A,B,N.数字之间用空格分割.(-10000 <= A, B <= 10000, 1 <= N <= 10^9) Output 输出f(n)的值. Input示例 3 -1 5 Output示例 6题意:f(n) = (A * f(n - 1) + B * f(n - 2)…
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1013 这是一个等比数列,所以先用求和公式,然后和3^(n+1)有关,有n比较大,所以用快速幂来解决,又有/2的操作,所以可以用费马小定理取逆元. #include<map> #include<queue> #include<stack> #include<cmath> #include<cstdio> #include&…
1046 A^B Mod C 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出3个正整数A B C,求A^B Mod C. 例如,3 5 8,3^5 Mod 8 = 3. Input 3个正整数A B C,中间用空格分隔.(1 <= A,B,C <= 10^9) Output 输出计算结果 Input示例 3 5 8 Output示例 3 题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!prob…
1024: 末位零 Time Limit: 1 Sec  Memory Limit: 32 MB Submit: 60  Solved: 11 [Submit][Status][Web Board] Description 给定一个正整数N,那么N的阶乘N!末尾有多少个0呢?例如:N=10,N!=3 628 800,N!的末尾有两个0. 注意:N<=100,000,000 Input 第一行为N,表示有N个输入.接下来有N行,每一行包括一个正整数. Output 对于每个输入,每行输出结果 Sa…
题目地址:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1013 Konwledge Point: 快速幂:https://www.cnblogs.com/liubilan/p/9450568.html 除法取模:(a/b)%mod = (a%(b*mod))/b 当a/b比mod小,而a又比mod大的时候a先取余再除以b就会产生错误:为了避免这个错误,只需将模数乘以b即可: 这个题目其实就是找规律,n 有1e9大,不…