当前位置:网站首页>求组合数 AcWing 888. 求组合数 IV
求组合数 AcWing 888. 求组合数 IV
2022-07-27 10:35:00 【T_Y_F666】
求组合数 AcWing 888. 求组合数 IV
原题链接
算法标签
组合数学 组合计数 高精度
思路


代码
#include<bits/stdc++.h>
#define int long long
#define abs fabs
#define rep(i, a, b) for(int i=a;i<b;++i)
#define Rep(i, a, b) for(int i=a;i>=b;--i)
using namespace std;
const int N = 5015;
int pr[N], st[N], s[N], cnt;
inline int read(){
int s=0,w=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
return s*w;
}
void put(int x) {
if(x<0) putchar('-'),x=-x;
if(x>=10) put(x/10);
putchar(x%10^48);
}
void pri(int n){
rep(i, 2, n+1){
if(!st[i]){
pr[cnt++]=i;
}
for(int j=0; pr[j]<=n/i; ++j){
st[pr[j]*i]=true;
if(!(i%pr[j])){
break;
}
}
}
}
int get(int n, int p){
int res=0;
while(n){
res+=n/p;
n/=p;
}
return res;
}
vector<int> mul(vector<int> a, int b){
vector<int> c;
int t=0;
rep(i, 0, a.size()){
t+=a[i]*b;
c.push_back(t%10);
t/=10;
}
while(t){
c.push_back(t%10);
t/=10;
}
return c;
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int a=read(), b=read();
pri(a);
rep(i, 0, cnt){
int p=pr[i];
s[i]=get(a, p)-get(a-b, p)-get(b, p);
}
vector<int> res;
res.push_back(1);
rep(i, 0, cnt){
rep(j, 0, s[i]){
res=mul(res, pr[i]);
}
}
Rep(i, res.size()-1, 0){
printf("%lld", res[i]);
}
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- Antd table+checkbox default value display
- Instructions for mock platform
- 记忆化搜索 AcWing 901. 滑雪
- The difference of iteration number and information entropy
- Maximized array sum after 13 K negations
- What changes will metauniverse bring to the music industry in the trillion market?
- A deep analysis of the soul of C language -- pointer
- The longest ascending subsequence model acwing 1016. The sum of the largest ascending subsequence
- IO流_字符流、IO流小结、IO流案例总结
- Thank you for your likes and attention
猜你喜欢

Knapsack model acwing 423. Picking herbs

Cancer DDD

Opengauss kernel analysis - statistics and row count estimation

如何创建一个带诊断工具的.NET镜像

背包问题 AcWing 9. 分组背包问题

迭代次数的差异与信息熵

最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼

Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!

ACM warm-up Exercise 2 in 2022 summer vacation (summary)

An article reveals the NFT strategy of traditional game manufacturers such as Ubisoft
随机推荐
高斯消元 AcWing 884. 高斯消元解异或线性方程组
IO流_数据输入输出流的概述和讲解
Longest ascending subsequence model acwing 1014. mountaineering
数字三角形模型 AcWing 275. 传纸条
Non progressive phenomena of entropy and morphology
How to build a data index system is the most effective. From 0 to 1, we will take you a quick start - 02 live review
349两个数组的交集和01两数之和
7 row K with the weakest combat effectiveness in the matrix
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
Ten year structure five year life-07 young and vigorous transformation
推导STO双中心动能积分的详细展开式
求组合数 AcWing 885. 求组合数 I
Luogu p1896 non aggression
Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!
Analysis of C language pointer function and function pointer
Longest ascending subsequence model acwing 1010. Interceptor missile
[QNX hypervisor 2.2 user manual]9.9 logger
MySQL installation (RPM package)
349 sum of intersection of two arrays and 01
10 complete half of the questions