数论 CF27E Number With The Given Amount Of Divisors

求因子数一定的最小数(反素数)

#include<iostream>
#include<string>
#include<cmath>
#include<cstring>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<queue>
#include<stack>
#include<list>
#include<sstream>
#include<cstdio>
#define INF 0x3f3f3f3f
const int maxn = 1e3 + ;
const double PI = acos(-1.0);
typedef long long ll;
typedef unsigned long long ull;
using namespace std; //若取前17个素数,其乘积大于要求范围
ull p[] = { ,,,,,,,,,,,,,, }; ull ans;
ull n; //depth 当前在枚举第几个素数,num:当前因子数
//tmp:当前因子数量为num的时候的数值
//up:上一个素数的幂,这次应该小于等于这个幂次 void dfs(ull depth, ull tmp, ull num, ull up) {
if (num > n || depth >= ) return;
if (num == n && ans >= tmp) {
ans = tmp;
return;
}
for (int i = ; i <= up; i++) {
if (tmp / p[depth] > ans) return;
dfs(depth + , tmp = tmp * p[depth], num * (i + ), i);
}
} int main() {
while (scanf("%llu", &n) != EOF) {
ans = INF;
dfs(, , , );
printf("%llu", ans);
}
return ;
}
上一篇:orace函数


下一篇:玩转 Ceph 的正确姿势