Codeforces Round #432 (Div. 2) D. Arpa and a list of numbers(暴力)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Codeforces Round #432 (Div. 2) D. Arpa and a list of numbers(暴力)相关的知识,希望对你有一定的参考价值。
枚举质数,判断是否超过临界值。临界值就是将不是因子中不含这个素数的数的个数乘以x和y的较小值,是否小于当前最小值。
#include <algorithm> #include <cstdio> #include <cstring> #include <iostream> #define Max 1000001 #define MAXN 500005 #define MAXNUM 1000005 #define MOD 100000000 #define rin freopen("in.txt","r",stdin) #define rout freopen("1.out","w",stdout) #define Del(a,b) memset(a,b,sizeof(a)) using namespace std; typedef long long LL; const int INF = 0x3f3f3f3f; const LL LINF = 0x3f3f3f3f3f3f3f3fLL; int a[MAXN]; int sum[MAXNUM]; int vis[MAXNUM]; int n, x, y; int main() { //rin; scanf("%d%d%d", &n, &x, &y); Del(sum, 0); Del(vis, 0); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); sum[a[i]]++; } LL cnt = LINF; for (int i = 2; i <= 1000000; i++) { if (!vis[i]) { LL ans = sum[i]; for (int j = 2 * i; j <= 1000000; j += i) vis[j] = 1, ans += sum[j]; if ((n - ans) * min(x, y) < cnt) { LL tans = 0; for (int j = 0; j < n; j++) { if (a[j] % i) { LL t = a[j] % i; tans += min(1ll * x, 1ll * y * (i - t)); } } cnt = min(cnt, tans); } } } printf("%lld",cnt); return 0; }
以上是关于Codeforces Round #432 (Div. 2) D. Arpa and a list of numbers(暴力)的主要内容,如果未能解决你的问题,请参考以下文章
Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) A
Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) D
D. Arpa and a list of numbers Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)(示
枚举Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017) Div2C题