[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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值