莫比乌斯反演 刷题记录

BZOJ1101: [POI2007]Zap

  • 题意:对于给定的整数a,b和d,求有多少正整数对x,y,满足x<=a,y<=b,并且gcd(x,y)=d
  • 直接求有多少正整数对x,y,gcd(x,y)=d比较难求,而且询问有50000个,


  • \begin{gather*}
    要求\ \ \ \ \ \ \ \ f( n) =\ \sum\nolimits ^{\ b}_{\ y=1} \ \ \sum\nolimits ^{\ a}_{\ x=1} \ [ \ gcd( x,y) =n\ ]\\
    \\
    则\ \ \ \ \ \ \ \ \ \ \ F( n) =\sum\nolimits ^{\ b}_{\ y=1}\sum\nolimits ^{\ a}_{\ x=1}\sum\nolimits _{\ n|gcd( x,y)} \ 1\\
    \\
    因为\ \ \ \ \ \ \ \sum\nolimits _{\ n|gcd( x,y)} 1=\sum\nolimits _{\ n|d} \ [ \ gcd( x,y) =d\ ]\\
    \\
    F( n) \ =\ \sum\nolimits _{\ n|d} \ \ f( d)\\
    \\
    然后就是莫比乌斯反演辣\\
    \\
    \end{gather*}

  • 代码:

猜你喜欢

转载自www.cnblogs.com/jiecaoer/p/11586397.html