随笔分类 - 数学
摘要:《组合数学》里面的容斥原理,写的。。太乱了啊, 下面是关于容斥原理的详细介绍链接:http://www.cppblog.com/vici/archive/2011/09/05/155103.html 自己理解个粗浅的意思,容斥原理其实就是概率论里面的加法公式的n项延伸, 对于集合Ai有以下原理公式, 原理的意思就是: 要计算n个集合并集的大小,先计算所有单个集合的大小,再减去所有两个集合相...
阅读全文
摘要:欧拉函数总结+证明 欧拉函数总结2 POJ 1284 原根 #include #include #include #include #include using namespace std; int Euler(int n) { int res=n; for(int i=2;i*i1) res-=(res/n); return res; } int ...
阅读全文
摘要:/**********/ #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; /***********GCD**********************/ ll gcd(ll a,...
阅读全文
摘要:素数判定Miller_Rabin算法详解: http://blog.csdn.net/maxichu/article/details/45458569 大数因数分解Pollard_rho算法详解: http://blog.csdn.net/maxichu/article/details/45459533 然后是参考了kuangbin的模板: http://www.cnblogs.com/kuang...
阅读全文
摘要:找素数本来是很简单的问题,但当数据变大时,用朴素思想来找素数想必是会超时的,所以用素数筛法。 素数筛法 打表伪代码(用prime数组保存区间内的所有素数): void isPrime() vis[]数组清零;//vis[]数组用于标记是否已被检验过 prime[]数组全赋初值false;//prime[]数组从下标0...
阅读全文
摘要:以下是三种高精度算术的模版: 高精度加法: string s="0123456789",s1,s2; int ss1[1005],ss2[1005],len; void dashu(string s1,int ss1[]) { for(int i=s1.length()-1;i>=0;i--) { for(int j=0;jlen2) len=l...
阅读全文
摘要:当mod一个大数p的时候,还有进行乘法的时候可能会爆long long的时候,就用快速乘或者快速幂。 参考:http://www.cnblogs.com/whywhy/p/5066730.html 先上模板: 快速乘: ll multi(ll a,ll b,ll m) { ll ans=0; while(b) { if(b&1) (ans+=a) %= m...
阅读全文

浙公网安备 33010602011771号