QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#257984#7585. TDLddl_VS_pigeon#AC ✓97ms3820kbC++17877b2023-11-19 14:10:462023-11-19 14:10:47

Judging History

你现在查看的是最新测评结果

  • [2023-11-19 14:10:47]
  • 评测
  • 测评结果:AC
  • 用时:97ms
  • 内存:3820kb
  • [2023-11-19 14:10:46]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

const int lmt = 800;

bool check(ll n, ll m, ll k) {
    int cnt = 0;
    for (int d=1;d<=lmt;d++) {
        if (gcd(n, d) == 1) {
            cnt += 1;
        }
        if (cnt == m) {
            if ((d^n) == k) return true;
            else return false;
        }
    }
    return false;
}
void solve() {
    ll k, m;
    cin>>k>>m;
    
    ll ans = 8e18;
    for (ll d=1;d<=lmt;d++) {
        ll n = (k^d);
        if (check(n, m, k)) {
            ans = min(ans, n);
        }
    }
    if (ans > 7e18) {
        printf("%d\n", -1);
    }else{
        printf("%lld\n", ans);
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 3816kb

input:

2
3 5
6 100

output:

5
-1

result:

ok 2 number(s): "5 -1"

Test #2:

score: 0
Accepted
time: 97ms
memory: 3820kb

input:

10
525775438567843653 99
682312746347646949 100
928247462368723598 89
389467864734767741 77
734712353456789580 91
928574865348354786 95
56042586089579521 93
614889782588491751 60
614889782588490923 90
614889782588491001 100

output:

-1
682312746347646754
928247462368723467
389467864734767645
734712353456789527
928574865348354669
56042586089579704
614889782588491410
614889782588490776
614889782588490814

result:

ok 10 numbers