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

    )

  • 相关阅读:
    视频学习网站
    保存文章
    maven常见命令总结
    Eclipse vs IDEA快捷键对比大全(win系统)
    JS调用android逻辑方法
    【原创】不用封装jar包 直接引入工程使用的方法(类似android的 is Library功能)
    windows下eclipse+hadoop2
    Solaris用户管理(一):用户与组管理
    jquery 操作 checkbox
    模拟用户登录的操作
  • 原文地址:https://www.cnblogs.com/yzxqq/p/11329620.html
Copyright © 2020-2023  润新知