随笔 - 531
文章 - 0
评论 - 3
阅读 -
10215
随笔分类 - 数学
求质因数
摘要:1. 求一个数的质因数 #include <iostream> #include <algorithm> using namespace std; const int N =200; int tot,fac[N]; void getFac(int x){ tot=0; for(int i=2;i*i
阅读全文
递推组合数
摘要:const int M=1e3; const int N=2e3; int c[N][N]; void init(){ int i,j; c[1][1]=1; for(i=0;i<=M;i++) c[i][0]=1; for(i=2;i<=M;i++) for(j=1;j<=i;j++) c[i][
阅读全文
奶牛和轿车 Cows and Cars uva 10491
摘要:全概率公式 #include <iostream> #include <cstring> #include <iomanip> using namespace std; int main(){ double a,b,c; while(cin>>a>>b>>c){ cout<<setprecision
阅读全文
同余线性方程组
摘要:求解 ax Ξb (mod n) 充要条件: ax-b= k*n 即 ax-ny = b 1. 用exgcd 可以求方程 ax-ny= gcd(a,n) 的一组解 即 x0 , y0, https://www.cnblogs.com/towboa/p/17001472.html 2. 可以得到原方程
阅读全文
幂取模
摘要:运用分治,复杂度logn typedef long long LL; LL mod; LL f(LL a,LL b){ if(b==1) return a; if(b==0) return 1; LL t=f(a,b/2); return b%2==0? t*t%mod : (((t*t)%mod)
阅读全文
筛质数
摘要:int b[N+2], pm[N+2],tot=0; void init(){ b[1]=1; for(int i=2;i<=N;i++){ if(b[i]) continue; pm[++tot]= i; for(int j=2;j*i<=N;j++) b[j*i]=1; } } const in
阅读全文
扩展欧几里得算法
摘要:算法求解了不定方程 ax+by=gcd(a,b) (1) 的一组解x0,y0 void gcd(int a,int b,int &d,int &x,int &y){ if(b==0){ d=a; x=1,y=0; return ; } gcd(b,a%b,d,y,x); y-=x*(a/b); }
阅读全文