結果

問題 No.1895 Mod 2
ユーザー 👑 ygussanyygussany
提出日時 2022-03-20 10:07:02
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 97 ms / 2,000 ms
コード長 772 bytes
コンパイル時間 1,195 ms
コンパイル使用メモリ 28,328 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-18 18:58:35
合計ジャッジ時間 2,236 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 57 ms
4,376 KB
testcase_02 AC 63 ms
4,376 KB
testcase_03 AC 68 ms
4,376 KB
testcase_04 AC 49 ms
4,376 KB
testcase_05 AC 92 ms
4,380 KB
testcase_06 AC 97 ms
4,376 KB
testcase_07 AC 97 ms
4,380 KB
testcase_08 AC 49 ms
4,376 KB
testcase_09 AC 55 ms
4,376 KB
testcase_10 AC 21 ms
4,376 KB
testcase_11 AC 65 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

long long solve(long long L, long long R)
{
	long long ans = 0, l[2], r[2], m, b, LL, RR;
	for (b = 1; b <= R; b <<= 1) {
		LL = (L + b - 1) / b;
		RR = R / b;
		l[0] = 0;
		r[0] = 1 << 25;
		while (l[0] < r[0]) {
			m = (l[0] + r[0]) / 2;
			if (m * m >= LL) r[0] = m;
			else l[0] = m + 1;
		}
		l[1] = 0;
		r[1] = 1 << 25;
		while (l[1] < r[1]) {
			m = (l[1] + r[1] + 1) / 2;
			if (m * m <= RR) l[1] = m;
			else r[1] = m - 1;
		}
		if (l[0] % 2 == 0) l[0]++;
		if (l[1] % 2 == 0) l[1]--;
		if (l[0] <= l[1]) ans += (l[1] - l[0]) / 2 + 1;
	}
	return ans;
}

int main()
{
	int i, t, T;
	long long L, R;
	scanf("%d", &T);
	for (t = 1; t <= T; t++) {
		scanf("%lld %lld", &L, &R);
		printf("%lld\n", solve(L, R) % 2);
	}
	fflush(stdout);
	return 0;
}
0