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. cmd窗口中java命令报错。错误:找不到或无法加载主类 java的jdk安装过程中踩过的坑

    错误: 找不到或无法加载主类 HelloWorld 遇到这个问题时,我尝试过网上其他人的做法.有试过添加classpath,也有试过删除classpath.但是依然报错,这里javac可以编译通过,说 ...

  2. [OpenCV实战]39 在OpenCV中使用ArUco标记的增强现实

    文章目录 1 什么是ArUco标记? 2 在OpenCV中生成ArUco标记 3 检测Aruco标记 4 增强现实应用 5 总结和代码 5.1 生成aruco标记 5.2 使用aruco增强现实 6 ...

  3. MongoDB - 分片简介

    简介 什么是分片 高数据量和高吞吐量的数据库应用会对单机的性能造成较大压力,大的查询会将单机的 CPU 耗尽,大的数据量对单机的存储压力较大,最终会耗尽系统的内存压力转移到磁盘 IO 上. 为了解决这 ...

  4. [cocos2d-x]从源码角度思考convertToWorldSpace()与convertToWorldSpaceAR()坐标系的转换

    convertToWorldSpace() 话不多说,先上源码,之后再慢慢讲解: (5和6图截图的时候重复了,这里就不弄出来了) 只要通过图1到图8中我写的注释进行分析(不懂的地方可以自己去翻一下co ...

  5. P5687 [CSP-S2019 江西] 网格图

    题面 给定一个 \(n\times m\) 的网格图,行从 \(1\sim n\) 编号,列从 \(1\sim m\) 编号,每个点可用它所在的行编号 \(r\) 与所在的列编号 \(c\) 表示为 ...

  6. liunx系统安装Redis详细步骤

    liunx系统安装Redis详细步骤 官网下载Redis安装包 使用工具将redis安装包拖入liunx系统 创建Redis存放目录 mkdir /usr/local/redis 解压到redis存放 ...

  7. ajax 用 get方法 验证登录

    get-login-ajax.html --------------------------------------------- <body> <input type=" ...

  8. linux命令与公私钥

    昨日内容回顾 etc目录 配置相关 /etc/profile 环境变量文件 /etc/motd 开机欢迎界面 usr目录 程序相关 四种安装软件的方式 1.yum安装 自动解决依赖性问题 2.rap安 ...

  9. django框架之drf:3、API执行流程、Response源码剖析、序列化器的简介和使用、反序列化的校验

    Django框架之drf 目录 Django框架之drf 一.APIView执行流程 1.API执行流程总结(重点) 2.补充 二.Response源码剖析 1.Response类总结(重点) 三.序 ...

  10. 大三末java实习生一面凉经

    在南京投了一些小公司,想找个实习,因为知道自己很菜,就收到了一家公司的面试. 面试一般在线上进行,我是在腾讯会议上进行的.面试官其实挺好的,一般不会为难你,因为他知道你是在校生不会懂那么多企业的技术. ...