Top technology-crazy prefix and

Source: Internet
Author: User

\ [\ Sum _ {k = 1} ^ n f_k \]

Obviously, this item can be \ (O (n) \) and cannot be optimized.

But there are still faster algorithms in this universe ......

Order \ [g_n = \ sum _ {d | n} f_d, f_n = \ sum _ {k = 1} ^ {n} f_k \]

Because \ [\ sum _ {k = 1} ^ n G_k = \ sum _ {k = 1} ^ n {f_k \ lfloor \ frac NK \ rfloor} = \ sum _{ k = 1} ^ n f _ {\ lfloor \ frac NK \ rfloor} \]

\ [F_n = \ sum _ {k = 1} ^ n G_k-\ sum _ {k = 2} ^ n f _ {\ lfloor \ frac NK \ rfloor }\]

If \ (\ sum _ {k = 1} ^ n G_k \) can be obtained within \ (O (\ SQRT {n \), then \ (f (n) \) can be calculated in \ (O (N ^ \ frac 34 )\).

\ (\ Sum _ {k = 1} ^ n G_k \) for some special \ (G_k \) can be very fast, for example \ [\ sum _ {k = 1} ^ n \ sum _ {d | K} \ Mu (d) = 1 \] \ [\ sum _ {k = 1} ^ n \ sum _ {d | K} \ PHI (d) = \ sum _ {k = 1} ^ n k = \ frac {n (n + 1)} {2} \]

If \ (g_n \) can be quickly computed, then \ (n \ Leq n ^ \ frac 23 \) linear brute force calculation \ (f_n \) can be performed. Otherwise, recursive calculation is performed, \ (O (N ^ \ frac 23 )\).

Related Article

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.