Logu P1463 [HAOI2007] Inverse prime ant__ Search

Source: Internet
Author: User
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;
}

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.