zoukankan      html  css  js  c++  java
  • hdu多校第六场1008 (hdu6641)TDL 暴力

    题意:

    设f(n,m)为比n大的第m个和n互质的数,给定一个k=(f(n,m)-n)xor n和m,求最小的n

    题解:

    对于给定的m而言,一个k周围合法的n分布的很密,因此在k的邻域暴力搜索即可。

    #include<iostream>
    #define LL long long
    using namespace std;
    LL gcd(LL a,LL b){
        return b==0?a:gcd(b,a%b);
    } 
    bool solve(LL n,LL k,int m){
        //找到n后面的第m个互质
        register LL i;
        for(i=n+1;;i++){
            if(gcd(i,n)==1)m--;
            if(m==0)break;
        } 
        if(((i-n)^n)==k){
    //        printf("%lld",i);
            return 1;
        }
        else return 0;
    }
    int main(){
        int t;
        scanf("%d",&t);
        while(t--){
            LL k;
            int m;
            scanf("%lld %d",&k,&m);
            for(register LL i=max(1ll,k-3000);i<=k+3000;i++){
                if(solve(i,k,m)){
                    printf("%lld
    ",i);
                    goto A;
                }
            }
            printf("-1
    ");
            A:;
        }
    }
  • 相关阅读:
    xutils 上传文件 ,暂时
    UIView.FRAMEWORK
    2016.11.7
    2016.11.6新阶段开始
    远程推送
    xcode8 导入 dylib
    bugly使用
    anelife
    心阶段
    新阶段
  • 原文地址:https://www.cnblogs.com/isakovsky/p/11321685.html
Copyright © 2011-2022 走看看