QOJ.ac

QOJ

IDSubmission IDProblemHackerOwnerResultSubmit timeJudge time
#1065#671832#21686. 【NOIP Round #2】恰钱max666dong123wth2026Failed.2024-10-24 16:02:092024-10-24 16:02:09

Details

Extra Test:

Accepted
time: 399ms
memory: 8964kb

input:

100000
176771879 555247693
120210120 191710048
244960703 538664353
920732290 977847565
20579938 48123050
325973596 381551844
909621500 934309036
106075145 593461812
774790808 972784063
234469234 917157806
49629984 301140663
35448263 855412618
824796858 890510727
620593334 728852619
354197478 4252172...

output:

176772608
120210944
244963328
920732672
20580096
325976576
909627392
106075648
774793216
234475520
49630208
35448320
824798208
620595200
354198016
245221376
135640576
71038976
169906560
800862208
337698304
62521600
581620736
852492416
730626048
750977280
645132288
319410688
576369664
240838656
49718...

result:

ok Accepted!

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#671832#21686. 【NOIP Round #2】恰钱wth2026100 ✓407ms9288kbC++141.5kb2024-10-24 14:37:342024-10-24 14:37:34

answer

#include <bits/stdc++.h>

#define endl '\n'
#define int long long
#define inf 0x3f3f3f3f
#define lnf 0x3f3f3f3f3f3f3f3f

const bool Debug = false;

//#define Debug true

using namespace std;

void input (int& x) {
	x = 0;
	char c = getchar ();
	
	while (! isdigit (c)) {
		c = getchar ();
	}
	
	while (isdigit (c)) {
		x = (x << 3) + (x << 1) + (c ^ 48);
		c = getchar ();
	}
}

void output (int x) {
	register char _Wrt[25], cnt = 0;
	
	do {
		_Wrt[++ cnt] = x % 10;
		x /= 10;
	} while (x);
	
	do {
		putchar (_Wrt[cnt] | 48);
		-- cnt;
	} while (cnt);
}

int lowbit (int x) {
	return x & -x;
}

int ppc (int x) {
	int _ = 0;
	
	while (x) {
		++ _;
		x -= lowbit (x);
	}
	
	return _;
}

int l, r;
int a[2] = {134217729, 100663297};
vector <int> ok;

signed main () {
//	freopen ("qiaqia.in", "r", stdin);
//	freopen ("qiaqia.out", "w", stdout);
	
	for (register int i = 1; i <= 1e8; ++ i) {
		if ((i & 1) && (i << ppc (i)) <= 1e9) {
			ok.push_back (i << ppc (i));
		}
	}
	
	for (register int i = 0; i < 2; ++ i) {
		ok.push_back (a[i] << ppc (a[i]));
	}
	
	sort (ok.begin (), ok.end ());
	
	if (Debug) {
		cout << ok.size () << endl;
	}
	
	int T;
	input (T);
	
	while (T --) {
		input (l);
		input (r);
		auto it = lower_bound (ok.begin (), ok.end (), l);
		
		if (it != ok.end () && (* it) <= r) {
			output (* it);
			putchar ('\n');
		} else {
			putchar ('-');
			putchar ('1');
			putchar ('\n');
		}
	}
	
	return 0;
}