Topic Description
For any positive integer x, the number of divisors is g (x). For example G (1) =1, g (6) = 4.
If a positive integer x satisfies: g (x) >g (i) 0<i<x, the x is called the inverse prime. For example, integer 1,2,4,6 are all inverse prime numbers.
Now given a number n, you can find the largest inverse prime that is no more than N. input and output formats Input Format:
A number N (1<=n<=2,000,000,000).
output Format:
The largest inverse prime number that does not exceed N.
input and Output sample Enter Sample #:
1000
Output Sample #:
840
The meaning is to find a number within 1 to n so that the number has the most divisors. If you have more solutions, just look for the smallest one.
(Difficulty in Reading questions)
First of all, no more than 12, the enumeration index, the storm search.
#include <iostream>
#include <cstdio>
using namespace std;
Long Long n,mx,ans,pri[]={0,2,3,5,7,11,13,17,19,23,29,31,37};
void Dfs (int u,long long Sum,long long res)
{
if (u>12) return
;
if (sum>mx| | Sum==mx&&res<ans)
{
mx=sum;
ans=res;
}
Long long pw=1,cnt=0;
while (pw*res<=n)
{
dfs (u+1,sum* (cnt+1), RES*PW);
Pw*=pri[u];
cnt++
}
}
int main ()
{
scanf ("%lld", &n);
DFS (1,1,1);
printf ("%lld\n", ans);
return 0;
}