Find AP Number

Source: Internet
Author: User
Topic Background

Positive integer n is infinite, but some of these numbers have magical properties, we give it a name--ap number. Topic Description

The necessary and sufficient condition for a number i is an AP number is that all of the number of factors that are smaller than it are not the number of I. For example, the factor of 6 is 1 2 3 6 Total has 4 factor. It is an AP number (1-5 of the number of factors is not 2 or 3). The task of our topic is to find a maximum number of AP that is no more than N. Input output format input format:

Each test point may have multiple sets of data.

For each row there is an N, as described in the topic

Output format:

For each line of the maximum number of AP and no more than n

#include <cmath>
#include <cstdio>
#include <iostream>
using namespace std;
Long long N,AP,FAP;
int mm[30]={2,3,5,7,11,13,17,19,23,29};
void Dfs (Long long num,long long Fnum,long long I,long long j)
{
    if fap<fnum| | (fap==fnum&&ap>num))
	{
        fap=fnum;
        Ap=num;
    }
    int t=1;
    while (t<=j&&num*mm[i]<=n)
	{
        num*=mm[i];
        DFS (num,fnum* (t+1), i+1,t);
        t++;
    }
    return;
} 
int main ()
{
    while (~scanf ("%lld", &n))
    {
    	ap=0;
		Fap=0;
   	 	DFS (1,1,0,20);
		cout<<ap<<endl;
	}
}    AP=AP/3;    ap=ap*3;    AP=AP/11;    ap=ap*11;
    


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.