ACM-数学
fzw_captain
hold on tight
展开
-
Generating function
普通篇 HDU1171#include <iostream>#include <cstdio>#include <cstdlib>using namespace std;int t1[8100],t2[8100] ;/*i:第I个表达式j:第j个变量k:乘第i个表达式子(1+x^i + x^2i + ...) */ int main(){ int num[4] ={0}原创 2016-05-28 18:43:57 · 259 阅读 · 0 评论 -
中国剩余定理 不互质
然,对于不互质的情况,同样可以用它来解。将方程组合并。推导如下 取两方程组 {x = n1*k1 + a1 ; {x = n2*k2 + a2 ; 目标合成为x = n*k + a; 有n1*k1+a1 = n2*k2 + a2 ; 设d = gcd(n1,n2) ; 则有(n1*k1)/d - (n2*k2)/d = (a2-a1)/d; I a:当且仅当 d|(a2-a1) ,原创 2016-07-15 17:59:40 · 1187 阅读 · 0 评论 -
中国剩余定理CRT (互质)
中国剩余定理给出了以下的一元线性同余方程组: 有解的判定条件,并用构造法给出了在有解情况下解的具体形式。 中国剩余定理说明:假设整数m1,m2, … ,mn两两互质,则对任意的整数:a1,a2, … ,an,方程组 有解,并且通解可以用如下方式构造得到: 设M是整数m1,m2, … ,mn的乘积,并设Mi是除了mi以外的n- 1个整数的乘积。 设为Mi^-1模mi的数论倒数 : 方原创 2016-07-15 17:40:52 · 1263 阅读 · 0 评论 -
lucas定理
Lucas 适合大组合数取模。 Lucas定理是用来求 c(n,m) mod p,p为素数的值。 时间复杂度O(logp(n)*p): 表达式C(n,m)%p=C(n/p,m/p)*C(n%p,m%p) 重新证明一遍: 令n=sp+q , m=tp+r .(q ,r ≤p) 原式子=C(sp+q,tp+r)%p (1+x)^nΞ(1+x)^(sp+q)Ξ(1+x)^(sp)*(1+x原创 2016-07-13 11:37:16 · 482 阅读 · 0 评论 -
miller-rabin
概率型素性测试。可以说是历史上对费马小定理的”误“翻译起源,后逐渐发展而成。费尔马小定理:如果p是一个素数,且0#include <iostream>#include <cstdio>#include <cstdlib>typedef long long ll ;using namespace std ;ll multi(ll a, ll b , ll mod){ ll ans =原创 2016-07-11 10:15:23 · 371 阅读 · 0 评论 -
poj 2480 Longge's problem
#include<cstdio>inline void prin(const int &n){ printf("%lld\n",n) ;}typedef long long ll ;ll quick_pow(ll n , ll k){ ll ans = 1; while(k){ if(k&1) ans *= n; n*=原创 2016-07-11 10:04:06 · 245 阅读 · 0 评论 -
HDU 2582 f(n)
定理:设,那么的值为 (1)为素数,那么答案就是 (2)有多个素因子,那么答案就是 (3)只有一个素因子,那么答案就是该素因子#include #include #include using namespace std;//int judge(int n){// int tmp = sqrt(n+0.5) ;原创 2016-06-06 23:40:30 · 324 阅读 · 0 评论 -
POJ 3233 Matrix Power Series
http://poj.org/problem?id=3233分析表达式,等比矩阵求和sum(k) = A + A^2 + A^3+...A^k . k 太大容易联想到求矩阵高次幂。sum(k-1) + A^k = sum(k) . 有这个特性,构造出矩阵:|A 1| ans[0][0] 每次相乘得到A^x , ans[0][1] 每次把ans[0][0] 项加之原创 2016-06-05 12:31:24 · 233 阅读 · 0 评论 -
hdoj 2685
#include #include using namespace std;int quick(int a, int k ,int mod ){ int ans = 1 ; while(k){ if(k&1) { ans = (ans*a)%mod ; } a *= a; a %= mod原创 2016-06-05 16:39:36 · 292 阅读 · 0 评论 -
Fib 性质 Gcd(f[n],f[m]) = f(gcd(n,m))
a) gcd(fn, fn-1) = 1, for all n b) fm+n = fm+1 fn + fm fn-1 c) if m divides n, then fm divides fn and the ever important Euclidean Algorithm which states: if n=qm+r, then gcd(n,m)=gcd(m,r). Fo原创 2016-06-07 18:54:20 · 1446 阅读 · 0 评论 -
HDU 1214
思维要灵活。。原创 2016-06-01 20:37:31 · 257 阅读 · 0 评论 -
HDU2554
(ai-bi)=i+1all(ai+bi) = (1+2n)2n/2all(ai-bi)=(3+n)n/2#include using namespace std;/*(b1+...+bn) = (n(n+3)/2 + 2n(2n+1)/2 )/2== (5n*n+5*n)/4 5n(n+1)/4(a1+...+an) = ( 3n*n-n)/4 n(3n-1)/4*/原创 2016-06-01 14:14:47 · 266 阅读 · 0 评论 -
poj 2229
POJ 2229#include <iostream>#include <cmath>using namespace std;/*if n is odd , then f(n) = f(n-1) .because n is odd , add the answer must have at least a 1, and f(n-1) above all solutionselse if原创 2016-05-31 22:18:07 · 201 阅读 · 0 评论 -
Gauss poj 1222
POJ 1222#include <iostream>#include <cstdio>#include <cmath>#include <cstdlib>using namespace std;//0x11 1x12 1x13 0x14//1x21 0x22 0x23 1x24//0x31 0x32 1x33 0x34//1x41 0x42 0x43 1x44//-> simpl原创 2016-05-30 21:28:28 · 314 阅读 · 0 评论 -
Gauss poj 1830
POJ1830 开关问题巧用位运算。 对于有效true的影响:0->1 , 1->0 ; 无效false的影响:0->0 , 1->1 ; true ^ 0->1 , true^1->0 ; false^0->0 , false^1->1 ; 已知结果矩阵,和初始矩阵,和关系矩阵。初始矩阵^(关系矩阵*变元) == 结果矩阵 变换-> 变元*(关系矩阵)=初始矩阵^结果矩阵 变元的值原创 2016-05-30 18:20:02 · 259 阅读 · 0 评论 -
Gauss template
learn from kuangbin#include <iostream>#include <cmath>#include <cstdio>#include <cstdlib>using namespace std;const int maxn = 50;int a[maxn][maxn]; // zeng guangint x[maxn] ; // ans_xint free_x原创 2016-05-30 14:02:14 · 315 阅读 · 0 评论 -
HDU3939Sticks and Right Triangle勾股数,容斥,欧拉筛,积性函数
若(a, b, c) 三者互质(它们的最大公因数是 1),它们就称为素勾股数。 勾股数的构造: a = m*m-n*n b = 2m*n c = m*m+n*n 若 m 和 n 是互质,而且 m 和 n 其中有一个是偶数,计算出来的 (a, b, c) 就是素勾股数。(若 m 和 n 都是奇数, (a, b, c) 就会全是偶数,不符合互质。) 题意:给定L,求不大于L的勾股数(a,b,原创 2016-07-12 15:34:07 · 517 阅读 · 0 评论