結果

問題 No.136 Yet Another GCD Problem
ユーザー ぴろずぴろず
提出日時 2015-01-25 23:31:33
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 5,000 ms
コード長 1,336 bytes
コンパイル時間 4,935 ms
コンパイル使用メモリ 84,760 KB
実行使用メモリ 56,216 KB
最終ジャッジ日時 2023-09-05 06:34:51
合計ジャッジ時間 12,039 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,728 KB
testcase_01 AC 127 ms
55,752 KB
testcase_02 AC 125 ms
55,560 KB
testcase_03 AC 126 ms
55,676 KB
testcase_04 AC 126 ms
55,688 KB
testcase_05 AC 128 ms
55,640 KB
testcase_06 AC 130 ms
55,740 KB
testcase_07 AC 128 ms
56,052 KB
testcase_08 AC 128 ms
55,664 KB
testcase_09 AC 130 ms
55,748 KB
testcase_10 AC 128 ms
55,612 KB
testcase_11 AC 127 ms
55,636 KB
testcase_12 AC 126 ms
55,684 KB
testcase_13 AC 127 ms
56,100 KB
testcase_14 AC 130 ms
55,576 KB
testcase_15 AC 130 ms
55,516 KB
testcase_16 AC 129 ms
55,776 KB
testcase_17 AC 129 ms
55,448 KB
testcase_18 AC 131 ms
55,560 KB
testcase_19 AC 129 ms
55,680 KB
testcase_20 AC 129 ms
55,636 KB
testcase_21 AC 127 ms
56,088 KB
testcase_22 AC 127 ms
55,732 KB
testcase_23 AC 127 ms
55,616 KB
testcase_24 AC 125 ms
55,816 KB
testcase_25 AC 125 ms
55,680 KB
testcase_26 AC 124 ms
55,756 KB
testcase_27 AC 126 ms
55,512 KB
testcase_28 AC 124 ms
55,704 KB
testcase_29 AC 126 ms
55,552 KB
testcase_30 AC 127 ms
55,816 KB
testcase_31 AC 128 ms
55,876 KB
testcase_32 AC 128 ms
56,216 KB
testcase_33 AC 128 ms
56,000 KB
testcase_34 AC 128 ms
55,548 KB
testcase_35 AC 128 ms
55,444 KB
testcase_36 AC 126 ms
55,580 KB
testcase_37 AC 128 ms
55,820 KB
testcase_38 AC 128 ms
54,144 KB
testcase_39 AC 128 ms
55,680 KB
testcase_40 AC 126 ms
55,524 KB
testcase_41 AC 128 ms
55,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

package no136;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.nextInt();
		ArrayList<Long> pf = Sieve.primeFactorL(n);

		System.out.println(n / pf.get(0));
	}

}
class Sieve {
	public static boolean[] isPrimeArray(int max) {
		boolean[] isPrime = new boolean[max+1];
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		for(int i=2;i*i<=max;i++) {
			if (isPrime[i]) {
				int j = i * 2;
				while(j<=max) {
					isPrime[j] = false;
					j += i;
				}
			}
		}
		return isPrime;
	}
	public static ArrayList<Integer> primeList(int max) {
		boolean[] isPrime = isPrimeArray(max);
		ArrayList<Integer> primeList = new ArrayList<Integer>();
		for(int i=2;i<=max;i++) {
			if (isPrime[i]) {
				primeList.add(i);
			}
		}
		return primeList;
	}

	public static ArrayList<Long> primeFactorL(ArrayList<Integer> primeList,long num) {
		ArrayList<Long> ret = new ArrayList<Long>();
		for(int p:primeList) {
			while(num % p == 0) {
				num /= p;
				ret.add((long) p);
			}
		}
		if (num > 1) {
			ret.add(num);
		}
		return ret;
	}
	public static ArrayList<Long> primeFactorL(long num) {
		return primeFactorL(primeList((int) (Math.sqrt(num) + 0.5)), num);
	}


}
0