2019 summer training DAY16 (problem2.b) (approx.)

Subject to the effect

A given n, n is less than or equal seeking "divisor number" largest number to the number (n <= 1e18)

Usually the number of different divisors, example: There are about 12 number 1,234,612, respectively, these numbers 122,346 th divisor, that number from about 12 to about 18 in number.

Because of the wide range of n, so we can not use the simple approach.

We think this way: Since it is seeking a few more about the number and this number as small as possible, if 2 ^ 3 ^ 2 * 3 * 3 and 2 ^ 3 ^ 2 is within the range of n, we choose the former is certainly better, because two by about as much as the number is the number, are (2 + 1) * (1 + 3), while the former is smaller.

Available quality index factor is not monotonic drop

note! There may be an erroneous concept : Since the election of smaller quality factor better, why not take it all from 2 tired?

Such as 8 and 12, 8 = 2 ^ 2 ^ 2 * 3,12 = 3, we have chosen 12 to clearly better, because we have determined that when the case is more preferred to ensure that the same number has divisors, choose a more away a small number, but not blindly to the small choice. (Pay attention to preconditions, ideological rigor).

Then consider the "divisor number."

Or explanation: for example 12, can be decomposed into 2 * 2 ^ 3, then the quality index factor of 2 may be 0,1,2, index 3 prime factors may be 0, the number of select any combination of the two phases It is the last ride "about the number of the number of"

Concrete realization, we can use dfs, because we found a quality factor to take the tired, the quality factor used is in the range up to tens, you can enumerate one by one, and the last time we can answer dfs statistics

#include<bits/stdc++.h>
#define N 10000003
#define LL long long
#define INF 2100000000
using namespace std;
LL read()
{
    LL x=0,f=1;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}
LL n,tot=0;
LL ans=INF;
LL prime[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,51,53,57,59,61,67,71,73,79,83};
void dfs(LL num,LL pos,LL n,LL sum)
{
    if(sum>n)return ;
    if(num>tot){ans=sum,tot=num;}
    else if(tot==num&&ans>sum)ans=sum;
    for(int i=1;i<=100;++i)
    {
        LL res=pow(prime[pos],i);
        if(sum>n/res)break;
        dfs(num*((i+2)*(i+1)/2),pos+1,n,sum*res);
    }
}
int main()
{
//    freopen("b.in","r",stdin);
//    freopen("b.out","w",stdout);
    n=read();
    dfs(1,0,n,1);
    printf("%lld\n%lld",ans,tot);
} 
/*
*/
View Code

When I was playing was not in the loop from the beginning on a prime number is (because the update mode dfs in ans and tot can guarantee the smallest ans), if a prime number from the beginning, and then save a variable last just fine.

This question is the idea of ​​feeling is still very important, especially where quality factor is the introduction of monotonous index did not fall, problem-solving is the key point, if there is no thought of this, simple to enumerate all prime factors, it is obviously too can not.

Guess you like

Origin www.cnblogs.com/yyys-/p/11266412.html