当前位置:网站首页>数学知识:求组合数 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;
}
边栏推荐
- One of the basics - overview of sta Basics
- TypeError: Argument ‘angle‘ can not be treated as a double
- 3500字归纳总结:一名合格的软件测试工程师需要掌握的技能大全
- [Qt5 basics] random number display
- Selenium经典面试题-多窗口切换解决方案
- [Qt5 tab] tab label and content hierarchical analysis
- TypeError: Argument ‘angle‘ can not be treated as a double
- Exploration and practice of "flow batch integration" in JD
- Use of typora
- WIN11中MathType编辑中“打开数学输入面板”是灰色不可编辑
猜你喜欢

gin_ gorm

Pre training / transfer learning of models

"Open math input panel" in MathType editing in win11 is gray and cannot be edited

PHP crawls data through third-party plug-ins

Exploration and practice of "flow batch integration" in JD

Neo4j installation, operation, project construction and function realization

Basic knowledge II - Basic definitions related to sta

Service grid ASM year end summary: how do end users use the service grid?

Use of typora

Connectivity basis of Graphs
随机推荐
Zero of DC learning notes -- overview and basic process introduction
Pre training / transfer learning of models
【qt5-tab标签精讲】Tab标签及内容分层解析
图灵奖得主LeCun指明AI未来的出路在于自主学习,这家公司已踏上征途
One of the basics - overview of sta Basics
zabbix如何配置告警短信?(预警短信通知设置流程)
PHP converts two-dimensional array elements into key value pairs
工作八年的程序员,却拿着毕业三年的工资,再不开窍就真晚了...
Basic knowledge II - Basic definitions related to sta
Ks009 implementation of pet management system based on SSH
Use of typora
Log logrus third party library usage
面对产业互联网的时候,甚至还用消费互联网的方式和方法去落地和实践产业互联网
Selenium经典面试题-多窗口切换解决方案
Use strictmode strictmode principle (1)
1500w播放下还藏着什么热点?B站2个未来趋势你不得错过
Service grid ASM year end summary: how do end users use the service grid?
mysql插入\更新前+判断条件
MFC TCP通信服务端客户端Demo备忘vs2019
【动态规划】路径dp:931. Minimum Falling Path Sum