結果

問題 No.1200 お菓子配り-3
ユーザー ks2mks2m
提出日時 2020-08-28 22:18:42
言語 Java21
(openjdk 21)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,284 bytes
コンパイル時間 2,372 ms
コンパイル使用メモリ 78,696 KB
実行使用メモリ 75,676 KB
最終ジャッジ日時 2024-04-26 23:30:48
合計ジャッジ時間 22,021 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
50,284 KB
testcase_01 AC 53 ms
52,188 KB
testcase_02 AC 57 ms
50,348 KB
testcase_03 AC 57 ms
50,012 KB
testcase_04 AC 56 ms
49,868 KB
testcase_05 AC 56 ms
50,140 KB
testcase_06 AC 56 ms
50,316 KB
testcase_07 AC 132 ms
52,216 KB
testcase_08 AC 99 ms
52,016 KB
testcase_09 AC 97 ms
52,000 KB
testcase_10 AC 98 ms
51,976 KB
testcase_11 AC 98 ms
51,920 KB
testcase_12 AC 201 ms
52,580 KB
testcase_13 AC 218 ms
52,660 KB
testcase_14 AC 195 ms
52,444 KB
testcase_15 AC 219 ms
52,876 KB
testcase_16 AC 215 ms
52,996 KB
testcase_17 AC 474 ms
55,040 KB
testcase_18 AC 583 ms
57,436 KB
testcase_19 AC 222 ms
52,840 KB
testcase_20 AC 1,584 ms
75,456 KB
testcase_21 AC 1,523 ms
75,156 KB
testcase_22 AC 1,624 ms
75,532 KB
testcase_23 AC 1,452 ms
75,364 KB
testcase_24 AC 1,519 ms
74,692 KB
testcase_25 AC 1,446 ms
71,792 KB
testcase_26 AC 1,486 ms
75,676 KB
testcase_27 AC 54 ms
50,028 KB
testcase_28 AC 1,468 ms
57,528 KB
testcase_29 AC 1,249 ms
58,748 KB
testcase_30 AC 1,270 ms
59,720 KB
testcase_31 WA -
testcase_32 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int s = Integer.parseInt(br.readLine());
		PrintWriter pw = new PrintWriter(System.out);
		for (int i = 0; i < s; i++) {
			String[] sa = br.readLine().split(" ");
			int x = Integer.parseInt(sa[0]);
			int y = Integer.parseInt(sa[1]);
			int xy = x + y;
			List<Integer> list = divList(xy);
			int ans = 0;
			for (int o : list) {
				long a = o - 1;
				long bc = xy / o;
				if (a == 1) {
					if (x == y && bc % 2 == 0) {
						ans++;
					}
					continue;
				}
				long y2 = y * a - x;
				long c2 = a * a - 1;
				if (y2 > 0 && y2 % c2 == 0 && y2 / c2 < bc) {
					ans++;
				}
			}
			pw.println(ans);
		}
		br.close();
		pw.flush();
	}

	static List<Integer> divList(int n) {
		List<Integer> list = new ArrayList<>();
		int end = (int) Math.sqrt(n);
		for (int i = 2; i <= end; i++) {
			if (n % i == 0) {
				list.add(i);
			}
		}
		int i = end * end == n ? list.size() - 2 : list.size() - 1;
		for ( ; i >= 0; i--) {
			list.add(n / list.get(i));
		}
		return list;
	}
}
0