結果

問題 No.1895 Mod 2
ユーザー 蜜蜂蜜蜂
提出日時 2022-04-08 22:32:41
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,678 bytes
コンパイル時間 1,791 ms
コンパイル使用メモリ 173,200 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-05-06 08:03:46
合計ジャッジ時間 2,728 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 18 ms
5,376 KB
testcase_02 AC 19 ms
5,376 KB
testcase_03 AC 29 ms
5,376 KB
testcase_04 AC 29 ms
5,376 KB
testcase_05 AC 30 ms
5,376 KB
testcase_06 AC 31 ms
5,376 KB
testcase_07 AC 31 ms
5,376 KB
testcase_08 AC 24 ms
5,376 KB
testcase_09 AC 26 ms
5,376 KB
testcase_10 AC 20 ms
5,376 KB
testcase_11 AC 28 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//g++ 1.cpp -std=c++14 -O2 -I .
#include <bits/stdc++.h>
using namespace std;

#include <atcoder/math>
#include <atcoder/modint>
using namespace atcoder;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())

// [a,b]
ll sub(ll a,ll b){
  if(a>b)return 0;

  if(a==b){
    while(a%2==0)a/=2;
    ll sq=sqrt(a);
    rep(i,sq-10,sq+10){
      if(i*i==a){
        return 1;
      }
    }
    return 0;
  }


  ll mineven=a+a%2;
  ll maxeven=b-b%2;
  mineven/=2,maxeven/=2;
  ll res=sub(mineven,maxeven);

  ll p=sqrt(a);
  p+=10;
  while(true){
    if(p*p<a){
      p++;
      break;
    }
    p--;
  }

  ll q=sqrt(b);
  q+=10;
  while(true){
    if(q*q<=b){
      break;
    }
    q--;
  }

  /*
  p以上q以下奇数いくつ
  p+1以上q+1以下偶数いくつ
  */

  res+=(q+1)/2-p/2;
  return res%2;
}

void solve(){
  /*
  /=2をしまくる
  平方数の時 -> 奇数
  そうでない時 -> 偶数
  */

  ll l,r;
  cin>>l>>r;
  cout<<sub(l,r)<<endl;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int t;
  cin>>t;

  while(t--){
    solve();
  }
}
0