Luo Gu P1463 solution to a problem

Topic links: https://www.luogu.com.cn/problem/P1463

First of all, we see a problem, you know a few essay questions, first a square mouth Hu violence, because the road is the provincial topics, not too sure.

By meter? Estimated to run more than a decade. .

Assume x is a number from about a, a definitely less than equal to the square root of x, can be determined because the number of other about x / a, then x is about Laid judged when the number of the square, so we double loop, each x under heavy cycle root, the time complexity of O (n).

While thinking is accurate, a look at the data range, 2e9, vomiting blood on the spot.

O (logn) algorithm? Fast power? Dichotomy? You kidding me?

O (1) algorithm? Obviously, this question is seeking an interval (1 ~ n) of the maximum qualified, the answer can not add Save subtraction.

Obviously, this question time complexity and n does not matter.

Thinking about a number of numbers is how come.

This set number is x, then x = p1 ^ k1 * p2 ^ k2 * ... * pn ^ kn, the number is approximately the number (k1 + 1) * (k2 + 1) * ... * (kn + 1 ) to prove it, the principle of multiplication, step by step multiplied.

Here the number of columns p is a prime number and monotonically increased.

Let k number of columns as large as possible, we should let p columns as small as possible, we can boldly guess: p columns just take the first few prime numbers, as for the first few, practice makes perfect = =

and then? K enumerate the number of columns. . (In fact, this is a search problem, not the number of topics

Well, put the code:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int sum[20]={0,2,3,5,7,11,13,17,19,23,29,31,33};//素数表
 4 long long n,ans,qwq;
 5 void dfs(long long x,long long y,long longz) {// x represents subscript array sum, y is the current number, z is the number of divisors
 . 6      IF (Z> qwq) {
 . 7          qwq = Z;
 . 8          ANS = Y;
 . 9      }
 10      IF (Z == qwq && ANS > Y) ANS = Y;
 . 11      IF (X> . 11 ) return ;
 12 is      for ( Long  Long I = . 1 ; I <= n-; ++ I) {
 13 is          IF (Y * SUM [X]> n-) return ;
 14          DFS (X + . 1 , Y * SUM [X], Z * (I + . 1 ));
 15          Y * = SUM [X];
16     }
17 }
18 signed main(){
19     cin>>n;
20     dfs(1,1,1);
21     cout<<ans<<endl;
22     return 0;
23 }

This will certainly make progress after the title just to get started will certainly look ignorant, do a certain topic.

Codeword is not easy, point a praise it QwQ

Guess you like

Origin www.cnblogs.com/-YueYang-/p/12625810.html