Luogu [POI2002] [HAOI2007] the number of anti-hormone problem solution

Cackle

Konjac began studying mathematics. . .

I may have learned a fake math before

Face questions

Face questions

Solution

  • Lemma \ (1 \) :

Is the maximum number of anti-prime \ (1 \ dots N \) minimum number of the maximum number of divisor numbers.

prove:

Set \ (m \) of \ (1 \ cdots N \) up to about the number of the number of a smallest number. The \ (m \) defined, apparently satisfied:

  1. \(\forall x<m,g_x<g_m\)

  2. \(\forall x>m,g_x\leq g_m\)

    The definition of the anti-prime, first described the nature of \ (m \) is emirp, is greater than the second nature described \ (m \) number not emirp, so \ (m \) is also desired.

  • Lemma \ (2 \) :

\ (1 \ dots N \) any number of different prime factors are not more than \ (10 \) a, and the sum of all prime factors of the index does not exceed \ (30 \) .

prove:

Minimum \ (11 \) product of a prime number greater than \ (2 * 10 ^ 9 \) , so \ (N <2 * 10 ^ 9 \) can not have more than \ (10 \) different prime factors .

Because even the smallest prime number comprising only, still \ (2 ^ {31}> 2 * 10 ^ 9 \) , so \ (N <2 * 10 ^ 9 \) sum can not exceed the quality factor index \ (30 \) .

  • Lemma \ (3 \) :

    \ (\ FORALL X \ in [. 1, N] \) , \ (X \) necessary conditions for emirp is: \ (X \) after decomposition of the quality factor can be written as \ (2 ^ {c_1} * 3 ^ { c_2} * 5 ^ {c_3} * 7 ^ {c_4} * 11 ^ {c_5} * 13 ^ {c_6} * 17 ^ {c_7} * 19 ^ {c_8} * 23 ^ {c_9} * 29 ^ {c_ { 10}} \) , and \ (c_1 and \ GEQ c_2 \ GEQ \ cdots \ GEQ C_ {10} \ GEQ 0 \) .

prove:

Because the sum of the divisor exponent is determined, but also the smallest. If the index is not monotonically decreasing, we will be by way of exchange index, constructed around a number of the same number, and the value of a smaller number, obviously does not meet the definition.

To sum up, we can use \ (DFS \) to determine the prime factors of each index, and meet all the conditions described above, followed by updating the answer to.

Code

#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
    int f=1;char k=getchar();x=0;
    for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
    for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
    x*=f;
}
template<class T>il print(T x){
    if(x/10) print(x/10);
    putchar(x%10+'0');
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
    int res=1,bas=x%mod;
    while(m){
        if(m&1) res=(res*bas)%mod;
        bas=(bas*bas)%mod,m>>=1;
    }
    return res%mod;
}
int T,n,m,ans,cnt,prime[15]={0,2,3,5,7,11,13,17,19,23,29};
il DFS(int pos,int pre,int res,int num){
    if(pos==11){
        if(num>cnt) cnt=num,ans=res;
        else if(num==cnt) ans=min(ans,res);
        return ;
    }
    for(ri i=pre;i>=0;--i){
        if(pow(prime[pos],i)>n) continue;
        if(pow(prime[pos],i)>n/res) continue;
        DFS(pos+1,i,res*pow(prime[pos],i),num*(i+1));
    }
}
int main()
{
//  freopen(".in","r",stdin);
//  freopen(".out","w",stdout);
    read(n);
    DFS(1,30,1,1);
    printf("%d",ans);
    return 0;
}

to sum up

I have really good food ah. .

These questions must seize the characteristics of problem analysis, to gradually narrow the scope or find a way to positive solutions.

\ (ps: \) above explanations are from all contents of Li Yudong "algorithm contest Step-up Guide"Konjac is weak, only Transcription

Guess you like

Origin www.cnblogs.com/TheShadow/p/11391319.html