解题关键:1001=7*11*13,模数非常小,直接暴力lucas.递归次数几乎为很小的常数.最后用中国剩余定理组合一下即可. 模数很小时,一定记住lucas定理的作用 http://acm.xidian.edu.cn/problem.php?id=1227 #include<bits/stdc++.h> using namespace std; typedef long long ll; ; ; inline int read(){ ;';k=ls,ls=getchar()); ;)+(x&…
CRT, lucas及其扩展形式 exgcd int exgcd(int a, int b, int &x, int &y) { if (b == 0) return a, x = 1, y = 0; int y = exgcd(b, a % b, x, y), t; t = x, x = y, y = t - a / b * y; } 证明: gcd的过程中, 假设我们已经求出了\(b * x + (a~\%~b) * y = gcd(a, b)\)推导到\(a*x + b*y = gc…
Each test case starts with three integers n,m,k(1≤m≤n≤1018,1≤k≤10) on a line where k is the number of primes. Following on the next line are kdifferent primes p1,...,pk. It is guaranteed that M=p1⋅p2⋅⋅⋅pk≤1018 and pi≤105 for every i∈{1,...,k}. Outp…
Unknown Treasure Problem Description On the way to the next secret treasure hiding place, the mathematician discovered a cave unknown to the map. The mathematician entered the cave because it is there. Somewhere deep in the cave, she found a treasure…
首先假设输入的是n,m 我们就是要求m^(Σ(c(n,i) i|n)) mod p 那么根据费马小定理,上式等于 m^(Σ(c(n,i) i|n) mod (p-1)) mod p 那么问题的关键就是求 Σ(c(n,i) i|n) mod (p-1)了 那么如果P是素数的话,我们可以用lucas定理来快速求出来组合数,这道题的p-1是 非素数,那么我们分解质因数pi,假设c(n,i) i|n为X,那我们求出来X mod pi=ai,这个是 符合lucas定理的,那么我们可以得到质因子数个式子…
思路: 枚举约数 套个裸的Lucas+CRT就完了... //By SiriusRen #include <cmath> #include <cstdio> using namespace std; #define int long long ,N=; void exgcd(int a,int b,int &x,int &y){ ,y=;return;} exgcd(b,a%b,x,y); int temp=x;x=y;y=temp-a/b*y; } int CRT…
#include<bits/stdc++.h> #define re register #define int long long using namespace std; ; inline int read(){ re ,b=;re char ch=getchar(); ') b=(ch==:,ch=getchar(); ') a=(a<<)+(a<<)+(ch^),ch=getchar(); return a*b; } inline int qpow(re int…