[HAOI2007]反素数

这道题其实就是求在 [1,n] 的区间内,那个数的约数个数最多,如果同样多,取最小。。。

那么我们只需要把质因数分解反过来做,然后更新答案就好了。。。

素数不需要筛出来,直接打表就好,因为只能用到几个,就超过范围了。。。

呆码:

#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;

int pr[25]={0,2,3,5,7,11,13,17,19,23,31};
ll n,ans,maxn;

inline void dfs(ll sum,ll tot,int nb,int p)
{
    if(sum>maxn || (sum==maxn && tot<ans))
    {
        maxn=sum;
        ans=tot;
    }
    int j=0;
    ll summ=0,tott=tot;
    while(j<=p && n/tott>=pr[nb])
    {
        j++;
        summ=sum*(j+1) , tott*=pr[nb];
        if(tott<=n) dfs(summ,tott,nb+1,p);
    }
}

int main()
{
    scanf("%lld",&n);
    dfs(1,1,1,31);
    printf("%lld
",ans);
}
代码
原文地址:https://www.cnblogs.com/zzzyc/p/9229970.html