BZOJ2005: [Noi2010] Another method of energy harvesting for the inverse of the--nlogn sieve

Source: Internet
Author: User


Note: Two points have been harvested from this question

1, the number of the hour on the first quadrant (x, y) to (0,0) line is gcd (x, y)

2, the newly learned gcd (x, y) =k How many pairs of posture, known 0<x<=n,0<y<=m

Make X=min (n,m), so f[i] represents the logarithm of gcd (x, y) =i,

Then the complexity of O (XLOGX) can be obtained f[1] to F[n] (reverse loop)

Ordinary Möbius (ie, inversion) is actually O (XLOGX), just need to sift through the Möbius function

Summary: For a single gcd (x, y) =k logarithm, can be done with Möbius inversion, such complexity is O (n/k)

For gcd (x, y) = (1,.. n) logarithm, each solved separately, directly with such O (NLOGN) sieve method is good, save code, fortunately write

#include <cstdio>#include<cstring>#include<queue>#include<cstdlib>#include<algorithm>#include<vector>#include<cmath>using namespaceStd;typedefLong LongLL;Const intn=1e5+5;Const intinf=0x3f3f3f3f; LL F[n];intMain () {LL N,m,ans=0; scanf ("%lld%lld",&n,&m); if(n>m) swap (N,M);  for(inti=n;i>=1;--i) {F[i]=n/i* (m/i);  for(intj=i+i;j<=n;j+=i) f[i]-=F[j]; Ans+=f[i]* (2*i-1); } printf ("%lld\n", ans); return 0;}
View Code

BZOJ2005: [Noi2010] Another method of energy harvesting for the inverse of the--nlogn sieve

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: 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.