51nod1060(反素数&dfs)

题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1060

题意:中文题诶~

思路:

  这里用到了反素数的性质:

  对于任何正整数x,其约数的个数记做g(x).例如g(1)=1,g(6)=4.如果某个正整数x满足:对于任意i(0 < i < x),都有g(i) < g(x),则称x为反素数。

  性质:

  No.1 一个反素数的质因子必然是从2开始连续的质数。 

  No.2 p=2^t1*3^t2*5^t3*7^t4…..必然t1>=t2>=t3>=…. 

  然后按照性质dfs就好啦

代码:

 1 #include <bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 
 5 ll dir[]={2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59};
 6 ll x, gg=1, cc=1;
 7 
 8 void dfs(ll ans, ll cnt, int num, int b_num){//ans表当前积, cnt表当前可能总数, num表当前深度, b_num表上一个因子的个数
 9     if(ans<x){
10         if(gg<cnt){
11             gg=cnt;
12             cc=ans;
13         }else if(gg==cnt&&ans<cc){
14             cc=ans;
15         }
16         for(int i=1; i<=b_num; i++){
17             if(ans<=x/dir[num]){ //**如果用乘判断的话可能爆long long
18                 ans*=dir[num];
19                 dfs(ans, cnt*(i+1), num+1, i);
20             }else{
21                 break;
22             }
23         }
24     }
25 }
26 
27 int main(void){
28     ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
29     int t;
30     cin >> t;
31     while(t--){
32         cin >> x;
33         cc=1, gg=1;
34         dfs(1, 1, 0, 10);
35         cout << cc << " " << gg << endl;
36     }
37     return 0;
38 }
原文地址:https://www.cnblogs.com/geloutingyu/p/6476153.html