結果

問題 No.937 Ultra Sword
ユーザー leaf_1415leaf_1415
提出日時 2019-11-30 22:21:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 51 ms / 3,000 ms
コード長 1,072 bytes
コンパイル時間 462 ms
コンパイル使用メモリ 60,016 KB
実行使用メモリ 5,180 KB
最終ジャッジ日時 2023-08-13 09:47:56
合計ジャッジ時間 3,411 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
4,376 KB
testcase_01 AC 8 ms
4,380 KB
testcase_02 AC 7 ms
4,376 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 6 ms
4,380 KB
testcase_05 AC 40 ms
4,608 KB
testcase_06 AC 43 ms
4,792 KB
testcase_07 AC 46 ms
4,920 KB
testcase_08 AC 24 ms
4,552 KB
testcase_09 AC 20 ms
4,436 KB
testcase_10 AC 51 ms
5,064 KB
testcase_11 AC 15 ms
4,376 KB
testcase_12 AC 43 ms
4,516 KB
testcase_13 AC 42 ms
4,516 KB
testcase_14 AC 48 ms
4,592 KB
testcase_15 AC 37 ms
4,560 KB
testcase_16 AC 8 ms
4,380 KB
testcase_17 AC 10 ms
4,380 KB
testcase_18 AC 40 ms
4,476 KB
testcase_19 AC 26 ms
4,376 KB
testcase_20 AC 24 ms
4,380 KB
testcase_21 AC 49 ms
4,988 KB
testcase_22 AC 7 ms
4,380 KB
testcase_23 AC 7 ms
4,376 KB
testcase_24 AC 43 ms
4,604 KB
testcase_25 AC 44 ms
4,904 KB
testcase_26 AC 36 ms
4,888 KB
testcase_27 AC 37 ms
4,780 KB
testcase_28 AC 41 ms
4,812 KB
testcase_29 AC 7 ms
4,376 KB
testcase_30 AC 31 ms
4,648 KB
testcase_31 AC 47 ms
5,008 KB
testcase_32 AC 31 ms
4,556 KB
testcase_33 AC 48 ms
4,948 KB
testcase_34 AC 12 ms
4,376 KB
testcase_35 AC 9 ms
4,380 KB
testcase_36 AC 42 ms
5,180 KB
testcase_37 AC 10 ms
4,376 KB
testcase_38 AC 34 ms
4,696 KB
testcase_39 AC 7 ms
4,376 KB
testcase_40 AC 39 ms
4,856 KB
testcase_41 AC 19 ms
4,384 KB
testcase_42 AC 31 ms
4,556 KB
testcase_43 AC 29 ms
4,620 KB
testcase_44 AC 14 ms
4,380 KB
testcase_45 AC 21 ms
4,456 KB
testcase_46 AC 21 ms
4,488 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#define llint long long

using namespace std;

llint n;
llint a[100005], cnt[100005];
bool prime[100005];

llint mod(llint a, llint b)
{
	llint k = -1;
	for(llint t = b; t; t/=2) k++;
	
	for(int i = 60; i >= k; i--){
		if(a & (1LL<<i)) a ^= (b<<(i-k));
	}
	return a;
}

llint gcd(llint a, llint b)
{
	if(b == 0) return a;
	return gcd(b, mod(a, b));
}

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++) cnt[a[i]] += a[i];
	
	for(int i = 2; i < 100005; i++){
		if(prime[i]) continue;
		for(int j = 2*i; j < 100005; j+=i) prime[j] = true;
	}
	for(int i = 2; i < 100005; i++){
		if(prime[i]) continue;
		for(int j = 100004/i; j >= 1; j--){
			cnt[j] += cnt[j*i];
		}
	}
	
	llint g = 0;
	for(int i = 1; i <= n; i++) g = gcd(g, a[i]);
	
	llint sum = cnt[1], ans = sum;
	for(int i = 1; i < (1<<17); i++){
		llint x = 0;
		for(int j = 0; j < 17; j++){
			if(i & (1<<j)) x ^= g << j;
		}
		if(x >= 100005) continue;
		ans = min(ans, sum-cnt[x]+cnt[x]/x);
	}
	cout << ans << endl;
	
	return 0;
}
0