1055. Combinations

Time limit: 1.0 second
Memory limit: 64 MB
As you have known MMM corporation lab researches the matter of haricot proportions in soup For every day. The ladle is placed down into the soup pan. This ladle holds exactly M haricot seeds of N got into the pan. All the seeds are of different size.
Experimenters calculate the quantity of possible methods to proportion M seeds in the pan with the formula: C = N! / (M! · (N − M)!). The main feature of these experiments is the quantity of different prime divisors of number C.
Lest money would be spent for programmer, MMM corporation board decided to make necessary estimating during the ICPC quarterfinal in Rybinsk. Thus, your aim is to find this quantity.

Input

The only line contains integers N and M that are the number of haricot seeds in the pan and the capacity of the ladle (1 ≤ M < N ≤ 50000).

Output

Output the quantity of different prime divisors of number C.

Sample

input output
5 3
2

Notes

In the example C = 5! / (3! · 2!) = 120 / (6 · 2) = 10 = 2 · 5.
https://acm.timus.ru/problem.aspx?space=1&num=1055
大意
输入n,m。求出Cmn中不同质因数的个数
思路
不能算出来,C最大50000!。
map统计质因数,先统计m!,在统计n!,最后统计m-n!
代码
#include <bits/stdc++.h>
using namespace std;
map<int,int>mp;
int main(){
int m,n;
cin>>m>>n;
for(int i=1;i<=m;i++){
int num=i;
for(int j=2;j*j<=i&&num!=1;j++){
while(num%j==0){
num/=j;
mp[j]++;
} }
if(num!=1){
mp[num]++;
}
}
for(int i=1;i<=n;i++){
int num=i;
for(int j=2;j*j<=i&&num!=1;j++){
while(num%j==0){
num/=j;
mp[j]--;
} }
if(num!=1){
mp[num]--;
}
}
for(int i=1;i<=m-n;i++){
int num=i;
for(int j=2;j*j<=i&&num!=1;j++){
while(num%j==0){
num/=j;
mp[j]--;
} }
if(num!=1){
mp[num]--;
}
}
int ans=0;
for(auto t:mp){
if(t.second!=0){
ans++;
}
}
cout<<ans<<endl;
}

版权所有,参考请贴网址;{^__^}

 
 
 
 
 
 
 
 

最新文章

  1. Oracle执行计划详解
  2. JS中的“!!”
  3. 配置Tomcat web保存文件到项目路径之外
  4. Docker 安装部署
  5. MSSql使用SQL语句快速查看表对的就说明,及表字段描述及字段类型
  6. Vijos1056 图形面积
  7. Xcode 之自己编译静态库
  8. IE中console的正确使用方法
  9. tcpdump tutorial
  10. python challenge第1关--NoteBook上的“乱码”
  11. Scala学习——基础篇
  12. C primer plus 读书笔记第十一章
  13. jquery css hover
  14. Java NIO 与 IO
  15. 原生javascript 制作canvas 验证码
  16. ORM(二)常用字段小记
  17. mac电脑使用技巧和相关快捷键
  18. Java核心技术及面试指南面试题,基本数据类型、封装类和运算操作的面试题
  19. 《EM-PLANT仿真技术教程》读书笔记
  20. Python自动化开发 - 函数式编程

热门文章

  1. XSS漏洞利用案例实验
  2. Python图像处理丨详解图像去雾处理方法
  3. All in one入门之All in one和三种PVE、ESXI、Windows Server方案
  4. [python] 基于paramiko库操作远程服务器
  5. 基于Spark的均值漂移算法在网络舆情聚类中的应用
  6. VMware Workstation Pro 16安装CentOS7超详细图文步骤
  7. Svelte框架实现表格协同文档
  8. 踩坑纪实----tomcat部署前端服务器不能访问中文文件夹或中文文件名问题
  9. 创建型模式 - 单例模式Singleton
  10. 前端基础知识-js(一)个人学习记录