当前位置:网站首页>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;
}
边栏推荐
- Laravel+redis generates an order number - automatically increase from 1 on the same day
- Sort custom function
- PHP crawls data through third-party plug-ins
- 迪赛智慧数——其他图表(平行坐标图):2021年应届专业就业情况
- Ks009 implementation of pet management system based on SSH
- 日志 logrus第三方库的使用
- With regard to the white box test, you have to master these skills~
- PHP array splicing MySQL in statement
- 软件测试的可持续发展,必须要学会敲代码?
- What are the functions of soil microorganisms in microbial detection?
猜你喜欢
![[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

3500字归纳总结:一名合格的软件测试工程师需要掌握的技能大全

Institute of Microbiology, commonly used biochemical reactions in microbiological testing

Note d'étude du DC: zéro dans le chapitre officiel - - Aperçu et introduction du processus de base

Using recyclerreview to show banner is very simple
![[Qt5 tab] tab label and content hierarchical analysis](/img/cc/c8c2e79877a958f742a8e9e60ceb43.png)
[Qt5 tab] tab label and content hierarchical analysis

3500 word summary: a complete set of skills that a qualified software testing engineer needs to master

工作八年的程序员,却拿着毕业三年的工资,再不开窍就真晚了...

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

Connectivity basis of Graphs
随机推荐
[problem handled] -nvidia SMI command cannot obtain the GPU process number of its own container and the external GPU process number
QT5-布局在创作中的理解应用
Connectivity basis of Graphs
Exploration and practice of "flow batch integration" in JD
Unknown database connection database error
Institute of Microbiology, commonly used biochemical reactions in microbiological testing
gin 配置文件
亲测有效,快速创建JMeter桌面快捷方式
[stack] 921 Minimum Add to Make Parentheses Valid
sort自定义函数
工作6年,来盘点一下职场人混迹职场的黄金法则
Zero of DC learning notes -- overview and basic process introduction
Lecun, a Turing Award winner, pointed out that the future of AI lies in self-learning, and the company has embarked on the journey
Working for eight years as a programmer, but with a salary of three years after graduation, it's too late to be enlightened again
Log logrus third party library usage
微生物安全与健康,什么是生物处理?
DC學習筆記正式篇之零——綜述與基本流程介紹
neo4j安装、运行以及项目的构建和功能实现
zabbix如何配置告警短信?(预警短信通知设置流程)
数字IC设计流程总结