You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
# define endl "\n"
# define int long long
const int N = 2e9 ;
int n ;
int primes [ 9 ] = { 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 } ; // 枚举的质数前9位, 足够了
int mc , mx ; // 最大反素数的约数个数,最大反素数值
/*
u:走到数组primes的第几位
last:前一个质数, 我们取的指数是多少, 当前位置取的质数的指数需要小于等于last
tmx: 当前路线上取得的最大反素数
tmc: 当前路线上取得的约数个数
*/
void dfs ( int u , int last , int tmx , int tmc ) {
if ( u = = 9 ) { // 走完全程
// ① 当前路径中约数个数大于最大约数个数,需要替换
// ② 当前路径中的约数个数等于最大约数个数,但是,当前路径的数值更小,也需要替换
if ( tmc > mc | | ( tmc = = mc & & tmx < mx ) )
mc = tmc , mx = tmx ;
return ;
}
for ( int i = 0 ; i < = last ; i + + ) { // 幂次只能是小于等于前一个数的幂次
int k = pow ( primes [ u ] , i ) ;
if ( k * tmx > n ) break ; // 如果取当前这个素数的i次方, 乘到原来的最大值后, 大于n, 那么此路径不通
/*
u+1:下一个素数位置
i: 当前u这个素数取了i次幂
tmx*k : 因为取了i次幂, 所以, 最大值变大了k倍
tmc*(i+1) : 根据约数个数公式,因为有了质数 primes[u]后, 取了i次幂, 那么约数和增加(i+1)倍
*/
dfs ( u + 1 , i , tmx * k , tmc * ( i + 1 ) ) ;
}
}
signed main ( ) {
cin > > n ;
dfs ( 0 , 30 , 1 , 1 ) ; // 从最小的质数2出发, 最大的幂次不超过30
// n的最小取值是1, 也就是小于等于1的范围内, 最小的反素数是1, 而且, 约数的个数也是1
cout < < mx < < endl ;
}