无关的元素

#include <bits/stdc++.h>
using namespace std;
//无关的元素.png
//算法入门经典
// 组合数Cmn很大,很有可能溢出,真的非常大,类似于n!,即使longlong也存不下
// 在这种情况下 可以考虑 用组合数递推公式,这样从1开始每次对(n-k+1)/k进行素因子分解然后累加,
//就得到了每个的分解结果,但是要注意(n-k+1)/k可能<1所以还要分情况,
//在<1时只能把分母的值用已经得到的上次的C值消去,肯定可以消去
int n,m;
map<int,int> yinzi;//m的素因子及其个数
void fenjie(){
    int i=2,x=m,s=0;
    while(x>1){
        while(x%i==0){
            x=x/i;
            s++;
        }
        if(x%i!=0){
            if(s!=0){
                yinzi.insert(make_pair(i,s));
                cout<<i<<" "<<s<<endl;
            }
            s=0;
            i++;
        }
    }
}
int main()
{   
    // //m>=2,所以a1 an都不行
    // while(cin>>n>>m){
    //     yinzi.clear();
    //     fenjie();
    //     int oks=0,p[yinzi.size()]={0},flg=1,index;
    //     memset(p,0,sizeof(p));
    //     for(int i=1;i<n-1;i++){
    //         int k;
    //         if(n-i<i) {flg=-1;k=i/(n-i);}
    //         else k=(n-i)/i;
    //         index=0;
    //         cout<<k<<endl;
    //         for(map<int,int>::iterator it=yinzi.begin();it!=yinzi.end();it++){
    //             // cout<<it->first<<endl;
    //             while(k%(it->first)==0){
    //                 k=k/(it->first);
    //                 p[index]+=flg;
    //                 if(p[index]==it->second){
    //                     oks+=flg;
    //                 }
    //             }
    //             // cout<<p[index]<<endl;
    //             index++;
    //         }
    //         // cout<<oks<<endl;
    //         for(int pp=0;pp<5;pp++) cout<<p[pp]<<" ";cout<<endl;
    //         if(oks==yinzi.size()) cout<<"a"<<i+1<<" ";
    //     }
    //     cout<<endl;
    // }
    return 0;
}

 

posted @ 2020-06-06 21:22  西伯利亚挖土豆  阅读(157)  评论(0编辑  收藏  举报