对于C(n, m) mod p.这里的n,m,p(p为素数)都很大的情况. 就不能再用C(n, m) = C(n - 1,m) + C(n - 1, m - 1)的公式递推了. 一般lucas定理的p不能大,在1e6以内,一下代码应该可以吧 typedef long long LL; using namespace std; LL exp_mod(LL a, LL b, LL p) { LL res = ; ) { ) res = (res * a) % p; a = (a*a) % p; b…
传送门 对分母求一下逆元,把除法取模变成乘法取模,逆元介绍看这里 这种方法只适合模为质数的情况 #include<bits/stdc++.h> using namespace std; ; long long quickpow(long long a, long long b) { ) ; ; a %= mod; while(b) { ) ret = (ret * a) % mod; b >>= ; a = (a * a) % mod; } return ret; } long l…
题目来源 The 2018 ACM-ICPC China JiangSu Provincial Programming Contest 35.4% 1000ms 65536K Persona5 Persona5 is a famous video game. In the game, you are going to build relationship with your friends. You have N friends and each friends have his upper b…
二分求幂 int getMi(int a,int b) { ; ) { //当二进制位k位为1时,需要累乘a的2^k次方,然后用ans保存 == ) { ans *= a; } a *= a; b /= ; } return ans; } 快速幂取模运算 公式: 最终版算法: int PowerMod(int a, int b, int c) { ; a = a % c; ) { = = )ans = (ans * a) % c; b = b/; a = (a * a) % c; } retur…
https://codeforces.com/contest/1236/problem/B Alice got many presents these days. So she decided to pack them into boxes and send them to her friends. There are nn kinds of presents. Presents of one kind are identical (i.e. there is no way to disting…
Sumdiv Time Limit:1000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1845 Appoint description: System Crawler (2015-05-27) Description Consider two natural numbers A and B. Let S be the sum of all natural…
Description People are different. Some secretly read magazines full of interesting girls' pictures, others create an A-bomb in their cellar, others like using Windows, and some like difficult mathematical games. Latest marketing research shows, that…
小明系列故事——师兄帮帮忙 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 3502 Accepted Submission(s): 894 Problem Description 小明自从告别了ACM/ICPC之后,就开始潜心研究数学问题了,一则可以为接下来的考研做准备,再者可以借此机会帮助一些同学,尤其是漂亮的师妹.这不,班里…