Codeforces Round #432 (Div. 2) D. Arpa and a list of numbers(暴力)
阿新 • • 發佈:2017-09-05
esp for int ans logs and codeforce style inf
枚舉質數,判斷是否超過臨界值。臨界值就是將不是因子中不含這個素數的數的個數乘以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) #defineDel(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(暴力)