Bzoj 2154:crash's digital table [MO-Black inversion]

Source: Internet
Author: User

2154:crash Digital Table Time limit:20 Sec Memory limit:259 MB
submit:2924 solved:1091
[Submit] [Status] [Discuss] Description

Today's math class, crash children learn least common multiple (Least Common multiple). For two positive integers a and B,LCM (A, b) represent the smallest positive integers that can be divisible by A and b at the same time. For example, the LCM (6, 8) = 24. Back home, crash still thinking about class school, in order to study least common multiple, he drew a n*m form. A number is written in each lattice, where the lattice in column J of Row I is written in the LCM (i, J). A 4*5 table is as follows: 1 2 3 4 5 2 2 6 4 10 3 6 3 12 15 4 4 12 4 20 Looking at this form, crash thought of a lot of things to think about. But the question he most wants to solve is a very simple question: how much is there in this table? When N and M are big, crash is helpless, so he finds the smart you use the program to help him solve the problem. Since the end result can be large, crash only wants to know the values of all the numbers in the table and mod 20101009.

Input

The first line of input contains two positive integers, representing N and M., respectively.

Output

Outputs a positive integer that represents the number of values in the table and mod 20101009.

Sample Input4 5
Sample Output122
"Data size and conventions"
100% of the data satisfies N, m≤10^7.
calculates the and of all LCM (I,J)
 consider the value of each GCD, then you can getans=σ{d=1...min (n,m)}f (n,m,d)/d further overwrites convenient chunking  (reason: Consider all gcd (i,j) =k I and J are ii*k and Jj*k and gcd (II,JJ) =1)The problem is solving the F function and discovering the F function and the " bzoj2301 "
    • F (i) is 1<=x<=n,1<=y<=m and gcd (x, y) =i number of pairs (x, y)
"Very much like, this is not the number but the i*j, and the same consideration of the MO-Ufa inversion construct F (x,y,k) for the i*j of K|GCD (I,J) and find a way to calculate directly f  (Reason: K|GCD (i,j)--all multiples of k) Momo inversion  the part that ANS needs is  we found that part of the ANS can be sqrt (n) blocks with F, and can be sqrt (n) blocks (processing mu[i]*i*i prefixes and) in a total O (n )Experience:need F (x,y,1) When you think about it, don't just think about 1, that's not good.Note:prefix and want to use LL, however the topic int also no problem
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespaceStd;typedefLong Longll;Const intn=1e7+5, mod=20101009; 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];voidSieveintN) {mu[1]=1;  for(intI=2; i<=n;i++){        if(!notp[i]) p[++p[0]]=i,mu[i]=-1;  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;  Break; } Mu[t]=-Mu[i]; }    }     for(LL i=1; i<=n;i++) S[i]= (s[i-1]+ (I*i*mu[i])%mod)%MOD;} inline ll S (ll X,ll y) {return((X* (x+1)/2)%mod) * ((y* (y+1)/2)%mod)%MOD;} ll F (ll N,ll 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[r]-s[d-1]) *s (n/d,m/d)%mod)%MOD; }    returnans;}intMain () {n=read (); M=read ();    Sieve (n); 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+f (n/d,m/d) * ((r-d+1) * (R+D)/2)%mod)%MOD; } printf ("%lld", (ans+mod)%MOD);}

Bzoj 2154:crash's digital table [MO-Black inversion]

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.