結果

問題 No.1200 お菓子配り-3
ユーザー 37zigen37zigen
提出日時 2020-08-30 06:25:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 2,284 ms / 4,000 ms
コード長 1,347 bytes
コンパイル時間 2,095 ms
コンパイル使用メモリ 79,716 KB
実行使用メモリ 67,340 KB
最終ジャッジ日時 2024-05-01 00:18:40
合計ジャッジ時間 29,663 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 107 ms
52,832 KB
testcase_01 AC 109 ms
54,036 KB
testcase_02 AC 141 ms
54,244 KB
testcase_03 AC 139 ms
54,216 KB
testcase_04 AC 139 ms
54,112 KB
testcase_05 AC 126 ms
53,744 KB
testcase_06 AC 122 ms
53,992 KB
testcase_07 AC 164 ms
54,692 KB
testcase_08 AC 155 ms
54,184 KB
testcase_09 AC 157 ms
54,560 KB
testcase_10 AC 179 ms
54,816 KB
testcase_11 AC 157 ms
54,168 KB
testcase_12 AC 390 ms
58,804 KB
testcase_13 AC 359 ms
57,276 KB
testcase_14 AC 395 ms
58,764 KB
testcase_15 AC 426 ms
58,780 KB
testcase_16 AC 357 ms
57,496 KB
testcase_17 AC 993 ms
66,536 KB
testcase_18 AC 1,159 ms
66,656 KB
testcase_19 AC 429 ms
58,960 KB
testcase_20 AC 1,978 ms
67,340 KB
testcase_21 AC 1,933 ms
66,712 KB
testcase_22 AC 2,284 ms
66,640 KB
testcase_23 AC 2,020 ms
66,632 KB
testcase_24 AC 1,905 ms
66,532 KB
testcase_25 AC 1,954 ms
66,560 KB
testcase_26 AC 1,958 ms
67,336 KB
testcase_27 AC 112 ms
54,044 KB
testcase_28 AC 2,027 ms
66,568 KB
testcase_29 AC 1,696 ms
67,268 KB
testcase_30 AC 1,792 ms
67,028 KB
testcase_31 AC 102 ms
53,264 KB
testcase_32 AC 104 ms
52,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
	
	
	ArrayList<Long> gen_divs(long n) {
		ArrayList<Long> divs=new ArrayList<>();
		if (n%2==0) {
			for (long div=2;div*div<=n;++div) {
				if (n%div!=0) continue;
				divs.add(div);
				divs.add(n/div);
			}
		} else {
			for (long div=3;div*div<=n;div+=2) {
				if (n%div!=0) continue;
				divs.add(div);
				divs.add(n/div);
			}
		}
		if (divs.size()>2 && divs.get(divs.size()-1)==divs.get(divs.size()-2)) {
			divs.remove(divs.size()-1);
		}
		return divs;
	}
	
	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=gen_divs(x+y);
			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));}
}

0