zoukankan      html  css  js  c++  java
  • TDL HDU

    题面:

    For a positive integer nn, let's denote function f(n,m)f(n,m) as the mm-th smallest integer xx that x>nx>n and gcd(x,n)=1gcd(x,n)=1. For example, f(5,1)=6f(5,1)=6 and f(5,5)=11f(5,5)=11. 

    You are given the value of mm and (f(n,m)n)n(f(n,m)−n)⊕n, where ``⊕'' denotes the bitwise XOR operation. Please write a program to find the smallest positive integer nn that (f(n,m)n)n=k(f(n,m)−n)⊕n=k, or determine it is impossible.

    题意:

    fn,m)表示比n大的,第m个与n互质的数。给出nkk=(f(n,m)-n)^n。问n是最小值。m最大为100

    思路:

    可以想到f(n,m)并不会比n大太多,所以我们可以枚举f(n,m)-n

    对于每一个i,通过n=i^k,求出当前的n,然后再判断n+i是否恰好是n的第m个互质数(此处不可以判n+i内是否有m个与n互质的数当答案)。

    要点:

    对于我们枚举的上界。gcd(n+k,n)=gcd(n,k)=gcd(k,n%k),由于在1~k内至少有k/lgk个素数,所以nn+k内至少有k/lgk个与n互质的数。

    所以上界up=700(up/lgup>100

    #include<bits/stdc++.h>
    using namespace std;
    #define ll long long
    ll k,m,n,key,i;
    bool  check()
    {
        ll s=0,j=1;
        for(;; j++)
        {
            if(__gcd(n,n+j)==1)s++;
            if(s==m) break;
        }
        return j==i;
    }
    int main()
    {
        int T;
        cin>>T;
        while(T--)
        {
            cin>>k>>m;
            ll ans=-1;
            for( i=1; i<700; i++)
            {
                n=k^i;
                if(n>=2&&check())
                {
                    if(ans==-1)ans=n;
                    else ans=min(n,ans);
                }
            }
            cout<<ans<<endl;
    
        }
        return 0;
    }

    )

  • 相关阅读:
    【题解】Luogu P4391 [BOI2009]Radio Transmission 无线传输
    kmp匹配详解
    点分治详解
    【题解】Luogu P3871 [TJOI2010]中位数
    树链剖分详解
    【题解】Luogu P3901 数列找不同
    【题解】Luogu P1503 鬼子进村
    【题解】 P2234 [HNOI2002]营业额统计
    Splay详解
    JSOI2020备考知识点复习
  • 原文地址:https://www.cnblogs.com/yzxqq/p/11329620.html
Copyright © 2011-2022 走看看