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;
}

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

 
 
 
 
 
 
 
 

1055. Combinations的更多相关文章

  1. Combinations

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

  2. [LeetCode] Factor Combinations 因子组合

    Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a func ...

  3. [LeetCode] Combinations 组合项

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

  4. [LeetCode] Letter Combinations of a Phone Number 电话号码的字母组合

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  5. Leetcode 254. Factor Combinations

    Numbers can be regarded as product of its factors. For example, 8 = 2 x 2 x 2; = 2 x 4. Write a func ...

  6. 17. Letter Combinations of a Phone Number

    题目: Given a digit string, return all possible letter combinations that the number could represent. A ...

  7. LeetCode——Letter Combinations of a Phone Number

    Given a digit string, return all possible letter combinations that the number could represent. A map ...

  8. Combination Sum II Combinations

    https://leetcode.com/problems/combination-sum-ii/ 题目跟前面几道题很类似,直接写代码: class Solution { public: vector ...

  9. No.017:Letter Combinations of a Phone Number

    问题: Given a digit string, return all possible letter combinations that the number could represent.A ...

  10. Leetcode 77, Combinations

    Given two integers n and k, return all possible combinations of k numbers out of 1 ... n. For exampl ...

随机推荐

  1. 【c#】从外部复制文本、图片到我的软件中的解决方案(支持ppt,qq等)

    原文地址 https://www.cnblogs.com/younShieh/p/17010572.html 如果本文对你有所帮助,不妨点个关注和推荐呀,这是对笔者最大的支持~       我们先考虑 ...

  2. [cocos2d-x]关于Action

    Action的分类 第一种:FiniteTimeAction类:有限时间的动作类 第二种:Follow类:节点跟随另一种节点的类 第三种:Speed类:节点执行速度类 第一种有限时间的动作类又分为瞬时 ...

  3. sikulix___自动化办公___重复性_机械性_的电脑操作___python脚本___Java运行环境下德jar包完成自动化测试相关___截图编程控制键盘鼠标

    sikulix___自动化办公___重复性_机械性_的电脑操作___python脚本___Java运行环境下德jar包完成自动化测试相关___截图编程控制键盘鼠标 应用场景: 公司内的大佬更改了xml ...

  4. 大公司为什么禁止SpringBoot项目使用Tomcat?

    本文已经收录到Github仓库,该仓库包含计算机基础.Java基础.多线程.JVM.数据库.Redis.Spring.Mybatis.SpringMVC.SpringBoot.分布式.微服务.设计模式 ...

  5. 【原创】项目六 Load Of The Root

    实战流程 新创建文件夹,在这个文件夹里进行操作 nmap扫描下网段 根据nmap逐个排查,发现目标主机,但只有22端口 因此进一步扫描22端口的具体信息,没有扫出很有用的信息 发现靶场又提示一个用户, ...

  6. 字符编码,存储引擎及MySQL字段类型相关知识点

    字符编码,存储引擎及MySQL字段类型相关知识点 一.字符编码 1.在终端输入\s,查看数据库的基本信息(当前用户,版本,编码,端口号) 2.默认的配置文件是my-default.ini 拷贝上述的文 ...

  7. 自定义接口-lambda使用前提

    自定义接口 lambda使用前提 可推导即可省略 Lambda强调的是"做什么"而不是"怎么做",所以凡是可以根据上下文推导得知的信息,都可以省略.例如上例还可 ...

  8. Vue12 监视属性

    1 简介 所谓监听就是对内置对象的状态或者属性变化进行监听并且做出反应的响应,监听属性,意思就是可以监视其他数据的变化 2 使用 使用watch配置项,在配置项里面写上要监视的属性,每次属性值的变化都 ...

  9. spring-in-action_day02

       开发web应用 # 开发Spring web应用,最基本的需要构建以下组件: 1.pojo类(从数据库获取数据) 2.pringmvc控制器 3.视图模板(页面) ##第一步 构建pojo类 p ...

  10. P1_Day1.学习目标

    目标 能够知道如何创建小程序项目 能够清楚小程序项目的基本组成结构 能够知道小程序页面由几个部分组成 能够知道小程序中常见的组件如何使用 能够知道小程序如何进行协同开发和发布 学习目录 小程序简介 第 ...