Http://codeforces.com/contest/1047/problem/C
Problem
Given a sequence \ (a\), the greatest common divisor of all numbers in the original sequence is \ (p\). Now to delete some number to form a new sequence, count the new sequence of all the number of greatest common divisor for \ (q\) to ask for a minimum of delete more than a few can make \ (q > P\).
Exercises
First find \ (p\), then enumerate \ (q > P\), calculate what multiples of \ (q\) in the sequence. Note that if \ ( a | q\) and \ (A > P\)are present, then \ (a\) is obviously better than \ (p\), so it is good to enumerate with a method similar to sieve, complexity \ (O ( N \cdot \log{\log{n}}) .
#include <bits/stdc++.h>using namespace Std;typedef long long ll;typedef unsigned int uint;typedef unsigned long lon G Ull;typedef Pair<int, int> pii;int rint () {int n, c, sgn = 0; while ((c = GetChar ()) < '-'); if (c = = '-') n = 0, sgn = 1; else n = C-' 0 '; while ((c = GetChar ()) >= ' 0 ') {n = ten * n + C-' 0 '; } return SGN? -n:n;} const int N = 300010;const int MAX = 1.5e7 + 10;int n;bool mark[max];int cnt[max];int Main () {scanf ("%d", &n); int g = 0; for (int i = 0; i < n; i++) {int x; scanf ("%d", &x); cnt[x]++; g = __GCD (g, X); } int ans = n; for (int d = g + 1; d < MAX; d++) {if (mark[d]) continue; int need = 0; for (ll j = D; j < MAX; J + = d) {Mark[j] = true; Need + = Cnt[j]; } if (need > 0) {ans = min (ans, n-need); }} if (ans = = N) puts ("-1"); else printf ("%d\n", ans); FprinTF (stderr, "%.3lf sec\n", double (Clock ())/clocks_per_sec); return 0;}
Codeforces Round #511 Div2 C. Enlarge GCD