数论 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 + 5; const double PI = acos(-1.0); typedef long long ll; typedef unsigned long long ull; using namespace std; //若取前17个素数,其乘积大于要求范围 ull p[16] = { 2,3,5,7,11,13,17,23,29,31,37,41,43,47,53 }; ull ans; ull n; //depth 当前在枚举第几个素数,num:当前因子数 //tmp:当前因子数量为num的时候的数值 //up:上一个素数的幂,这次应该小于等于这个幂次 void dfs(ull depth, ull tmp, ull num, ull up) { if (num > n || depth >= 16) return; if (num == n && ans >= tmp) { ans = tmp; return; } for (int i = 1; i <= up; i++) { if (tmp / p[depth] > ans) return; dfs(depth + 1, tmp = tmp * p[depth], num * (i + 1), i); } } int main() { while (scanf("%llu", &n) != EOF) { ans = INF; dfs(0, 1, 1, 64); printf("%llu", ans); } return 0; }