Codeforces Round #511 Div2 C. Enlarge GCD

Source: Internet
Author: User
Tags gcd greatest common divisor

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.