結果
問題 | No.136 Yet Another GCD Problem |
ユーザー |
![]() |
提出日時 | 2015-01-25 23:31:33 |
言語 | Java17 (openjdk 17.0.1) |
結果 |
AC
|
実行時間 | 106 ms / 5,000 ms |
コード長 | 1,336 bytes |
コンパイル時間 | 2,873 ms |
使用メモリ | 37,860 KB |
最終ジャッジ日時 | 2023-01-20 12:43:39 |
合計ジャッジ時間 | 8,801 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 103 ms
37,492 KB |
testcase_01 | AC | 97 ms
37,608 KB |
testcase_02 | AC | 101 ms
37,508 KB |
testcase_03 | AC | 98 ms
37,428 KB |
testcase_04 | AC | 97 ms
37,516 KB |
testcase_05 | AC | 101 ms
37,460 KB |
testcase_06 | AC | 98 ms
37,560 KB |
testcase_07 | AC | 98 ms
37,640 KB |
testcase_08 | AC | 101 ms
37,452 KB |
testcase_09 | AC | 99 ms
37,444 KB |
testcase_10 | AC | 99 ms
37,696 KB |
testcase_11 | AC | 101 ms
37,736 KB |
testcase_12 | AC | 96 ms
37,536 KB |
testcase_13 | AC | 97 ms
37,572 KB |
testcase_14 | AC | 97 ms
37,372 KB |
testcase_15 | AC | 100 ms
37,636 KB |
testcase_16 | AC | 102 ms
37,556 KB |
testcase_17 | AC | 98 ms
37,404 KB |
testcase_18 | AC | 102 ms
37,772 KB |
testcase_19 | AC | 99 ms
37,464 KB |
testcase_20 | AC | 100 ms
37,464 KB |
testcase_21 | AC | 103 ms
37,608 KB |
testcase_22 | AC | 100 ms
37,448 KB |
testcase_23 | AC | 98 ms
37,596 KB |
testcase_24 | AC | 99 ms
37,512 KB |
testcase_25 | AC | 103 ms
37,652 KB |
testcase_26 | AC | 96 ms
37,612 KB |
testcase_27 | AC | 106 ms
37,372 KB |
testcase_28 | AC | 101 ms
37,436 KB |
testcase_29 | AC | 101 ms
37,728 KB |
testcase_30 | AC | 103 ms
37,860 KB |
testcase_31 | AC | 97 ms
37,560 KB |
testcase_32 | AC | 101 ms
37,804 KB |
testcase_33 | AC | 102 ms
37,644 KB |
testcase_34 | AC | 103 ms
37,584 KB |
testcase_35 | AC | 99 ms
37,496 KB |
testcase_36 | AC | 99 ms
37,408 KB |
testcase_37 | AC | 102 ms
37,608 KB |
testcase_38 | AC | 104 ms
37,556 KB |
testcase_39 | AC | 101 ms
37,568 KB |
testcase_40 | AC | 100 ms
37,372 KB |
testcase_41 | AC | 101 ms
37,604 KB |
ソースコード
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); } }