[DFS] BZOJ1053: [HAOI2007] Inverse prime ant__ Search

Source: Internet
Author: User
the

For any positive integer x, the number of divisors is g (x). For example G (1) =1,g (6) = 4.
If a positive integer x is satisfied: g (x) >g (i) (0 < i < x) is called an inverse prime number.
Now given a number n, ask for no more than N of the largest inverse prime.
(n<=2000000000) Solving

We must first observe some conclusions.
In fact, we do not really verify that a certain number is the inverse prime, consider the problem requires the largest 1~n, it is clear that the number of the answer to the number of 1~n is the largest, if there are more than the number of the approximate number of the same, the answer is the smallest one.
So what we're asking for is the optimal number under the above rules.
How to calculate "excellent".
1. More than a few.
2. The smaller the number is, the better.
The approximate number of numbers is generally decomposed into pk11∗pk22∗...pkmm (P1<P2<P3...<PM) p_1^{k_1}*p_2^{k_2}*...p_m^{k_m} (P1<><>
Then the approximate number is (k1+1) ∗ (k2+1) ∗ ... (km+1) (k_1+1) * (k_2+1) * ... (k_m+1)
After observation, it is found that the possible inverse prime of the Ki k_i must be monotonous.
Suppose there is a PI<PJ p_i after a number is decomposed
With the above conclusion, we can have DFS. <>

 #include <cstdio> #include <cstring> using namespace std; typedef long LL;
LL N,ans1,ans2;
LL p[15]={11,2,3,5,7,11,13,17,19,23,29,31}; void Dfs (int step,ll res1,ll Res2,ll last) {if (step>p[0]) {if (res2>ans2| | (RES2==ANS2&&RES1<ANS1))
        {ans1=res1;ans2=res2;}
    Return
For (LL I=0,now=1;i<=last&&res1*now<=n;i++,now*=p[step]) Dfs (step+1,res1*now,res2* (i+1), i);
    int main () {freopen ("bzoj1053.in", "R", stdin);
    Freopen ("Bzoj1053.out", "w", stdout);
    scanf ("%lld", &n);
    DFS (1,1,1,20);
    printf ("%lld\n", ans1);
return 0; }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.