結果
| 問題 |
No.1200 お菓子配り-3
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-08-30 06:10:19 |
| 言語 | Java (openjdk 23) |
| 結果 |
TLE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,038 bytes |
| コンパイル時間 | 3,492 ms |
| コンパイル使用メモリ | 79,092 KB |
| 実行使用メモリ | 67,232 KB |
| 最終ジャッジ日時 | 2024-11-14 17:54:32 |
| 合計ジャッジ時間 | 45,194 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 30 TLE * 1 |
ソースコード
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
new Main().run();
}
final long MOD=(long)1e9+7;
void run() {
Scanner sc = new Scanner(System.in);
PrintWriter pw=new PrintWriter(System.out);
int S=sc.nextInt();
while (S-->0) {
long ans=0;
long x=Long.parseLong(sc.next());
long y=Long.parseLong(sc.next());
if (x<y) {
x^=y;y^=x;x^=y;
}
if (x==y) ans=x-1;//a=1の場合
ArrayList<Long> divs=new ArrayList<>();
for (long div=2;div*div<=x+y;++div) {
if ((x+y)%div!=0) continue;
divs.add(div);
if (div*div!=x+y) {
divs.add((x+y)/div);
}
}
for (long d:divs) {
if (d==2) continue;
long a=d-1;
long bc=(x+y)/d;
long b=(x-bc)/(a-1);
long c=bc-b;
if (x!=a*b+c || y!=a*c+b || a<=0 || b<=0 || c<=0) continue;
ans+=1;
}
pw.println(ans);
}
pw.flush();
}
void tr(Object...o) {System.out.println(Arrays.deepToString(o));}
}