結果

問題 No.719 Coprime
ユーザー 37zigen37zigen
提出日時 2018-07-29 01:02:37
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,721 bytes
コンパイル時間 2,363 ms
コンパイル使用メモリ 76,040 KB
実行使用メモリ 58,964 KB
最終ジャッジ日時 2023-09-20 21:03:47
合計ジャッジ時間 13,595 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 121 ms
55,264 KB
testcase_01 AC 120 ms
55,700 KB
testcase_02 AC 121 ms
56,116 KB
testcase_03 AC 122 ms
55,508 KB
testcase_04 AC 121 ms
55,800 KB
testcase_05 AC 122 ms
56,420 KB
testcase_06 AC 124 ms
55,540 KB
testcase_07 AC 125 ms
55,612 KB
testcase_08 AC 124 ms
55,680 KB
testcase_09 AC 126 ms
55,696 KB
testcase_10 AC 128 ms
55,836 KB
testcase_11 AC 125 ms
55,824 KB
testcase_12 AC 124 ms
55,580 KB
testcase_13 AC 122 ms
55,904 KB
testcase_14 AC 123 ms
55,748 KB
testcase_15 AC 125 ms
55,864 KB
testcase_16 AC 125 ms
55,452 KB
testcase_17 AC 126 ms
56,068 KB
testcase_18 AC 126 ms
56,080 KB
testcase_19 AC 127 ms
55,780 KB
testcase_20 AC 127 ms
55,296 KB
testcase_21 AC 127 ms
55,556 KB
testcase_22 AC 128 ms
55,808 KB
testcase_23 AC 128 ms
56,216 KB
testcase_24 AC 128 ms
55,520 KB
testcase_25 AC 130 ms
55,484 KB
testcase_26 AC 131 ms
55,552 KB
testcase_27 AC 130 ms
56,036 KB
testcase_28 AC 132 ms
55,516 KB
testcase_29 AC 130 ms
55,828 KB
testcase_30 AC 130 ms
55,648 KB
testcase_31 AC 131 ms
56,104 KB
testcase_32 AC 131 ms
55,632 KB
testcase_33 AC 130 ms
55,612 KB
testcase_34 AC 130 ms
55,832 KB
testcase_35 AC 130 ms
55,948 KB
testcase_36 AC 131 ms
55,680 KB
testcase_37 AC 132 ms
55,552 KB
testcase_38 AC 132 ms
55,612 KB
testcase_39 AC 131 ms
53,552 KB
testcase_40 AC 131 ms
55,980 KB
testcase_41 AC 136 ms
55,944 KB
testcase_42 AC 136 ms
55,468 KB
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
testcase_51 WA -
testcase_52 WA -
testcase_53 WA -
testcase_54 WA -
testcase_55 WA -
testcase_56 WA -
testcase_57 WA -
testcase_58 WA -
testcase_59 WA -
testcase_60 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

public class Main {
	public static void main(String[] args) {
		new Main().run();
	}

	void run() {
		Scanner sc = new Scanner(System.in);
		boolean[] isPrime = new boolean[1263];
		int[] g = new int[isPrime.length];
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;
		int cnt = 0;
		for (int i = 2; i < isPrime.length; ++i) {
			if (!isPrime[i])
				continue;
			for (int j = 2 * i; j < isPrime.length; j += i) {
				isPrime[j] = false;
			}
			if (i * i <= isPrime.length)
				for (int j = i; j < isPrime.length; j += i) {
					g[j] |= 1 << cnt;
				}
			++cnt;
		}
		ArrayList<Integer> plist = new ArrayList<>();
		for (int i = 0; i < isPrime.length; ++i) {
			if (isPrime[i])
				plist.add(i);
		}
		int N = sc.nextInt();
		boolean[] vis = new boolean[N + 1];
		long[] dp = new long[1 << 11];
		for (int i = N; i > plist.get(10); --i) {
			if (!isPrime[i])
				continue;
			long[] ndp = Arrays.copyOf(dp, dp.length);
			for (int j = i; j <= N; j += i) {
				vis[j] = true;
				for (int s = 0; s < 1 << 11; ++s) {
					if ((s & g[i]) == 0) {
						ndp[s | g[i]] = Math.max(ndp[s | g[i]], dp[s] + j);
					}
				}
			}
			dp = ndp;
		}

		for (int i = 2; i <= N; ++i) {
			if (vis[i])
				continue;
			for (int s = 0; s < 1 << 11; ++s) {
				if ((s & g[i]) == 0)
					dp[s | g[i]] = Math.max(dp[s | g[i]], dp[s] + i);
			}
		}
		long ans = 0;
		for (long v : dp)
			ans = Math.max(ans, v);
		System.out.println(ans);
	}

	long gcd(long a, long b) {
		if (a > b)
			return gcd(b, a);
		if (a == 0)
			return b;
		return gcd(a, b % a);
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}
0