随笔分类 - 数论
摘要:1.公式法 根据组合数递推公式求解 题目描述: 代码实现: #include<iostream> using namespace std; const int N=2005,p=1e9+7; long long dp[N][N]; void init(){ for(int i=0;i<=2000;i
阅读全文
摘要:中国剩余定理: 代码实现: //互质版中国剩余定理(CRT) #include<iostream> using namespace std; typedef long long LL; const int N=20; LL a[N], b[N]; int n; void exgcd(LL a, LL
阅读全文
摘要:整除的概念和性质: 素数和合数的定义: 例题一:
阅读全文
摘要:欧几里得算法基本原理和证明 代码实现: #include<iostream> using namespace std; int gcd(int a,int b){ return b?gcd(b,a%b):a; } int main(){ int x,y; cin>>x>>y; cout<<gcd(x
阅读全文
摘要:欧拉函数的定义: 公式法求欧拉函数代码实现: #include<iostream> using namespace std; int main(){ int t; cin>>t; while(t--){ int n; cin>>n; int res=n; for(int i=2;i<=n/i;i++
阅读全文
摘要:约数个数和约数之和推导: 约数个数代码实现: 求n个数的乘积的约数个数: #include<iostream> #include<unordered_map> using namespace std; #define int long long const int p=1e9+7; unordere
阅读全文
摘要:筛质数: 朴素筛法代码实现: #include<iostream> using namespace std; const int N=1e5+5; int prime[N],vis[N],cnt; void init(int n){ for(int i=2;i<=n;i++){ if(!vis[i]
阅读全文
摘要:卡特兰数公式: 或者 引例1、(姐妹洗碗问题) 思考过程: 横坐标表示姐姐洗完的碗的个数,纵坐标表示妹妹摞碗的个数,前提条件为妹妹摞碗的个数不能超过姐姐洗完的碗的个数,要求摞法的方案数实际上是求从坐标(0,0)到坐标(5,5)的所有满足条件的路径数。 引例2、(进出栈问题) 思考过程: 本质上和姐妹
阅读全文