PoPoQQQ讲义第4题

  题解:http://www.cnblogs.com/jianglangcaijin/archive/2013/11/27/3446169.html

 

  感觉两次sqrt(n)的枚举是亮点……

RE:汗- -b 10^7是8位数,开数组少打了一个0……

 1 /**************************************************************
 2     Problem: 2154
 3     User: Tunix
 4     Language: C++
 5     Result: Accepted
 6     Time:8780 ms
 7     Memory:167292 kb
 8 ****************************************************************/
 9  
10 //BZOJ 2154
11 #include<cstdio>
12 #include<cstdlib>
13 #include<cstring>
14 #include<iostream>
15 #include<algorithm>
16 #define rep(i,n) for(int i=0;i<n;++i)
17 #define F(i,j,n) for(int i=j;i<=n;++i)
18 #define D(i,j,n) for(int i=j;i>=n;--i)
19 using namespace std;
20  
21 int getint(){
22     int v=0,sign=1; char ch=getchar();
23     while(ch<'0'||ch>'9') {if (ch=='-') sign=-1; ch=getchar();}
24     while(ch>='0'&&ch<='9') {v=v*10+ch-'0'; ch=getchar();}
25     return v*=sign;
26 }
27 /*******************tamplate********************/
28 const int N=10000086,P=20101009;
29 typedef long long LL;
30 LL prime[N],mu[N];
31 bool check[N];
32 LL n,m;
33 void getmu(int n){
34     int tot=0;
35     mu[1]=1;
36     for(int i=2;i<n;i++){
37         if (!check[i]){
38             prime[tot++]=i;
39             mu[i]=-1;
40         }
41         rep(j,tot){
42             if (i*prime[j]>n) break;
43             check[i*prime[j]]=1;
44             if (i%prime[j]) mu[i*prime[j]]=-mu[i];
45             else{
46                 mu[i*prime[j]]=0;
47                 break;
48             }
49         }
50     }
51     F(i,1,n) mu[i]=(mu[i-1]+mu[i]*i%P*i%P)%P;
52 }
53 inline LL Sum(LL n,LL m){
54     n=n*(n+1)/2%P;
55     m=m*(m+1)/2%P;
56     return n*m%P;
57 }
58 inline LL f(LL n,LL m){
59     LL ans=0,i,last;
60     for(i=1;i<=n;i=last+1){
61         last=min(n/(n/i),m/(m/i));
62         ans=(ans+(mu[last]-mu[i-1])%P*Sum(n/i,m/i)%P)%P;
63     }
64     return ans;
65 }
66 int main(){
67 //  freopen("input.txt","r",stdin);
68     n=getint(); m=getint();
69     if(n>m) swap(n,m);
70     getmu(m);
71     LL ans=0,i,last;
72     for(i=1;i<=n;i=last+1){
73         last=min(n/(n/i),m/(m/i));
74         ans=(ans+(i+last)*(last-i+1)/2%P*f(n/i,m/i)%P)%P;
75     }
76     if (ans<0) ans+=P;
77     printf("%lld\n",ans);
78     return 0;
79 }
View Code

相关文章:

  • 2021-11-16
  • 2021-06-16
  • 2021-12-07
  • 2021-08-03
  • 2021-09-13
  • 2021-09-21
  • 2021-09-20
  • 2021-08-30
猜你喜欢
  • 2021-12-03
  • 2021-11-28
  • 2021-11-02
  • 2022-02-16
  • 2021-07-07
  • 2021-12-18
  • 2022-02-07
相关资源
相似解决方案