結果

問題 No.1895 Mod 2
ユーザー milanis48663220milanis48663220
提出日時 2022-04-08 22:02:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 26 ms / 2,000 ms
コード長 2,285 bytes
コンパイル時間 1,190 ms
コンパイル使用メモリ 115,972 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-19 00:37:05
合計ジャッジ時間 2,264 ms
ジャッジサーバーID
(参考情報)
judge15 / judge9
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 17 ms
4,376 KB
testcase_02 AC 19 ms
4,376 KB
testcase_03 AC 23 ms
4,376 KB
testcase_04 AC 23 ms
4,380 KB
testcase_05 AC 25 ms
4,380 KB
testcase_06 AC 25 ms
4,500 KB
testcase_07 AC 26 ms
4,380 KB
testcase_08 AC 21 ms
4,380 KB
testcase_09 AC 22 ms
4,380 KB
testcase_10 AC 18 ms
4,376 KB
testcase_11 AC 23 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0