首页 > 其他分享 >1055. Combinations

1055. Combinations

时间:2023-01-03 15:35:07浏览次数:43  
标签:haricot 1055 ladle seeds Combinations pan quantity

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

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

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

               

标签:haricot,1055,ladle,seeds,Combinations,pan,quantity
From: https://www.cnblogs.com/rabbit-fan/p/17022356.html

相关文章

  • 1055. 股票买卖 II
    贪心模板题思考这题之前,首先需要明确一点:对于任何买卖操作,即便跨了n天也是一样,都可以拆分成如图的形式{(at,at+1),(at2,at2+1)....,(atk,atk+1)},这样的集合,即可以拆......
  • [Typescript] 64. Hard - AllCombinations
    Implementtype AllCombinations<S> thatreturnallcombinationsofstringswhichusecharactersfrom S atmostonce.Forexample:typeAllCombinations_ABC=......
  • MySQL5.7及以上版本:1055错误解决
    今天在迁移数据库到服务器,再运行本地的查询语句时出现1055错误。该错误是关于groupby的,原因是MySql5.7以上,sql_mode中的“only_full_group_by”是默认开启的解决方案......
  • T1055 判断闰年 (信息学一本通C++)
     目录 [题目描述]判断某年是否是闰年。如果公元a年是闰年输出Y,否则输出N。[输入]输入只有一行,包含一个整数a(0<a<3000)。[输出]一行,如果公元a年是闰年输出Y,......