結果

問題 No.1895 Mod 2
ユーザー ゆにぽけゆにぽけ
提出日時 2024-03-20 21:03:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 1,540 bytes
コンパイル時間 1,371 ms
コンパイル使用メモリ 133,168 KB
実行使用メモリ 6,548 KB
最終ジャッジ日時 2024-03-20 21:03:46
合計ジャッジ時間 3,708 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 67 ms
6,548 KB
testcase_02 AC 86 ms
6,548 KB
testcase_03 AC 58 ms
6,548 KB
testcase_04 AC 59 ms
6,548 KB
testcase_05 AC 135 ms
6,548 KB
testcase_06 AC 108 ms
6,548 KB
testcase_07 AC 108 ms
6,548 KB
testcase_08 AC 61 ms
6,548 KB
testcase_09 AC 60 ms
6,548 KB
testcase_10 AC 32 ms
6,548 KB
testcase_11 AC 72 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <array>
#include <iterator>
#include <string>
#include <cctype>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <cmath>
#include <ctime>
#include <iomanip>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <random>
#include <utility>
#include <functional>
using namespace std;
vector<long long> Divisors(long long N)
{
	vector<long long> res;
	for(long long i = 1;i * i <= N;i++)
	{
		if(N % i == 0)
		{
			res.push_back(i);
			if(i != N / i) res.push_back(N / i);
		}
	}

	sort(res.begin(),res.end());

	return res;
}

int f(long long x)
{
	int ans = 0;
	while(x)
	{
		int ok = 1,ng = (int)1e8;
		while(ng - ok > 1)
		{
			int mid = (ok + ng) / 2;
			if((long long) mid * mid <= x)
			{
				ok = mid;
			}
			else
			{
				ng = mid;
			}
		}
		ans ^= (((ok - 1) / 2 + 1) & 1);
		x >>= 1;
	}
	return ans;
}
int g(long long x)
{
	int ans = 0;
	for(long long d : Divisors(x))
	{
		if(d & 1)
		{
			ans ^= 1;
		}
	}
	return ans;
}
void Main()
{
	/* int N; */
	/* cin >> N; */
	/* for(int i = 1;i <= N;i++) */
	/* { */
	/* 	/1* cout << g(i) << (i == N ? "\n":""); *1/ */
	/* 	if(g(i)) */
	/* 	{ */
	/* 		cout << i << " " << i / (i & -i) << "\n"; */
	/* 	} */
	/* } */
	long long L,R;
	cin >> L >> R;
	cout << (f(R) ^ f(L - 1)) << "\n";
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	cin >> tt;
	while(tt--) Main();
}
0