当前位置:网站首页>求组合数 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]);
}
}
原创不易
转载请标明出处
如果对你有所帮助 别忘啦点赞支持哈
边栏推荐
- The influence of the number of non-zero values in the picture on Classification
- Study notes Minio
- Local and overall differences between emergence and morphology
- Longest ascending subsequence model acwing 1010. Interceptor missile
- Taishan Office Technology Lecture: scaling and opening files
- The longest ascending subsequence model acwing 1017. The glider wing of the strange thief Kidd
- Internal and external troubles of digital collection NFT "boring ape" bayc
- 最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
- Opengauss kernel analysis - statistics and row count estimation
- IO流_数据输入输出流的概述和讲解
猜你喜欢

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

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

tensorflow运行报错解决方法

The longest ascending subsequence model acwing 1016. The sum of the largest ascending subsequence

最长上升子序列模型 AcWing 482. 合唱队形

黑白像素分布对迭代次数的影响

Budweiser, a well-known beer, plans to launch NFT in an attempt to unveil the "long planned" uplink?

Antd table+checkbox default value display

BeautifulSoup的使用

Redis+caffeine two-level cache enables smooth access speed
随机推荐
基于FPGA的ECG信号采集,存储以及传输系统verilog实现
Digital triangle model acwing 275. pass note
Shortest moving distance and entropy of morphological complex
Why is the data service API the standard configuration of the data midrange when we take the last mile of the data midrange?
高斯消元 AcWing 884. 高斯消元解异或线性方程组
01 BTC cryptology principle
Today's code farmer girl summarized her notes about NPM package management and URL module
Derivation of the detailed expansion sto overlap integrals
最长上升子序列模型 AcWing 1016. 最大上升子序列和
49 letter ectopic grouping and 242 effective letter ectopic words
PAT(乙级)2022年夏季考试
The longest ascending subsequence model acwing 1017. The glider wing of the strange thief Kidd
Use of pyquery
Error: image clipToBoundsAndScale, argument 'input'
Yonbuilder enables innovation, and the "golden keyboard Award" of the fourth UFIDA developer competition is open!
数字三角形模型 AcWing 1027. 方格取数
Instructions for mock platform
中国剩余定理 AcWing 204. 表达整数的奇怪方式
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
Yiwen counts NFT projects valued at more than US $100million