[2019杭电多校第六场][hdu6641]TDL

时间:2019-08-20
本文章向大家介绍[2019杭电多校第六场][hdu6641]TDL,主要包括[2019杭电多校第六场][hdu6641]TDL使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6641

题意为求出最小的n,满足(f(n,m)-n)^n=k,其中f(n,m)为第m大的x,其中x满足gcd(x,n)==1且x>n。

可以将式子化成f(n,m)=k^n+n,然后我们会发现f(n,m)的范围大致会在(n+1,n+loglogn)之间,因为f(n,m)内最多会有m个质数,质数的密度。

所以可以枚举k^n,k^n^k=n。

#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {
    return (b == 0 ? a : gcd(b, a% b));
}
ll f(ll n, ll m) {
    ll ans = n;
    while (m) {
        ans++;
        if (gcd(ans, n) == 1)
            m--;

    }
    return ans;
}
int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        ll k, m;
        scanf("%lld%lld", &k, &m);
        ll ans = -1;
        for (ll i = m; i <= 500; i++) {
            ll n = i ^ k;
            if (f(n, m) == i + n) {
                if (ans == -1)ans = n;
                else ans = min(ans, n);
            }
        }
        cout << ans << endl;
    }
}

原文地址:https://www.cnblogs.com/sainsist/p/11385152.html