当前位置:网站首页>求组合数 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]);
}
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- 数据可视化图表总结(一)
- Operator priority, one catch, no doubt
- Leetcode recursion
- How to understand the definition of sequence limit?
- 可变电阻器概述——结构、工作和不同应用
- Appium自动化测试基础 — Appium测试环境搭建总结
- MySQL advanced part 1: index
- [rust notes] 13 iterator (Part 2)
- 4. Object mapping Mapster
- Leetcode-6110: number of incremental paths in the grid graph
猜你喜欢

Matrixdb V4.5.0 was launched with a new mars2 storage engine!

开源存储这么香,为何我们还要坚持自研?

博弈论 AcWing 891. Nim游戏

实时时钟 (RTC)

Sqlmap tutorial (1)

WordPress switches the page, and the domain name changes back to the IP address

MIT-6874-Deep Learning in the Life Sciences Week 7

leetcode-6110:网格图中递增路径的数目

博弈论 AcWing 893. 集合-Nim游戏

Single chip computer engineering experience - layered idea
随机推荐
SQLMAP使用教程(二)实战技巧一
快速使用Amazon MemoryDB并构建你专属的Redis内存数据库
背包问题 AcWing 9. 分组背包问题
Niu Mei's math problems
栈 AcWing 3302. 表达式求值
博弈论 AcWing 893. 集合-Nim游戏
How to understand the definition of sequence limit?
Leetcode-6108: decrypt messages
博弈论 AcWing 891. Nim游戏
一些工具的记录2022
LeetCode 0107. Sequence traversal of binary tree II - another method
Règlement sur la sécurité des réseaux dans les écoles professionnelles secondaires du concours de compétences des écoles professionnelles de la province de Guizhou en 2022
传统数据库逐渐“难适应”,云原生数据库脱颖而出
Arduino 控制的 RGB LED 无限镜
数据可视化图表总结(二)
[rust notes] 17 concurrent (Part 1)
redis发布订阅命令行实现
1040 Longest Symmetric String
打印机脱机时一种容易被忽略的原因
Simple selection sort of selection sort