Bzoj 2693:jzptab [Momo inverse linear sieve]

Source: Internet
Author: User

2693:jzptabtime limit:10 Sec Memory limit:512 MB
submit:1194 solved:455
[Submit] [Status] [Discuss] Descriptioninputa positive integer t that represents the number of data groups

Next T line two positive integers per line represent N, M

Output

T line one integer per line indicates the result of Group I data

Sample Input

1

4 5
Sample Output122
HINT
T <= 10000
N, m<=10000000 as in the previous question, but multiple sets of data using a similar technique with bzoj2820, d=di changes the summation indicator so that sum can be advanced, and the remainder is processed by the prefix andHow to handle prefixes and: the approximate and also the integrable function of the integrable function, can be used linear sieveg[i]= approximate and d*i*mu[i]apparently g[p]=p* (1-p)G[i*p[j]] "when P[j]|i Mu[ii] II with P[J] is 0 can not be counted, so p[j] only in the remaining piece, that is, only d changed, so the total is p[j]*g[i]tried the method of enumerating multiples, T Summary: In fact, the two problems and the number of gcd=k two questions very much like, are the first question only ask one, the second question requires multiple, and then to rewrite the formula and then deal with the prefix and ...
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespaceStd;typedefLong Longll;Const intn=1e7+5, mod=100000009; inlineintRead () {CharC=GetChar (); intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; c=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; c=GetChar ();} returnx*F;}intn,m;BOOLNotp[n];intP[n];ll S[n],mu[n],g[n];voidsieve () {mu[1]=1; g[1]=1;  for(intI=2; i<n;i++){        if(!notp[i]) p[++p[0]]=i,mu[i]=-1, g[i]=i-(LL) i*i;  for(intj=1; j<=p[0]&&i*p[j]<n;j++){            intt=i*P[j]; Notp[t]=1; if(i%p[j]==0) {Mu[t]=0; G[t]= (G[i]*p[j])%MOD;  Break; } Mu[t]=-Mu[i]; G[t]= (G[i]*g[p[j]])%MOD; }    }         for(intI=1; i<n;i++) g[i]= (g[i]+g[i-1])%MOD; }inline ll S (ll X,ll y) {return((X* (x+1)/2)%mod) * ((y* (y+1)/2)%mod)%MOD;}intMain () {sieve (); intt=read ();  while(t--) {n=read (); M=read (); if(n>m) swap (N,M); ll ans=0, r=0;  for(LL d=1;D <=n;d=r+1) {R=min (n/(n/d), m/(m/D)); Ans= (Ans+s (n/d,m/d) * (g[r]-g[d-1]))%MOD; } printf ("%lld\n", (ans+mod)%MOD); }}

Bzoj 2693:jzptab [Momo inverse linear sieve]

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.