"BZOJ3529" [Sdoi2014] tables of the MO-colorimetric inversion + tree-like array

Source: Internet
Author: User
Tags gcd

"BZOJ3529" [Sdoi2014] Tables description

There is a table of NXM, and the number of rows J (1 < =i < = Lilly, 1 < =j < =m) of the first row is the sum of all the natural numbers that can be divisible by both I and J. Given a, the sum of the numbers in the calculation tables is not much more than a.

Input

The input contains multiple sets of data.
The first line of input, an integer q, represents the number of data groups in the test point, and the next Q row, three integers per line n,m,a (|a| < =10^9) describes a set of data.

Output

For each set of data, the output is an integer that represents the value of the answer modulus 2^31.

Sample Input2
4 4 3
10 10 5
Sample Output20
148HINT

1 < =n. M < =10^5, 1 < =q < =2x10^4

The first thing we need to know is the approximate number and the nloglogn level, so we do not consider the limitation of a, we still use the familiar Möbius inversion.

$ans =\sum\limits_{i=1}^n\sum\limits_{j=1}^nf (GCD (i,j)) \\=\sum\limits_{d=1}^nf (d) \sum\limits_{i=1}^{\lfloor \ Frac n d \rfloor}\sum\limits_{j=1}^{\lfloor \frac m D \rfloor} [gcd (I,j) ==1]\\=\sum\limits_{d=1}^nf (d) \sum\limits_{e=1 }^{\lfloor \frac n d \rfloor}\mu (e) \lfloor \frac n {de} \rfloor \lfloor \frac m {de} \rfloor\\=\sum\limits_{d=1}^{n}\sum\ limits_{d| D}f (d) \mu (\frac D d) \lfloor \frac n {d} \rfloor \lfloor \frac m {d} \rfloor$

So what if we consider the limits of a? We take all the inquiries offline, sort by a, and process all the inquiries from small to large, and each processing to a query will count the contributions of all F (d) <=a D. That is to say, we need to use a data structure to maintain F*MU prefixes and tree-like arrays.

#include <cstdio> #include <cstring> #include <iostream> #include <algorithm>using namespace std;const int n=100000;typedef unsigned int ui;int pri[n/10];ui mu[n+10],f[n+10],s[n+10],ans[n];int q[N+10];int Num,Q; BOOL Np[n+10];struct node{int n,m,a,org;} p[n];inline Int Rd () {int Ret=0,f=1;char gc=getchar (); while (gc< ' 0 ' | | Gc> ' 9 ') {if (gc== '-') F=-f;gc=getchar ();} while (gc>= ' 0 ' &&gc<= ' 9 ') ret=ret*10+ (gc^ ' 0 '), Gc=getchar (); return ret*f;} BOOL CMP (const node &AMP;A,CONST node &b) {return A.A&LT;B.A;} BOOL CMPQ (const int &a,const int &b) {return f[a]<f[b];} inline void updata (int x,ui val) {for (int i=x;i<=n;i+=i&-i) S[i]+=val;} Inline UI query (int x) {UI ret=0;for (int i=x;i;i-=i&-i) ret+=s[i];return ret;} int main () {int i,j,k,last;mu[1]=1;for (i=2;i<=n;i++) {if (!np[i]) pri[++num]=i,mu[i]=-1;for (j=1;j<=num& &i*pri[j]<=n;j++) {np[i*pri[j]]=1;if (i%pri[j]==0) break;mu[i*pri[j]]=-mu[i];}} for (i=1;i<=n;i++) for (j=i;j<=n;j+=i) f[j]+=i;for (i=1;i<=n;i++) q[i]=i; Q=rd (); for (i=1;i<=q;i++) {p[i].n=rd (), P[i].m=rd (), p[i].org=i;if (P[I].N&GT;P[I].M) Swap (P[I].N,P[I].M);p [i].a= Max (RD (), 0);} Sort (Q+1,Q+N+1,CMPQ), sort (p+1,p+q+1,cmp), for (i=j=1;i<=q;i++) {for (; f[q[j]]<=p[i].a;j++) for (k=q[j];k<=n ; K+=q[j]) Updata (K,f[q[j]]*mu[k/q[j]); for (k=1;k<=p[i].n;k=last+1) {last=min (p[i].n/(p[i].n/k), p[i].m/(p[i].m /k) ans[p[i].org]+= (p[i].n/k) * (p[i].m/k) * (query (last)-query (k-1));}} for (i=1;i<=q;i++) printf ("%u\n", ANS[I]&AMP;0X7FFFFFFF); return 0;}

"BZOJ3529" [Sdoi2014] tables of the MO-colorimetric inversion + tree-like array

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.