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. 使用idea进行gitee代码管理

    目录 1.在idea插件市场安装gitee插件 2.把本地仓库的release分支上的代码合到dev分支上 3.把本地dev分支上的代码合到远程dev分支上去 1.在idea插件市场安装gitee插件 ...

  2. P8340 [AHOI2022] 山河重整

    \(20pts\) 给 \(O(2^n)\) 枚举,\(60pts\) 是 \(O(n^2)\),先看看怎么做.计数题无非容斥和 \(dp\),不妨从 \(dp\) 入手.多项式复杂度的做法意味着无法 ...

  3. [C++]模版特例化和模版偏特化

    函数模版特例化 例子: //第一个版本;可以比较任意两个类型 template<typename T> int compare(const &T,const T&); // ...

  4. python利用matplotlib生成迷宫

    起因 我想要写一个项目叫python迷宫游戏,需求是玩家能和机器对抗率先走出迷宫,至少要有两个等级的电脑. 慢慢来,首先迷宫游戏需要有一个迷宫并展示出来,这便是这篇博客的目的 假设迷宫使用0表示点,1 ...

  5. Apache RocketMQ 5.0 笔记

    RocketMQ 5.0:云原生"消息.事件.流"实时数据处理平台,覆盖云边端一体化数据处理场景. 核心特性 云原生:生与云,长与云,无限弹性扩缩,K8s友好 高吞吐:万亿级吞吐保 ...

  6. java 入门与进阶P-6.3+P-6.4

    包裹类型 对于基本数据类型,Java提供了对应的包裹(wrap)类型.这些包裹类型将一个基本数据类型的数据转换成对象的形式,从而使得它们可以像对象一样参与运算和传递.下表列出了基本数据类型所对应的包裹 ...

  7. Array list练习

    Array list练习 数据添加到集合 生成6个1~33之间的随机整数,添加到集合,并遍历 public class Test01ArrayList { public static void mai ...

  8. 定时调度插件------Longbow.Tasks

    官网地址Longbow.Tasks 使用说明 dll引用 使用NuGet 搜索Longbow.Task可找到相关版本的dll 目前最新的为7.0.0版本,需net6.0+ 如果低版本用户可使用5.2. ...

  9. Grafana 系列文章(十五):Exemplars

    Exemplars 简介 Exemplar 是用一个特定的 trace,代表在给定时间间隔内的度量.Metrics 擅长给你一个系统的综合视图,而 traces 给你一个单一请求的细粒度视图:Exem ...

  10. 关闭Vim 的蜂鸣 | 解决Vim在Git BASH闪砾的问题

    set vb t_vb= 这个设置屏蔽了vim遇到无效命令时发出的蜂鸣声,而用一个快速的闪烁取而代之.