Bzoj2154 Crash numeric table

Source: Internet
Author: User
Tags cmath

Bzoj2154 Crash numeric table

2154: Crash digital table Time Limit: 20 SecMemory Limit: 259 MB
Submit: 2200 Solved: 824
[Submit] [Status] [Discuss] Description

In today's mathematics class, Crash learned the Least Common Multiple (Least Common Multiple ). For two integers a and B, LCM (a, B) indicates the smallest positive integer that can be divisible by both a and B. For example, LCM (6, 8) = 24. When I got home, Crash was still thinking about what I went to school. In order to study the least common factor, he drew a N * M table. A number is written in each grid, and the number in the grid in column j of row I is 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 4 20 looking at this table, crash thinks of many questions that can be considered. However, the problem he most wants to solve is a very simple one: what is the sum in this table. When N and M are big, Crash will be helpless, so he finds the smart one and uses the program to help him solve this problem. Since the final result may be very large, Crash only wants to know the values of all numbers in the table and mod 20101009.

Input

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

Output

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

Sample Input4 5
Sample Output122
[Data scale and Conventions]
100% of the data is N, M ≤ 107.

 

 

 

 

#include
 
  #include
  
   #include
   
    #include
    
     #include
     
      #include#define F(i,j,n) for(int i=j;i<=n;i++)#define D(i,j,n) for(int i=j;i>=n;i--)#define ll long long#define maxn 10000005#define mod 20101009using namespace std;int cnt,mu[maxn],pri[maxn],sum[maxn];ll n,m,ans;bool mark[maxn];inline int read(){int x=0,f=1;char ch=getchar();while (ch<'0'||ch>'9'){if (ch=='-') f=-1;ch=getchar();}while (ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}return x*f;}inline void pre(){mu[1]=1;F(i,2,n){if (!mark[i]) pri[++cnt]=i,mu[i]=-1;for(int j=1;j<=cnt&&i*pri[j]<=n;j++){mark[i*pri[j]]=true;if (i%pri[j]==0){mu[i*pri[j]]=0;break;}else mu[i*pri[j]]=-mu[i];}}F(i,1,n) sum[i]=(sum[i-1]+(ll)i*i%mod*mu[i]%mod)%mod;}inline ll get(ll x,ll y){return (x*(x+1)/2%mod)*(y*(y+1)/2%mod)%mod;}inline ll calc(ll x,ll y){if (x>y) swap(x,y);ll ret=0;for(ll i=1,pos;i<=x;i=pos+1){pos=min(x/(x/i),y/(y/i));ret=(ret+(sum[pos]-sum[i-1])*get(x/i,y/i)%mod)%mod;}return ret;}int main(){n=read();m=read();if (n>m) swap(n,m);pre();for(ll i=1,pos;i<=n;i=pos+1){pos=min(n/(n/i),m/(m/i));ans=(ans+(i+pos)*(pos-i+1)/2%mod*calc(n/i,m/i)%mod)%mod;}printf("%lld",(ans+mod)%mod);return 0;}
     
    
   
  
 

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.