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;
}