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.

45 lines
1.8 KiB

This file contains ambiguous Unicode characters!

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;
}