結果

問題 No.917 Make One With GCD
ユーザー ningenMeningenMe
提出日時 2019-09-09 04:02:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 735 bytes
コンパイル時間 1,757 ms
コンパイル使用メモリ 172,564 KB
実行使用メモリ 7,792 KB
最終ジャッジ日時 2023-09-10 09:06:04
合計ジャッジ時間 7,308 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 165 ms
4,388 KB
testcase_04 AC 20 ms
4,504 KB
testcase_05 WA -
testcase_06 AC 83 ms
4,384 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,384 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 1 ms
4,384 KB
testcase_18 WA -
testcase_19 AC 2 ms
4,384 KB
testcase_20 AC 5 ms
4,384 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

//divisor O(sqrt(N))
set<long long> Divisor(long long N) {
    set<long long> ret;
    for (long long i = 1; i*i <= N; ++i) {
        if (N%i == 0) {
            ret.insert(i);
            ret.insert(N / i);
        }
    }
    return ret;
}

//Greatest Common Divisor
long long GCD(long long a, long long b) {
    return ((b == 0) ? a : GCD(b, a % b));
}

//bit全探索愚直解
int main() {
	int N,MAX_A = 1000; cin >> N;
	vector<int> A(N);
	for(int i = 0; i < N; ++i) cin >> A[i];

	long long ans = 0;
	for(int i = 1; i < (1<<N); ++i) {
		int cnt = 0;
		for(int j = 0; j < N; ++j) {
			if(i&(1<<j)) cnt = GCD(cnt,A[j]);
		}
		if(cnt == 1) ans++;
	}
	cout << ans << endl;
	return 0;
}
0