题目
题解思路
在 1 到 N 中 如果 K 被称为反素数 ,那么他约数数量一定是 在 1 到 N 中 最多的 , 而且 他还要尽可能的小,不然就不一定都是小于号了 ,这样才能符号反素数的要求 。
很容易想到贪心策略
前面的质因子的次数肯定要比后面的多 ,这样数才能尽可能的小 。
并且最大的质因子次数必然不超过31,2的30次方就大概10亿多了。
而且质因子延展还不会超过第9个素数。
这些前置知识感觉都是要记的,写多题目就记住了。
这样我们就可以爆搜了 时间复杂度粗略估计这样怎么点
从2开始往后搜索,保证让后面的次数不超过前面的次数。
取最大约数 , 取最小答案即可。
闫总写dfs定义参数真的好快。
AC代码
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
const int INF = 0x3f3f3f3f;
int prm[10] = { 2 , 3 ,5 ,7 , 11 , 13 ,17 ,19 , 23 };
long long mas = -1 , nu = 0 ;
long long n ;
void dfs( int p , int last ,long long k ,long long sum )
{
if ( sum > mas )
{
mas = sum ;
nu = k ;
}else if ( sum == mas )
{
nu = min( nu , k );
}
if ( p == 9 )
return ;
for (int i = 1 ; i <= last ; i++ )
{
if ( k * prm[p] > n )
return ;
k *= prm[p];
dfs(p+1 , i , k , sum*(i+1) );
}
}
int main ()
{
ios::sync_with_stdio(false);
cin >> n ;
dfs(0 , 31 , 1 , 1 );
cout << nu <<"\n";
//cout << mas << "\n";
return 0 ;
}