[Bzoj 2154] Crash's digital table

Source: Internet
Author: User

2154:crash Digital Table Time limit:20 Sec Memory limit:259 MB
submit:1337 solved:531
[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≤107.
Hintsource

Arithmetical

Exercises

Multiply with Möbius (the solving algorithm is omitted to take modulo operation)

Set sum2 (i) =i* (i+1)/2

Set function sum (i,j) =sum2 (i) *sum2 (j)

So, Ans=sigma (d=1 to Min (n,m)) sum (n/d,m/d) * (Sigma (i| D) Di*mu[i])

(This can be pushed out)

And then, Ysy gathered to tell me one way:

Number of linear sieve sieve, record I minimum prime factor is mz[i]

Then, set F[d] to (Sigma (i| D) Di*mu[i]), then,

F [D]=f[d/mz[i]] (Mz[i/mz[i]]==mz[i])

f[d]=f[d/mz[i]]* (1-mz[i]) (ELSE)

Then, you can process it within O (n) time

You can use the prefix and maintenance f to finish processing within O (sqrt N)

What needs to be emphasized is the!!!!!!!

Brackets, curly braces!! Long, long long!!!.

WA was 10 times, and the accuracy exploded.

The first is sum, can't connect 3 times!!

A long long cast must be placed inside!

Alas, Ysy once a, I wa 10 times, TAT

1#include <bits/stdc++.h>2 using namespacestd;3 intprime[1000010];4 inttot,mz[10000010];5 intf[10000010],n,m;6 Long Longans;7 Const intMod=20101009;8 Long LongSumintKiintkj) {9     return((((Long Long) ki* (ki+1)/2) * ((%MOD) * ((Long Long) kj* (kj+1)/2) (%mod))%MoD;Ten } One intMain () { A     //freopen ("A.out", "w", stdout); -scanf"%d%d",&n,&m); -     if(n>m) { the         intt=N; -n=m; -m=T; -     } +      for(intI=2; i<=n;++i) { -         if(!Mz[i]) { +prime[++tot]=i; Amz[i]=i; at         } -          for(intj=1; j<=tot&&i*prime[j]<=n;++j) { -mz[i*prime[j]]=Prime[j]; -             if(i%prime[j]==0) Break; -         } -     } in     //for (int i=1;i<=tot;++i) cout<<prime[i]<<endl; -     //for (int i=1;i<=n;++i) cout<<mz[i]<<endl; tof[1]=1; +      for(intI=2; i<=n;++i) -         if(Mz[i/mz[i]]==mz[i]) f[i]=f[i/mz[i]]%MoD; the         ElseF[i]= ((Long Long) (F[i/mz[i]]* (1-mz[i]))%MoD; *      for(intI=1; i<=n;++i) ans= (ans+ (SUM (n/i,m/i) * ((Long Long) (F[i]*i)) (%mod)))%MoD; $printf"%lld\n", (ans%mod+mod)%MoD);Panax Notoginseng     return 0; -}
View Code

[Bzoj 2154] Crash's digital table

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.