結果
| 問題 |
No.1200 お菓子配り-3
|
| コンテスト | |
| ユーザー |
ks2m
|
| 提出日時 | 2020-08-28 22:18:42 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,284 bytes |
| コンパイル時間 | 2,396 ms |
| コンパイル使用メモリ | 78,216 KB |
| 実行使用メモリ | 75,696 KB |
| 最終ジャッジ日時 | 2024-11-14 15:35:18 |
| 合計ジャッジ時間 | 22,003 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 29 WA * 2 |
ソースコード
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;
}
}
ks2m