QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#300195#7585. TDLI_Love_Sonechka#AC ✓57ms3452kbC++141.9kb2024-01-07 20:48:382024-01-07 20:48:38

Judging History

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

  • [2024-01-07 20:48:38]
  • 评测
  • 测评结果:AC
  • 用时:57ms
  • 内存:3452kb
  • [2024-01-07 20:48:38]
  • 提交

answer

#include <bits/stdc++.h>
#include <math.h>

//#pragma GCC optimize("O3,unroll-loops")

using namespace std;
	
#ifndef ONLINE_JUDGE
	#define _GLIBCXX_DEBUG
	#define local_shit freopen("inp.txt", "r", stdin); freopen("out.txt", "w", stdout);
#else
	#define local_shit
#endif
		
// io macros
#define fastio ios::sync_with_stdio(false); cin.tie(nullptr);
#define make_test_shit freopen("inp.txt", "w", stdout);

// c++ short types
#define Int long long
#define vt vector
#define pi pair<int, int>

// code macros
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ins insert
#define mp make_pair

// loops macros
#define each(x, a) for(auto &x: a)

// some functions
template<typename T>
void umax(T &a, const T &b) { a = max(a,b); }
template<typename T>
void umin(T &a, const T &b) { a = min(a,b); }
void whattime() { cout << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl; }
template<typename T>
T firsttrue(T l, T r, function<bool(T)> f) {
	while(r - l > 1) {
		T m = (l+r)/2;
		if(f(m)) {
			r = m;
		} else {
			l = m;
		}
	}
	return r;
}
template<typename T>
T lasttrue(T l, T r, function<bool(T)> f) {
	while(r - l > 1) {
		T m = (l+r)/2;
		if(f(m)) {
			l = m;
		} else {
			r = m;
		}
	}
	return l;
}

long long gcd(long long a, long long b) {
	while(b) {
		b = a % b; swap(a,b);
	}
	return a;
}

void solver() {
	long long k, m; cin >> k >> m;
	long long res = -1;
	for(long long d = 0; d <= 1000; ++d) {
		long long n = k ^ d;
		int ord = 0;
		for(long long i = 0; i <= 1e4; ++i) {
			ord += __gcd(i,n) == 1;
			if(ord == m) {
				if(i == d) {
					if(res == -1) {
						res = n;
					}
					umin(res, n);
				}
				break;
			}
		}
	}
	cout << res << '\n';
}

int main()
{
	fastio;
	int tt = 1;
	cin >> tt;
	for(int t = 0; t < tt; ++t) {
    solver();
	}
	//whattime();
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 6ms
memory: 3444kb

input:

2
3 5
6 100

output:

5
-1

result:

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

Test #2:

score: 0
Accepted
time: 57ms
memory: 3452kb

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