当前位置:网站首页>数学知识:求组合数 IV—求组合数
数学知识:求组合数 IV—求组合数
2022-07-01 01:02:00 【奋斗吧!骚年!】
题目:AcWing 888. 求组合数 IV
输入 a,b,求 Cba 的值。
注意结果可能很大,需要使用高精度计算。
输入格式
共一行,包含两个整数 a 和 b。
输出格式
共一行,输出 Cba 的值。
数据范围
1≤b≤a≤5000
输入样例:
5 3
输出样例:
10
题目分析:
这道题步骤:
1.筛选素数
2.求每个质数的次数
3.用高精度乘把所有质因子乘上
#include <iostream>
#include <vector>
using namespace std;
const int N = 5010;
int primes[N],cnt;
int sum[N];
bool st[N];
void get_prime(int n) // 筛选素数
{
for(int i=2;i<=n;i++)
{
if(!st[i])primes[cnt++]=i;
for(int j=0;primes[j]<=n/i;j++)
{
st[primes[j]*i]=true;
if(i%primes[j]==0)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;
for (int i=0;i<a.size();i++)
{
t+=a[i]*b;
c.push_back(t%10);
t/=10;
}
while(t)
{
c.push_back(t%10);
t/=10;
}
return c;
}
int main()
{
int a,b;
cin>>a>>b;
get_prime(a);
for(int i=0;i<cnt;i++)
{
int p=primes[i];
sum[i]=get(a,p)-get(a-b,p)-get(b,p);
}
vector<int> res;
res.push_back(1);
for(int i=0;i<cnt;i++)
for(int j=0;j<sum[i];j++)
res = mul(res, primes[i]);
for(int i=res.size()-1;i>=0;i--)cout<<res[i];
cout<<endl;
return 0;
}
边栏推荐
- [Qt5 basic \u 1] starting from 0, Mr. Detian will study with you - Introduction to the window
- Digital IC design process summary
- Handsontable data grid component
- 45岁程序员告诉你:程序员为什么要跳槽,太真实...
- laravel Carbon 时间处理类使用
- 那些一门心思研究自动化测试的人,后来怎样了?
- 工作6年,来盘点一下职场人混迹职场的黄金法则
- [simulation] 922 Sort Array By Parity II
- Thinking brought by strictmode -strictmode principle (5)
- [Office PDF] PDF merging and splitting will free us from the functional limitations of paid software, OK
猜你喜欢

日志 logrus第三方库的使用

dc_ Study and summary of labs--lab1
![[problem handled] -nvidia SMI command cannot obtain the GPU process number of its own container and the external GPU process number](/img/51/e48e222c14f4a4e9f2be91a677033f.png)
[problem handled] -nvidia SMI command cannot obtain the GPU process number of its own container and the external GPU process number

Construction and beautification of personal blog

元宇宙为 VR/AR 带来的新机会

图的连通性基础

一站式洞察行业热点,飞瓜数据B站新功能「流量大盘」上线!

neo4j安装、运行以及项目的构建和功能实现

45岁程序员告诉你:程序员为什么要跳槽,太真实...

Creating ASCII art with C #
随机推荐
Lecun, a Turing Award winner, pointed out that the future of AI lies in self-learning, and the company has embarked on the journey
3500字归纳总结:一名合格的软件测试工程师需要掌握的技能大全
gin_ gorm
Handsontable數據網格組件
【多源bfs】934. Shortest Bridge
[Qt5 tab] tab label and content hierarchical analysis
C# 自定义并动态切换光标
远程办公如何保持高效协同,实现项目稳定增长 |社区征文
Ks009 implementation of pet management system based on SSH
Sécurité et santé microbiennes, qu'est - ce que le traitement biologique?
Try new possibilities
Last day of the second quarter
New opportunities for vr/ar brought by metauniverse
Strictmode analysis registration strictmode principle (4)
What will Web3 bring in the future?
一站式洞察行业热点,飞瓜数据B站新功能「流量大盘」上线!
Use of typora
短视频平台开发,依靠DrawerLayout实现侧滑菜单效果
【队列】933. Number of Recent Calls
Relationship between ASCII, Unicode, GBK, UTF-8