Bzoj 2301-mo

Source: Internet
Author: User
Tags greatest common divisor

For the given n queries, how many pairs (x, y) are asked each time , satisfy a≤x≤b, c≤y≤D, and gcd (x, y) = k, gcd (x,y) function x and the greatest common divisor of Y.

The topic here is very obvious.

for required f[n] = Sigma (A≤x≤b) Sigma (C≤y≤< Span lang= "en-us" >d) [gcd (x, y) =k] =  sigma (1≤x≤b)  sigma (1≤y≤d)  [gcd (x, y) =k] + sigma (1≤x≤ a-1)  sigma (1≤y≤c-1)  [gcd (x, y) =k]-  Sigma (1≤x≤a-1)  sigma (1≤y≤d) &NBSP;[GCD (x, y) =k]-  sigma (1≤x≤b)  sigma (1≤ y≤c-1)  [gcd (x, y) =k] 

For each g[n] = Sigma (1≤x≤a) sigma (1≤y≤c) [gcd (x, y) =k] = Sigma (1≤ x≤ a/k) Sigma (1≤y≤ c/k) [ GCD (x, y) =1] = Sigma (1≤x≤a/k) Sigma (1≤y≤c/k) Sigma (D|GCD (x, y)) mu[d] = Sigma (d) mu[d]*a/k/d*c/k/d

A/K/D*C/K/D This section of the interval can be added together to calculate the current value of the end is min (x/(x/i), y/(y/i))

Record the prefix of the Möbius function and update the entire interval so that the loop shrinks to the complexity of the sqrt (n)

1#include <bits/stdc++.h>2 using namespacestd;3 #definell Long Long4 #defineN 500005 intmu[n+Ten], prime[n+Ten], tot, sum[n+Ten];6 BOOLcheck[n+Ten];7 8 voidGet_mu ()9 {Tenmu[1] =1; One      for(intI=2; I<=n; i++){ A         if(!Check[i]) { -prime[tot++] =i; -Mu[i] =-1; the         } -          for(intj=0; J<tot; J + +){ -             if(LL) i*prime[j]>n) Break; -CHECK[I*PRIME[J]] =true; +             if(i%Prime[j]) { -MU[I*PRIME[J]] =-Mu[i]; +}Else  Break; A         } at     } -      for(intI=1; I<=n; i++) sum[i]=sum[i-1]+Mu[i]; - } -  - inta,b,c,d,k; -  in intSolveintXinty) - { toX/=k, y/=K; +     intmx = min (x, y), Len, ret=0; -      for(intI=1; I&LT;=MX; i=len+1) the     { *        //cout<<i<< "" <<ret<<endl; $len = min (x/(x/i), y/(y/i));Panax NotoginsengRET + = x/i* (y/i) * (sum[len]-sum[i-1]); -     } the     returnret; + } A  the intMain () + { -     //freopen ("In.txt", "R", stdin); $ Get_mu (); $     intT; -scanf"%d", &T); -      while(t--){ thescanf"%d%d%d%d%d", &a, &b, &c, &d, &k); -printf"%d\n", Solve (B,d) +solve (a1, C-1)-solve (A-1, d)-solve (b,c-1));Wuyi     } the     return 0; -}

Bzoj 2301-mo

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.