当前位置:网站首页>Mathematical knowledge: finding combinatorial number IV - finding combinatorial number
Mathematical knowledge: finding combinatorial number IV - finding combinatorial number
2022-07-01 01:39:00 【Fight! Sao Nian!】
subject :AcWing 888. Find the combination number IV
Input a,b, seek Cba Value .
Note that the results can be large , Need to use high-precision calculation .
Input format
All in one line , Contains two integers a and b.
Output format
All in one line , Output Cba Value .
Data range
1≤b≤a≤5000
sample input :
5 3
sample output :
10
Topic analysis :
The steps of this problem :
1. Screening primes
2. Find the number of times of each prime
3. Multiply all prime factors with high precision
#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) // Screening primes
{
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) // Number of primes obtained
{
int res=0;
while(n)
{
res+=n/p;
n/=p;
}
return res;
}
// High precision multiplication
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;
}
边栏推荐
- [deepin] common sets
- [stack] 921 Minimum Add to Make Parentheses Valid
- PHP array splicing MySQL in statement
- 日志 logrus第三方库的使用
- The argument type 'function' can't be assigned to the parameter type 'void function()‘
- 直播商城源码,实现左右联动商品分类页面
- Handsontable數據網格組件
- After working for 6 years, let's take stock of the golden rule of the workplace where workers mix up
- The personal test is effective, and the JMeter desktop shortcut is quickly created
- mysql数据库基础:流程控制
猜你喜欢

微研所,微生物检验中常用的生化反应

3dsmax plug-in development traversal node object and object acquisition and inode transformation matrix description

WIN11中MathType编辑中“打开数学输入面板”是灰色不可编辑

Complete software development process

Digital IC design process summary

gin 配置文件

视频教程 | 长安链推出系列视频教程合集(入门)

Test essential tool - postman practical tutorial

One of the basics - overview of sta Basics

农产品换房?“变相”购房补贴!
随机推荐
【队列】933. Number of Recent Calls
Some essential differences
如何选择券商?另外,手机开户安全么?
Basic knowledge 3 - standard unit library
zabbix如何配置告警短信?(预警短信通知设置流程)
gin 配置文件
laravel 事件 & 监听
Draw some interesting figures with flutter's canvas
用 Flutter 的 Canvas 画点有趣的图形
Sort custom function
Digital IC design process summary
未来的 Web3会带来什么?
[simulation] 922 Sort Array By Parity II
System. Csrebot for commandline
Log logrus third party library usage
测试必备工具-Postman实战教程
6月第4周榜单丨飞瓜数据UP主成长排行榜(哔哩哔哩平台)发布!
3500 word summary: a complete set of skills that a qualified software testing engineer needs to master
Lecun, a Turing Award winner, pointed out that the future of AI lies in self-learning, and the company has embarked on the journey
Thinking brought by strictmode -strictmode principle (5)