結果

問題 No.937 Ultra Sword
ユーザー leaf_1415leaf_1415
提出日時 2019-11-30 22:18:47
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 979 bytes
コンパイル時間 582 ms
コンパイル使用メモリ 58,164 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-05-01 03:17:51
合計ジャッジ時間 2,851 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 44 ms
6,940 KB
testcase_06 AC 39 ms
6,944 KB
testcase_07 AC 43 ms
6,944 KB
testcase_08 AC 20 ms
6,944 KB
testcase_09 AC 17 ms
6,940 KB
testcase_10 AC 46 ms
6,944 KB
testcase_11 AC 11 ms
6,944 KB
testcase_12 AC 41 ms
6,940 KB
testcase_13 AC 40 ms
6,940 KB
testcase_14 AC 46 ms
6,944 KB
testcase_15 AC 33 ms
6,940 KB
testcase_16 AC 4 ms
6,940 KB
testcase_17 AC 6 ms
6,940 KB
testcase_18 AC 37 ms
6,940 KB
testcase_19 AC 23 ms
6,940 KB
testcase_20 AC 20 ms
6,944 KB
testcase_21 AC 50 ms
6,940 KB
testcase_22 AC 3 ms
6,944 KB
testcase_23 AC 3 ms
6,940 KB
testcase_24 AC 47 ms
6,940 KB
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 35 ms
6,940 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 29 ms
6,940 KB
testcase_31 AC 46 ms
6,944 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 10 ms
6,944 KB
testcase_35 AC 5 ms
6,940 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 AC 11 ms
6,940 KB
testcase_45 WA -
testcase_46 AC 19 ms
6,944 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; g*i < 100005; i++){
		int x = g*i;
		ans = min(ans, sum-cnt[x]+cnt[x]/x);
	}
	cout << ans << endl;
	
	return 0;
}
0