随笔分类 -  数论

摘要:#define repf(i,a,b) for(int i=(a);i>= 1; } return c; } 阅读全文
posted @ 2016-08-27 13:28 相儒以沫 阅读(134) 评论(0) 推荐(0)
摘要:LL exp_mod(LL a, LL b, LL mod) { LL res = 1; while(b != 0) { if(b&1) res = (res * a) % mod; a = (a*a) % mod; b >>= 1; } return res; } LL Comb(LL a, LL b, LL... 阅读全文
posted @ 2016-08-05 09:18 相儒以沫 阅读(204) 评论(0) 推荐(0)
摘要:包含在c++<algorithm>库中的next_permutation(arr,arr+n)函数可以实现arr中元素的全排列 但是要求arr中元素事先已经按字典序排列好 具体使用方法如下: 阅读全文
posted @ 2016-07-13 08:43 相儒以沫 阅读(1799) 评论(0) 推荐(0)
摘要:ax=b(mod n) (1), 求解x 已知 ax+ny=gcd(a,n) (2),对等式两边取模 ax=gcd(a,n)(mod n) (3) 所以,原方程有解的条件是gcd(a,n)|b,即b=k*gcd(a,n); 所以,通过求解(2)可以得到x' 而x=x'*b/gcd(a,n)得到所求解 阅读全文
posted @ 2016-07-12 16:25 相儒以沫 阅读(753) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 4 using namespace std; 5 6 long long exgcd(long long a,long long b,long long &x,long long &y) 7 { 8 if(b==0) 9 {1... 阅读全文
posted @ 2015-10-03 11:48 相儒以沫 阅读(146) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 6 int arr[100000]; 7 8 using namespace std; 9 10 int main()11 {12 int n;13 cin>>n;14 ... 阅读全文
posted @ 2015-08-31 19:52 相儒以沫 阅读(128) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 //矩阵大小上限 8 const int SIZ=100; 9 int MOD=100;10 11 //矩阵大小为n*m,初始化全部为012 struct mat1... 阅读全文
posted @ 2015-08-29 10:47 相儒以沫 阅读(155) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 8 long long arr1[100000]; 9 long long MOD=9901;10 11 long long multi(lon... 阅读全文
posted @ 2015-08-13 09:52 相儒以沫 阅读(183) 评论(0) 推荐(0)
摘要:证明:设1,2,...,n的全排列t1,t2,...,tn的集合为I,而使ti=i的全排列的集合记为Ai(1<=i<=n),则Dn=|I|-|A1∪A2∪...∪An|.所以Dn=n!-|A1∪A2∪...∪An|.注意到|Ai|=(n-1)!,|Ai∩Aj|=(n-2)!,...,|A1∩A2∩.... 阅读全文
posted @ 2015-08-12 14:43 相儒以沫 阅读(227) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 void gcd(int a,int b,int &d,int &x,int &y) 8 { 9 if(!b)10 {11 d=a;... 阅读全文
posted @ 2015-08-12 14:22 相儒以沫 阅读(173) 评论(0) 推荐(0)
摘要:1 import java.math.*; 2 import java.util.*; 3 4 public class Main 5 { 6 public static void main(String[] args) 7 { 8 int m,n; 9 ... 阅读全文
posted @ 2015-08-05 15:00 相儒以沫 阅读(186) 评论(0) 推荐(0)
摘要:卡特兰数前几项为 : 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 208012, 742900, 2674440, 9694845, 35357670, 129644790, 477638700, 1767263190, 65641... 阅读全文
posted @ 2015-08-05 13:15 相儒以沫 阅读(146) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 //矩阵大小上限 8 const int SIZ=110; 9 int MOD=1000000000; 10 11 //矩阵大小为n*m,初始化... 阅读全文
posted @ 2015-07-27 15:09 相儒以沫 阅读(236) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 4 using namespace std; 5 6 long long tmp[11]; 7 8 //矩阵大小上限 9 const int SIZ=100; 10 int MOD=10000007; 11 12 //矩... 阅读全文
posted @ 2015-07-27 10:41 相儒以沫 阅读(104) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 4 using namespace std; 5 6 //矩阵大小上限 7 const int SIZ=100; 8 int MOD; 9 10 //矩阵大小为n*m,初始化全部为0 11 struct mat 12 { ... 阅读全文
posted @ 2015-07-26 16:31 相儒以沫 阅读(161) 评论(0) 推荐(0)
摘要:1 const int maxn=32790; 2 int euler[maxn+2]; 3 void make() 4 { 5 euler[1]=0; 6 for(int i=2;i<=maxn;++i) 7 euler[i]=i; 8 for(int i... 阅读全文
posted @ 2015-07-25 09:12 相儒以沫 阅读(383) 评论(0) 推荐(0)
摘要:1 int gcd(int x3,int y3) 2 { 3 int x1 = 1,x2 = 0,y1 = 0,y2 = 1; 4 while(1) 5 { 6 if (y3==1) return y2; 7 int q=x3/y3; 8 ... 阅读全文
posted @ 2015-07-24 18:06 相儒以沫 阅读(192) 评论(0) 推荐(0)
摘要:1 void gcd(int a,int b,int &d,int &x,int &y) 2 { 3 if(!b) 4 { 5 d=a; 6 x=1; 7 y=0; 8 } 9 else10 {11 ... 阅读全文
posted @ 2015-07-24 18:05 相儒以沫 阅读(155) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 int exgcd(int a,int b,int &x,int &y) 8 { 9 if(b==0)10 {11 x=1;12 ... 阅读全文
posted @ 2015-07-24 17:54 相儒以沫 阅读(156) 评论(0) 推荐(0)
摘要:1 #include 2 #include 3 #include 4 5 using namespace std; 6 7 int gcd(int a,int b) 8 { 9 if(b==0)10 return a;11 else12 r... 阅读全文
posted @ 2015-07-24 15:18 相儒以沫 阅读(123) 评论(0) 推荐(0)