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++进阶(哈希)

    vector容器补充(下面会用到) 我们都知道vector容器不同于数组,能够进行动态扩容,其底层原理:所谓动态扩容,并不是在原空间之后接续新空间,因为无法保证原空间之后尚有可配置的空间.而是以原大小 ...

  2. NC14501 大吉大利,晚上吃鸡!

    题目链接 题目 题目描述 最近<绝地求生:大逃杀>风靡全球,皮皮和毛毛也迷上了这款游戏,他们经常组队玩这款游戏. 在游戏中,皮皮和毛毛最喜欢做的事情就是堵桥,每每有一个好时机都能收到不少的 ...

  3. dinic及当前弧优化

    网络流 dinic及当前弧优化 前言 dinic比较适合学习完km之后再学习.因为dinic感觉像是km的一种优化.总之难度不是特别大 dinic算法 好了,言归正传.先分析一下km为什么效率低下?因 ...

  4. 数据预处理时为什么要使用OneHot编码?

    什么是LabelEncoder(整数编码) 整数编码 将一列文本数据转化成数值,即列中的每一个特征都通过一个整数来表示.例如,[red, blue, red, yellow] = [0,2,0,1]. ...

  5. ionic+vue+capacitor系列笔记--01项目初始化

    Ionic 是什么? Ionic 是一款接近原生的 Html5 移动 App 开发框架,只需要你会 HTML.CSS 和 JavaScript 就可以开发移动 App应用,使用最基础的 Web 技术创 ...

  6. axios 使用方法 以及服务器端 设置拦截发送404状态的提示语,当网络错误时候返回前端的提示, 当网络正常的时候返回后端的提示

    本文旨在说明  设置全局异常拦截器 当网络错误时候返回前端的提示, 当网络正常的时候返回后端的提示 export default ({ development: { baseURL: 'http:// ...

  7. 腾讯出品小程序自动化测试框架【Minium】系列(四)API详解(上)

    写在前面 不知道是不是因为之前出过书的原因,在写教程之类的文章,会潜意识有自带目录和章节的感觉在里面,有点说不出的感觉吧. 上篇文章我们介绍了关于元素定位的使用方法,这篇文章将为大家分享关于Miniu ...

  8. 分布式协议与算法-Quorum NWR

    1.强一致性与最终一致性 1.1强一致性 强一致性能保证写操作完成后,任何后续访问都能读到更新后的值:强一致性可以保证从库有与主库一致的数据.如果主库突然宕机,我们仍可以保证数据完整.但如果从库宕机或 ...

  9. vh 存在问题?试试动态视口单位之 dvh、svh、lvh

    大部分同学都知道,在 CSS 世界中,有 vw.vh.vmax.vmin 这几个与视口 Viewport 相关的单位. 正常而言: 1vw 等于1/100的视口宽度 (Viewport Width) ...

  10. drf-day7——认证组件、权限组件、频率组件、过滤排序、分页

    目录 一.认证组件 1.1 登录接口 1.2 认证组件使用步骤 1.3 整体代码 1.4认证时cookie的获取方式 二.权限组件 2.1需求分析: 2.2 权限的使用 2.3代码 三.频率组件 3. ...