找到最小的约数最多的。
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 using namespace std; 5 #define LL __int64 6 LL ans,res,n; 7 int prime[16] = {1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47}; 8 //当前枚举到的数;枚举到的第K大的质因子;该数的约数个数;质因子个数上限。 9 void dfs(LL num,LL k,LL sum,int limit) 10 { 11 LL temp; 12 int i; 13 if(res < sum) 14 { 15 res = sum; 16 ans = num; 17 } 18 if(res == sum&&ans > num) 19 ans = num; 20 if(k > 15) return ; 21 temp = num; 22 for(i = 1;i <= limit;i ++) 23 { 24 if(prime[k]*temp > n) break ; 25 temp = prime[k]*temp; 26 dfs(temp,k+1,sum*(i+1),i); 27 } 28 } 29 int main() 30 { 31 int cas,nn = 1; 32 scanf("%d",&cas); 33 while(cas--) 34 { 35 res = -1; 36 ans = -1; 37 scanf("%I64d",&n); 38 dfs(1,1,1,50); 39 printf("Case #%d: %I64d\n",nn++,ans); 40 } 41 return 0; 42 }