結果
問題 | No.1895 Mod 2 |
ユーザー |
![]() |
提出日時 | 2022-04-08 22:02:05 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 38 ms / 2,000 ms |
コード長 | 2,285 bytes |
コンパイル時間 | 1,010 ms |
コンパイル使用メモリ | 114,344 KB |
最終ジャッジ日時 | 2025-01-28 16:08:36 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 11 |
ソースコード
#include <iostream> #include <algorithm> #include <iomanip> #include <vector> #include <queue> #include <deque> #include <set> #include <map> #include <tuple> #include <cmath> #include <numeric> #include <functional> #include <cassert> #define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl; #define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } using namespace std; typedef long long ll; template<typename T> vector<vector<T>> vec2d(int n, int m, T v){ return vector<vector<T>>(n, vector<T>(m, v)); } template<typename T> vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){ return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v))); } template<typename T> void print_vector(vector<T> v, char delimiter=' '){ if(v.empty()) { cout << endl; return; } for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter; cout << v.back() << endl; } /** * y*y <= xを満たす最大の非負整数yを返します */ long long floor_sqrt(long long x){ long long sq = sqrt(x)+0.1; if(sq*sq > x) sq--; return sq; } ll sub_solve(ll l, ll r){ // cout << l << ':' << r << endl; if(l > r) return 0; if(l == r && l%2 == 1){ ll sq = floor_sqrt(l); if(sq*sq == l){ return 1; }else{ return 0; } } ll sl = floor_sqrt(l); if(sl*sl < l) sl++; ll sr = floor_sqrt(r); // cout << sl << ' ' << sr << endl; if(sl%2 == 0) sl++; if(sr%2 == 1) sr++; ll ans = 0; if(sr >= sl+1){ ans += (sr-sl+1)/2; } ll l1 = (l+1)/2; ll r1 = r/2; ans += sub_solve(l1, r1); ans %= 2; return ans; } void solve(){ ll l, r; cin >> l >> r; cout << sub_solve(l, r) << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; int t; cin >> t; while(t--) solve(); // debug_value(sub_solve(1, 4)); // cout << sub_solve(1, 4) << endl; // cout << sub_solve(2, 5) << endl; }