結果

問題 No.2051 Divide
ユーザー ks2mks2m
提出日時 2022-08-21 12:48:45
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 2,236 ms
コンパイル使用メモリ 77,124 KB
実行使用メモリ 41,672 KB
最終ジャッジ日時 2024-04-18 12:37:13
合計ジャッジ時間 5,775 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 116 ms
41,492 KB
testcase_01 AC 118 ms
39,804 KB
testcase_02 AC 98 ms
41,224 KB
testcase_03 AC 114 ms
41,128 KB
testcase_04 AC 122 ms
41,176 KB
testcase_05 AC 115 ms
40,176 KB
testcase_06 AC 116 ms
40,364 KB
testcase_07 AC 109 ms
41,640 KB
testcase_08 AC 117 ms
40,004 KB
testcase_09 AC 123 ms
41,300 KB
testcase_10 AC 105 ms
41,440 KB
testcase_11 AC 121 ms
41,328 KB
testcase_12 AC 129 ms
41,104 KB
testcase_13 AC 126 ms
41,484 KB
testcase_14 AC 124 ms
41,084 KB
testcase_15 AC 127 ms
41,400 KB
testcase_16 AC 109 ms
41,072 KB
testcase_17 AC 123 ms
41,672 KB
testcase_18 AC 115 ms
41,436 KB
testcase_19 AC 124 ms
41,084 KB
testcase_20 AC 127 ms
41,176 KB
testcase_21 AC 113 ms
41,456 KB
testcase_22 AC 106 ms
41,192 KB
testcase_23 AC 115 ms
41,300 KB
testcase_24 AC 128 ms
41,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		sc.close();

		List<Integer> list = divList(a);
		int ans = 0;
		for (int i : list) {
			if (i % b == 0) {
				ans++;
			}
		}
		System.out.println(ans);
	}

	static List<Integer> divList(int n) {
		List<Integer> list = new ArrayList<>();
		int end = (int) Math.sqrt(n);
		for (int i = 1; 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