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. 一个sql和C#代码结合的分组求和的查询

    业务描述:  业务主表(tab_main 主键 id), 供应商名称(supplier), 金额(amount 需要统计求和),还有分类( 有单独的表categoryid),集中采购标记字段(tend ...

  2. BalticOI 2004 Sequence 题解

    题目链接在这里~ 对于序列\(\{a\}\),把每一个\(a_i\)减去一个\(i\),得到\(\{a'\}\)序列\(\{b\}\)同理. 因为\(b_1<b_2<...<b_n\ ...

  3. (6)go-micro微服务consul配置、注册中心

    目录 一 Consul介绍 1. 注册中心Consul基本介绍 2.注册中心Consul关键功能 3.注册中心Consul两个重要协议 二 Consul安装 1.使用docker拉取镜像 三 Conf ...

  4. Java用户交互方法——Scanner

    Scanner用户交互 使用Next方法接收 Scanner scanner = new Scanner(System.in); if(scanner.hasNext()){//判断用户有无输入 St ...

  5. SICTF_wp

    misc 签到打卡完成 附加下载完成之后可以看到是qsnctf的公众号 使用010打开附件 可以发现key,去公众号回复key即可获得flag SICTF{fb23cefd-487f-42dd-a34 ...

  6. ionic+vue+capacitor系列笔记--capacitor3.X和2.X+android自定义capacitor的JSbridge插件注册与使用(不同版本注册方式不同,返回值格式也不同,使用方法也不同)

    经过我的多番折腾,终于搞明白了这个东西的用法,不同版本的注册方法,使用方法都不一样,现在把这个折腾的结果记录下来,造福大家~ 首先编写一个类,然后注册,注意,这个和2.x不一样,2.x的时候我们会使用 ...

  7. angular8实现前端携带cookie发送给后端+nodejs获取前端发送的cookie

    1.前端测试代码angular8 // 测试代码 testCookie() { const url = 'http://10.11.11.11:3000/test/cookie' const para ...

  8. FLASH-CH32F203替换CH32F103 FLASH快速编程移植说明

    因CH32F203 相对于CH32F103 flash操作的快速编程模式由单次128字节编程变成了单次256字节编程,该文档说明主要目的是为了方便客户在原先CH32F103工程的基础上实现flash ...

  9. 线程基础知识-CountDownLatch

    转:https://blog.csdn.net/hbtj_1216/article/details/109655995 1 概念1.1 简介 CountDownLatch是一个同步工具类,它允许一个或 ...

  10. Solon2 开发之插件,二、插件扩展机制(Spi)

    插件扩展机制,是基于 "插件" + "配置申明" 实现的解耦的扩展机制(类似 Spring Factories.Java Spi):简单.弹性.自由.它的核心作 ...