当前位置:网站首页>求组合数 AcWing 888. 求组合数 IV
求组合数 AcWing 888. 求组合数 IV
2022-07-05 06:16: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]);
}
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 1.14 - assembly line
- Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135
- 1041 Be Unique
- Operator priority, one catch, no doubt
- 高斯消元 AcWing 884. 高斯消元解异或线性方程组
- 容斥原理 AcWing 890. 能被整除的数
- 【Rust 笔记】15-字符串与文本(下)
- Spark中groupByKey() 和 reduceByKey() 和combineByKey()
- Quickly use Amazon memorydb and build your own redis memory database
- 做 SQL 性能优化真是让人干瞪眼
猜你喜欢
栈 AcWing 3302. 表达式求值
Doing SQL performance optimization is really eye-catching
Quickly use Amazon memorydb and build your own redis memory database
NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
leetcode-6110:网格图中递增路径的数目
Sqlmap tutorial (II) practical skills I
Redis publish subscribe command line implementation
什么是套接字?Socket基本介绍
liunx启动redis
随机推荐
Winter vacation water test 1 Summary
Groupbykey() and reducebykey() and combinebykey() in spark
Nested method, calculation attribute is not applicable, use methods
CPU内核和逻辑处理器的区别
Sword finger offer II 058: schedule
C - XOR to all (binary topic)
1039 Course List for Student
leetcode-6108:解密消息
1041 Be Unique
Leetcode-6108: decrypt messages
A reason that is easy to be ignored when the printer is offline
做 SQL 性能优化真是让人干瞪眼
MySQL advanced part 2: SQL optimization
Single chip computer engineering experience - layered idea
4. 对象映射 - Mapping.Mapster
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
Appium automation test foundation - Summary of appium test environment construction
Chapter 6 relational database theory
MySQL advanced part 2: optimizing SQL steps
[rust notes] 14 set (Part 2)