当前位置:网站首页>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;
}
边栏推荐
- 短视频平台开发,依靠DrawerLayout实现侧滑菜单效果
- 【Content-Type请求头的内容】
- mysql插入\更新前+判断条件
- TypeError: Argument ‘angle‘ can not be treated as a double
- Strictmode analysis activity leakage -strictmode principle (3)
- 一站式洞察行业热点,飞瓜数据B站新功能「流量大盘」上线!
- TypeError: can‘t convert cuda:0 device type tensor to numpy. Use Tensor. cpu() to copy the tensor to
- Thinking about business and investment
- [Office PDF] PDF merging and splitting will free us from the functional limitations of paid software, OK
- Open3d point cloud bounding box
猜你喜欢

Exploration and practice of "flow batch integration" in JD

数据探索电商平台用户行为流失分析

流批一体在京东的探索与实践

Microbiological health, why is food microbiological testing important

编译安装oh-my-zsh

Working for eight years as a programmer, but with a salary of three years after graduation, it's too late to be enlightened again

亲测有效,快速创建JMeter桌面快捷方式

Compile and install oh my Zsh

【qt5-tab标签精讲】Tab标签及内容分层解析

测试必备工具-Postman实战教程
随机推荐
Open3d point cloud bounding box
MFC TCP communication server client demo notes vs2019
After working for 6 years, let's take stock of the golden rule of the workplace where workers mix up
迪赛智慧数——其他图表(平行坐标图):2021年应届专业就业情况
【多源bfs】934. Shortest Bridge
Service grid ASM year end summary: how do end users use the service grid?
Gin configuration file
PHP crawls data through third-party plug-ins
QT5-布局在创作中的理解应用
mysql数据库基础:流程控制
zabbix如何配置告警短信?(预警短信通知设置流程)
PHP数组拼接MySQL的in语句
视频教程 | 长安链推出系列视频教程合集(入门)
QT web 开发 - video -- 笔记
laravel+redis 生成订单号-当天从1开始自增
Selenium经典面试题-多窗口切换解决方案
Applet Custom Grid
短信在企业中的应用有哪些?
Laravel+redis generates an order number - automatically increase from 1 on the same day
如何选择券商?另外,手机开户安全么?