51nod 1004 【快速幂】】的更多相关文章

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&…
1113 矩阵快速幂  基准时间限制:3 秒 空间限制:131072 KB 分值: 40 难度:4级算法题 给出一个N * N的矩阵,其中的元素均为正整数.求这个矩阵的M次方.由于M次方的计算结果太大,只需要输出每个元素Mod (10^9 + 7)的结果.   Input 第1行:2个数N和M,中间用空格分隔.N为矩阵的大小,M为M次方.(2 <= N <= 100, 1 <= M <= 10^9) 第2 - N + 1行:每行N个数,对应N * N矩阵中的1行.(0 <= …
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){//一次矩阵乘法…
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…
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1835 基准时间限制:1 秒 空间限制:131072 KB   初始有n个点,任意两个点之间有一条无向边,现在要移除一些无向边(至少一条),问移除后有恰好m个连通块的方案数是多少. 两个方案不同当且仅当存在至少一条无向边在某个方案中被移除,但是在另一个方案中没被移除. 答案可能很大请模一个998,244,353.   Input 第一行读入n,m. 1<=m<…
题目地址: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大,不…
#include <iostream> #include <cstdio> #include <cmath> #include <vector> #include <cstring> #include <string> #include <algorithm> #include <string> #include <set> #include <functional> #include…
下面我们来看一个容易让人蒙圈的问题:N的阶乘 mod P. 51Nod 1008 N的阶乘 mod P 看到这个可能有的人会想起快速幂,快速幂是N的M次方 mod P,这里可能你就要说你不会做了,其实你会,为什么呢,只要你明白快速幂的原理,你就会发现他们两个其实差不多是同一个问题. 重要原理:积的取模=取模的积再取模. 快速幂不过是一直乘的相同的的数,这里仅仅是改成乘以不同的数而已. 题目: 输入N和P(P为质数),求N! Mod P = ? (Mod 就是求模 %) 例如:n = 10, P…