結果

問題 No.1895 Mod 2
ユーザー ShirotsumeShirotsume
提出日時 2022-02-08 00:00:15
言語 Java21
(openjdk 21)
結果
AC  
実行時間 475 ms / 2,000 ms
コード長 864 bytes
コンパイル時間 2,919 ms
コンパイル使用メモリ 79,660 KB
実行使用メモリ 47,968 KB
最終ジャッジ日時 2024-05-06 00:46:02
合計ジャッジ時間 7,367 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 99 ms
39,844 KB
testcase_01 AC 417 ms
47,524 KB
testcase_02 AC 468 ms
47,384 KB
testcase_03 AC 419 ms
47,468 KB
testcase_04 AC 395 ms
47,524 KB
testcase_05 AC 458 ms
47,896 KB
testcase_06 AC 418 ms
46,652 KB
testcase_07 AC 475 ms
47,896 KB
testcase_08 AC 418 ms
47,624 KB
testcase_09 AC 454 ms
47,968 KB
testcase_10 AC 378 ms
47,660 KB
testcase_11 AC 435 ms
47,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
public class Main {
	  public static void main(String[] args) {
	        Scanner sc = new Scanner(System.in);
	        int t = sc.nextInt();
	        for(int i = 0; i < t; i++){
	        	long l, r;
	        	l = sc.nextLong();
	        	r = sc.nextLong();
	        	long ans = solve(r) - solve(l - 1);
	        	System.out.println(ans % 2);
	        }
	    }
	  public static long solve(long x){
		  if(x == 0) return 0;
		  long ok = 0;
		  long ng = 1000000000 + 1;
		  long mid;
		  long ans = 0;
		  while(Math.abs(ok - ng) > 1){
			  mid = (ok + ng) / 2;
			  if (mid * mid <= x) ok = mid;
			  else ng = mid;
		  }
		  ans += ok;
		  ok = 0;
		  ng = 1000000000 + 1;
		  while(Math.abs(ok - ng) > 1){
			  mid = (ok + ng) / 2;
			  if (2 * mid * mid <= x) ok = mid;
			  else ng = mid;
		  }
		  ans += ok;
		  return ans;
	  }


}
0