根据反素数的性质,dfs就好了 反素数讲解:http://blog.csdn.net/ACdreamers/article/details/25049767
#include <bits/stdc++.h> using namespace std; typedef unsigned long long ULL; const ULL INF = ~0ULL; int p[16] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53}; int best; ULL n,res; void dfs(int dept, int limit, ULL tmp, int num) { if(tmp > n) return; if(num > best) { best = num; res = tmp; } if(num == best && tmp < res) res = tmp; for(int i = 1; i <= limit; ++i) { if(n/p[dept] < tmp) break; dfs(dept+1,i,tmp*=p[dept],num*(i+1)); } } int main() { int T; cin >> T; while(T--) { cin >> n; res = INF; best = 0; dfs(0,60,1,1); cout << res << " " << best << endl; } return 0; }