"Bzoj1101-[poi2007]zap inversion + chunking"

Source: Internet
Author: User

"The main topic"

For a given integer, a, B, and D, how many positive integers to X, y, meet X<=a,y<=b, and gcd (x, y) =d.

Ideas

The idea of the front with HDU1695

However, the difference is that the problem (a, B) and (B,a) count as the same situation, do not need to subtract from the duplication of the situation.

This problem uses chunking to speed up efficiency. We can notice that the same, B ' (b '/i) B means the same as the current quotient of the last [B '/d],d ' (d '/i), POS is the smaller of the two. We preprocess Miu's prefix and can be the same as * (Sum[pos]-pos[k-1])!

?? Bzoj must use Printf%lld,cout will re??

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6typedefLong Longll;7 Const intmaxn=50000+ -;8 Const intinf=0x7ffffff;9 inta,b,d;Ten intMIU[MAXN]; One intMIU_SUM[MAXN]; A  - voidGet_miu (intMAXN) - { the     intprime[maxn],pnum=0; -memset (Miu_sum,0,sizeof(Miu_sum)); -miu[1]=miu_sum[1]=1; -      for(intI=2; i<maxn;i++) miu[i]=-INF; +      for(intI=2; i<maxn;i++) -     { +         if(miu[i]==-INF) A         { atmiu[i]=-1; -prime[++pnum]=i; -         } -          for(intj=1; j<=pnum;j++) -         { -             if(I*PRIME[J]&GT;=MAXN) Break; in             if(i%prime[j]==0) miu[i*prime[j]]=0; -                 Elsemiu[i*prime[j]]=-Miu[i]; to         } +miu_sum[i]=miu_sum[i-1]+Miu[i]; -     } the } *  $ll Get_ans (intAintBintd)Panax Notoginseng { -     intub=min (A, b), POS; thell ans=0; +      for(intI=1; i<=ub;i=pos+1) A     { thePos=min (A/(a/i), b/i)); +ans+= (LL) (miu_sum[pos]-miu_sum[i-1]) * (a/i) * (b/i); -     } $     returnans; $ } -  - intMain () the { -     intT;Wuyiscanf"%d",&T); theGet_miu (maxn-1);  -      for(intI=0; i<t;i++) Wu     { -scanf"%d%d%d",&a,&b,&d); AboutA/=d;b/=D; $printf"%lld\n", Get_ans (a,b,d)); -     } -}

"Bzoj1101-[poi2007]zap inversion + chunking"

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.