結果

問題 No.1200 お菓子配り-3
ユーザー ks2mks2m
提出日時 2020-08-28 22:13:31
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,191 bytes
コンパイル時間 5,049 ms
コンパイル使用メモリ 74,300 KB
実行使用メモリ 59,696 KB
最終ジャッジ日時 2023-08-09 08:48:58
合計ジャッジ時間 9,699 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
49,300 KB
testcase_01 AC 45 ms
49,500 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 AC 50 ms
49,920 KB
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 AC 45 ms
49,268 KB
testcase_28 AC 1,363 ms
57,200 KB
testcase_29 AC 1,181 ms
57,984 KB
testcase_30 AC 1,256 ms
59,696 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;
				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