HDU 2521 Inverse prime

Source: Internet
Author: User
Tags greatest common divisor

Inverse Prime Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4142 Accepted Submission (s): 2396


Problem Description The inverse prime is satisfied for any I (0<i<x), there is g (i) <g (x), (g (x) is the number of factors of x), then x is an inverse prime. Now give you an integer interval [a, b], please find out the x of the interval to make g (x) the largest.

Input first line n, next n line test data
The input includes a, B, 1<=a<=b<=5000, which indicates the closed interval [a, b].

The output is an integer that is the maximum number of the interval factor. If there are more than one, the minimum number is output.

Sample Input

3 2 3 1 10 47 359
Sample Output
2 6 240


#include <stdio.h> 
int s[5010]={0,1,2,2};
void f ()
{
    int i,j;
    for (i=4;i<5010;i++)
    {for
        (j=2;j<=i/2;j++)//I/2 represents greatest common divisor 
        //for (j=2;j*j<=i;j++)
        if (i%j==0 )  s[i]++;
        s[i]+=2;
    }
}
int main ()
{
	f ();
    int n,a,b,i,max,t;
    scanf ("%d", &n);
    while (n--)
    {
        scanf ("%d%d", &a,&b);
        T=a;
        max=0;
        for (i=a;i<=b;i++)
        {
            if (S[i]>max) 
            {  
                max=s[i];
                t=i;
            }
        }
        printf ("%d\n", t);
    }
    return 0;
} 


Related Article

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.