zoukankan      html  css  js  c++  java
  • 容斥原理

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    const int N = 1e6 + 7;
    int a[N];
    LL ans,all;

    void dfs(int x, LL y){
        if(x>a[0]){ans+=all/y; return;}
        dfs(x+1,y); dfs(x+1,-y*a[x]);
    }

    LL count(LL x){
        ans=0,all=x;
        dfs(1,1);
        return ans;
    }

    int main(){
        int m,k;
        while(!cin.eof()){
            cin>>m>>k;
            a[0]=0;
            for(int i=2;i*i<=m;++i)
                if(m%i==0){
                    a[++a[0]]=i;
                    for(;m%i==0;m/=i);
                }
            if(m>1)a[++a[0]]=m;
            LL l=1,r=1e18,mid;
            for(;l<=r;){
                mid=(l+r)>>1;
                if(count(mid)>=k)r=mid-1;
                else l=mid+1;
            }
            cout<<l<<endl;
        }
        return 0;
    }

  • 相关阅读:
    hdu 1296
    hdu 2101
    hdu 2100
    codeforces 3C
    codeforces 2A
    codeforces 1B
    codeforces 811B
    关于sws_scale() 段错误
    cf 1288 D. Minimax Problem (好题)(二分+二进制表状态+枚举)
    opencv4 鼠标事件 鼠标画线条
  • 原文地址:https://www.cnblogs.com/codetogether/p/7213829.html
Copyright © 2011-2022 走看看