HDU5317 (more than 2015 schools 3)--RGCDQ (prime Sieve + enumeration)

Source: Internet
Author: User

Topic Link: Click to open the link

Definition f (i) for the type of prime number comprising I, the maximum value of gcd (f (i), F (j)) (L <= i < J <= R) within the interval [l,r]

The prime number sieve 10^6 in the prime, the F (i) of each count, can be found F (i) <= 7, with an array of statistics S[I][J] from 2 to I f (x) =j how many, subtract directly from the calculation interval and judge the maximum GCD

#include <cstdio> #include <cstring> #include <cmath> #include <algorithm>using namespace std;  Define LL __int64#define maxn 1000000+10int A[MAXN], CHECK[MAXN]; int tot; int NUM[MAXN]; int s[maxn][10]; void Get_pri ()    {int I, J;    tot = 0;    memset (check,0,sizeof (check));        for (i = 2; I <= 1000000; i++) {if (!check[i]) a[tot++] = i;            for (j = 0; J < tot; J + +) {if (I*a[j] >= 1000000) break;            check[I*a[j]] = 1;        if (i%a[j] = = 0) break;    }}}int f (int x) {int J, cnt = 0;        for (j = 0; a[j]*a[j] <= x; j + +) {if (x%a[j] = = 0) cnt++;        while (x%a[j] = = 0) x/= a[j];    if (x = = 1) break;    } if (x! = 1) cnt++; return CNT;}    int main () {int T, L, R;    int I, j, ans;    Get_pri ();    for (i = 2; I <= 1000000; i++) num[i] = f (i);    Memset (s,0,sizeof (s)); for (i = 2; I <= 1000000; i++) {for (j = 1; J <= 7;        J + +) S[i][j] = S[i-1][j];    s[i][Num[i]]++;    } scanf ("%d", &t);        while (t--) {scanf ("%d%d", &l, &r);        ans = 1;            for (i = 1; I <= 7; i++) {s[0][i] = S[r][i]-s[l-1][i];        if (S[0][i] > 1) ans = i;        } if (s[0][3]+s[0][6] = = 2) ans = max (ans,3);        if (S[0][2]+s[0][4]+s[0][6] >= 2) ans = max (ans,2);    printf ("%d\n", ans); } return 0;}


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

HDU5317 (more than 2015 schools 3)--RGCDQ (prime Sieve + enumeration)

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.