数学
After0514
这个作者很懒,什么都没留下…
展开
-
辛普森
#include#include#includeusing namespace std;double F(double x){//f(x) return 0.0;}double simpson(double a,double b){ double c=(a+b)/2; return (F(a)+4*F(c)+F(b)*(b-a))/6;原创 2016-11-06 11:42:00 · 279 阅读 · 0 评论 -
Problem Three:[SPOJ LCMSUM]
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=27840 ∑lcm(i,n)=∑i∗n/gcd(i,n)=n∗∑i/gcd(i,n)=n∗∑d|n∑gcd(i,d)=1N/din∗∑d|nd∗φ(d)/2\begin{equation*}\sum lcm(i,n)=\sum i*n/gcd(i,n)=\\n*\sum i原创 2016-11-20 00:06:06 · 321 阅读 · 0 评论 -
Problem Four:[SPOJ GCDEX]
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=10576 ∑Ni=1∑i−1j=1gcd(i,j)\sum_{i=1}^N \sum_{j=1}^{i-1} gcd(i,j) 预处理 ∑Ni=1gcd(i,j)\sum_{i=1}^N gcd(i,j) 同 http://blog.csdn.net/wen_xp/ar原创 2016-11-20 00:21:24 · 298 阅读 · 0 评论 -
Problem Five:[双亲数/POI Zap(多组)]
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=21352 ∑i=1a∑j=1bgcd(i,j)==d=∑i=1a/d∑j=1b/dgcd(i,j)==1=∑i=1a/d∑j=1b/d∑d|i,d|jmin(i,j)μ(d)=∑d1=1min(a/d,b/d)μ(d1)∗(a/d/d1)∗(b/d/d1)\begin{equa原创 2016-11-20 10:23:15 · 271 阅读 · 0 评论 -
Problem Six:[SPOJ PGCD/BZOJ2820YY的GCD(多组)]
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=10581 ∑i=1n∑j=1mgcd(i,j)==质数另f(x)为gcd(i,j)=x的对数f(x)=∑x|dμ(d/x)∗(n/d)∗(m/d)ans=∑p,p为质数min(n,m)∗f(p)=∑p,p为质数min(n,m)∗∑dμ(d)∗⌊np∗d⌋∗⌊mp∗d⌋另T=p∗原创 2016-11-20 11:35:12 · 407 阅读 · 0 评论 -
Codeforces 311C
给定n个数字b_j,r个数字a_i 1.判断下面方程是否有整数解 1+∑i=1rxi∗ai=bj1+\sum_{i=1}^r x_i*a_i =b_j 2.r++,增加a_r,r最多为20#include <cstdio>#include <queue>using namespace std;typedef long long ll;const int N=1e5+5,K=1e4原创 2016-12-02 11:05:04 · 278 阅读 · 0 评论 -
Problem Seven:[NOI 2010 能量采集]
http://www.lydsy.com/JudgeOnline/problem.php?id=2005 ∑i=1n∑j=1mgcd(i,j)单组询问,反向递推f(x)表示gcd(i,j)==x的对数f(x)=(n/x)∗(m/x)−∑i=1min(n,m)/xf(x∗i)多组询问∑i=1n∑j=1m∑d|i,d|jmin(i,j)φ(d)=∑d=1min(n,m)φ(d)∗(n/d)∗(m/d)原创 2016-11-20 12:13:40 · 257 阅读 · 0 评论 -
Problem Eight:[Crash的数字表格/BZOJ2693 jzptab(多组)]
http://www.lydsy.com/JudgeOnline/problem.php?id=2154 ans=∑i=1n∑j=1mlcm(i,j)=∑i=1n∑j=1mi∗j/gcd(i,j)f(x,y)=∑i=1x∑j=1yi∗j∗[gcd(i,j)==1]ans=∑d=1min(n,m)d∗f(n/d,m/d)f(x,y)=∑i=1x∑j=1yi∗j∗∑k|i,k|jμ(k)=∑k=1mi原创 2016-11-20 12:35:00 · 325 阅读 · 0 评论 -
Problem Nine:[BZOJ2694LCM]
n的所有质因子次数<=1,则n是free−squaresans=∑i=1n∑j=1mlcm(i,j)[gcd(i,j)∈free−squares]另F(x)=⎧⎩⎨1x,0,x∈free−squaresx∉free−squares另t(n)=∑i|nμ(i)∗F(n/i)ans=∑i=1n∑j=1mi∗j∑d|i,d|jt(d)=∑d=1min(n,m)t(d)∗d2∑i=1n/d∑j=1m/di∗原创 2016-11-20 14:46:52 · 284 阅读 · 0 评论 -
Codeforces 93E
1~n多少个数不能被任意aia_i整除,n<=101310^{13} ,i<=100#include<bits/stdc++.h>using namespace std;#define rep(i,a,b) for(int i=a;i<=b;++i)const int maxn = 101000;typedef long long int ll;ll f[maxn][101];int a[原创 2016-12-05 20:03:18 · 462 阅读 · 0 评论 -
CodeForces 138D
观察可以看出 (a+b)%2==1和(a+b)%2==0 两个游戏相互独立 坐标变换 (a,b)->(a-b,a+b) 然后暴力计算sg值#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int N=22;char ss[N][N];i原创 2016-11-23 21:02:41 · 303 阅读 · 0 评论 -
Codeforces 576D
把边按需求次数从小到大排序 然后快速幂+每次重构矩阵#include <bits/stdc++.h>using namespace std;const int N=155;bitset<N> tmp[N],cur[N],aa[N];bitset<N> can[N],t,ok,mp[N];int n,m;void mat_p(int x){ for(int i=1;i<=n;i++原创 2016-12-08 10:49:13 · 307 阅读 · 0 评论 -
CodeForces 392C
矩阵快速幂#include#include#includeusing namespace std;typedef __int64 LL;const int mod=1e9+7;const int N=100;int K;void pri(LL A[N][N]){ for(int i=0;i<K;i++){ for(int j=0;j<K;j++原创 2016-10-30 21:55:28 · 316 阅读 · 0 评论 -
CodeForces 622F
http://codeforces.com/problemset/problem/622/F#include#include#include#include#include#include#includeusing namespace std;const int N=1e6+10;const int mod=1e9+7;typedef __int64 LL;LL原创 2016-10-26 10:48:09 · 405 阅读 · 0 评论 -
Problem Two:[Longge's problem]
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=295737 F(N)=∑gcd(i,n)=∑d|Nd∗φ(N/d)F(pk)=∑i=0kpi∗φ(pk−i)=k∗(pk−pk−1)+pk\begin{equation*}F(N)=\sum{gcd(i,n)}=\\\sum_{d|N}d*\varphi(N/d)\\F(原创 2016-11-19 23:32:48 · 274 阅读 · 0 评论 -
CodeForces 235E
http://blog.csdn.net/tc_to_top/article/details/48014357 ∑i=1a∑j=1b∑k=1cd(i∗j∗k)=∑gcd(i,j)=1,gcd(i,k)=1,gcd(k,j)=1⌊ai⌋⌊bj⌋⌊ck⌋=∑a⌊ai⌋∑gcd(i,j)=1b⌊bj⌋∑gcd(i,k)=1c⌊ck⌋∗gcd(k,j)==1gcd(k,j)==1=∑d|k,d|jmin(原创 2016-11-19 23:13:23 · 477 阅读 · 0 评论 -
三对角矩阵
#include#include#includeconst int N=1000+100;void tdma(int n,double aa[N],double bb[N],double cc[N],double xx[N]){ cc[0]=cc[0]/bb[0]; xx[0]=xx[0]/bb[0]; for(int i=1;i<n;i++){原创 2016-11-06 11:42:20 · 1596 阅读 · 0 评论 -
米勒测试
#include#include#include#include#include#includeusing namespace std;typedef __int64 LL;LL prime[]={2,3,5,7,11,19,23,29};LL mul(LL a,LL b,LL n){ LL s=0;a%=n; while(b){原创 2016-11-06 11:42:42 · 1166 阅读 · 0 评论 -
fft
#include#include#include#includeusing namespace std;#define ld doubleld pi=acos(-1.0); //注意π的精度const int N=50000+100;struct Complex{ ld r; ld i; Complex(){}; Complex(原创 2016-11-06 11:43:05 · 437 阅读 · 0 评论 -
NTT
#include#include#include#includeusing namespace std;typedef long long LL;const int P=998244353;const int MN=1<<18;const int g=10;LL power(LL a,int b){ LL res=1; while(b){原创 2016-11-06 11:43:09 · 178 阅读 · 0 评论 -
中国剩余
#include#include#includeusing namespace std;typedef __int64 LL;LL gcd(LL a, LL b){ return b==0?a:gcd(b, a%b);}void extend_gcd(LL a, LL b, LL &d, LL &x, LL &y){ if(!b){原创 2016-11-06 11:43:26 · 241 阅读 · 0 评论 -
CodeForces 113D
dp+高斯消元 两个人从a,b同时出发,随机走,当他们相遇的时候停止,问在A点停止的概率#include<cstdio>#include<iostream>#include<cstring>#include<cmath>using namespace std;const double eps=1e-14;const int N=25*25;int n,m,s,t;int mp[N]原创 2016-11-09 16:18:27 · 383 阅读 · 0 评论 -
CodeForces 185D
如果K为偶数,任意两个数互质 如果K为奇数,任意两个数gcd==2 然后算 乘积 然后算 和 等比数列#include<cstdio>#include<cstring>#include<iostream>using namespace std;typedef __int64 LL;LL _pow(LL a,LL b,LL mod){ LL c=1;a%=mod; whi原创 2016-11-10 21:34:16 · 566 阅读 · 0 评论 -
CodeForces 107D
矩阵快速幂 写出dp方程 状态就是所有模数的余数值的所有情况#include<cstdio>#include<iostream>#include<cstring>#include<vector>#include<algorithm>using namespace std;typedef __int64 LL;const int mod=12345;const int N=130;原创 2016-11-15 22:02:24 · 298 阅读 · 0 评论 -
CodeForces 593E
按时间分段, 在每个时间段内,进行矩阵快速幂#include<cstdio>#include<algorithm>#include<cstring>using namespace std;const int mod=1000000007;int M[44][44],Me[44][44],V[44],Ve[44],n;void pow_M(int e){ while(1)原创 2016-11-29 13:54:19 · 302 阅读 · 0 评论 -
CodeForces 286E
fft#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>using namespace std;#define ld doubleld pi=acos(-1.0); //注意π的精度typedef __int64 ll;const int N=1e6+100;struct Complex{原创 2016-11-17 20:57:19 · 404 阅读 · 0 评论 -
CodeForces 585E
ff[i]:i的倍数的个数 gg[i]:gcd==i的集合的个数 kk[i]:和i不互质的数的个数 #include<cstdio>#include<cstring>#include<iostream>using namespace std;const int mod=1e9+7;typedef __int64 LL;int _pow(int a,int b){ int c=1原创 2016-11-14 21:08:55 · 350 阅读 · 0 评论 -
CodeForces 93D
矩阵快速幂+波利亚定理 波利亚可以解决同构问题 前三条列出递推矩阵#include<cstdio>#include<iostream>#include<cstring>using namespace std;const int N=10;const int mod=1e9+7;typedef __int64 LL;void cp(LL A[N][N],LL B[N][N],int n原创 2016-11-15 11:03:04 · 373 阅读 · 0 评论 -
Problem One:[CQOI2007 余数之和sum]
Problem One:[CQOI2007 余数之和sum] ∑i=1n(K%i)\begin{equation*}\sum_{i=1}^n(K\%i)\end{equation*} [http://www.lydsy.com/JudgeOnline/problem.php?id=1257]#include<cstdio>#include<iostream>#include<cstrin原创 2016-11-19 00:11:33 · 303 阅读 · 0 评论 -
Codeforces 358E
真的不会做。。。 别人的代码没怎么看懂。。。#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <cstdio>#include <queue>#include <cmath>#include <stack>#include <map>#pragma comment(原创 2016-12-25 11:51:33 · 234 阅读 · 0 评论