結果

問題 No.719 Coprime
コンテスト
ユーザー startcpp
提出日時 2016-07-02 23:18:53
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
TLE  
実行時間 -
コード長 739 bytes
コンパイル時間 524 ms
コンパイル使用メモリ 54,908 KB
実行使用メモリ 9,888 KB
最終ジャッジ日時 2024-10-12 01:28:46
合計ジャッジ時間 11,845 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 TLE * 2 -- * 40
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
using namespace std;

int n;

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

int main() {
	int i, j, k;
	int ans = -1;
	
	cin >> n;
	for (i = 0; i < (1LL << (n - 1)); i++) {
		bool usedNum[41] = {false};
		
		for (j = 0; j < n - 1; j++) {
			if ((i >> j) % 2 == 1) {
				usedNum[j+2] = true;
			}
		}
		
		bool flag = true;
		for (j = 2; j <= n; j++) {
			if (!usedNum[j]) continue;
			for (k = 2; k <= n; k++) {
				if (!usedNum[k] || j == k) continue;
				if (gcd(j, k) >= 2) {
					flag = false;
				}
			}
		}
		if (flag) {
			int score = 0;
			for (j = 2; j <= n; j++) {
				if (usedNum[j]) {
					score += j;
				}
			}
			ans = max(ans, score);
		}
	}
	cout << ans << endl;
	return 0;
}
0