反素数
定义
满足任何小于 \(n\) 的正数的约数个数都小于 \(n\) 的约数个数的正整数 \(n\)
最小的因子数为 \(n\) 的数
以因子数个数为返回条件,dfs
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll p[20] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 };
ll n, ans;
//dep:正在枚举第几个素数 num:当前因子数
//tmp:当前数值 up:上一个素数的个数
void dfs(ll dep, ll tmp, ll num, ll up) {
if(num > n or dep >= 16) return;
if(num == n and ans > tmp) { ans = tmp; return; }
for(int i = 1; i <= up; i ++) {
if(tmp / p[dep] > ans) break;
dfs(dep + 1, tmp *= p[dep], num * (i + 1), i);
}
}
int main() {
while(~scanf("%llu", &n)) {
ans = ~0ull;
dfs(0, 1, 1, 64);
cout << ans << "\n";
}
return 0;
}
\(n\) 以内因子数最多的数
打表什么的最棒了
改一改上面的dfs的返回条件就行了
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll p[20] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53 };
ll n, ans, anu; //ans为最大反素数,anu为ans的因子数
void dfs(ll dep, ll tmp, ll num, ll up) {
if(tmp > n or dep >= 16) return;
if(num > anu) ans = tmp, anu = num;
if(num == anu and ans > tmp) ans = tmp;
for(int i = 1; i <= up; i ++) {
if(tmp * p[dep] > n) break;
dfs(dep + 1, tmp *= p[dep], num * (i + 1), i);
}
}
int main() {
cin >> n;
dfs(0, 1, 1, 64);
cout << ans;
return 0;
}
end.
而我们终其一生,都希望能成为更好的人。