首页 > 代码库 > BZOJ2693: jzptab

BZOJ2693: jzptab

题目:http://www.lydsy.com/JudgeOnline/problem.php?id=2693

题意:同2154 多组数据

题解:按2154再往后转化一下就可以把n,m放到一边儿,然后线性筛右边。

          硬要看推导的话可以戳:http://blog.csdn.net/popoqqq/article/details/42078725

          不会latex感觉跟不上时代了T_T

           还有此题模数真是坑爹

代码:

技术分享
  1 #include<cstdio>  2   3 #include<cstdlib>  4   5 #include<cmath>  6   7 #include<cstring>  8   9 #include<algorithm> 10  11 #include<iostream> 12  13 #include<vector> 14  15 #include<map> 16  17 #include<set> 18  19 #include<queue> 20  21 #include<string> 22  23 #define inf 1000000000 24  25 #define maxn 10000000+5 26  27 #define maxm 10000000 28  29 #define eps 1e-10 30  31 #define ll long long 32  33 #define pa pair<int,int> 34  35 #define for0(i,n) for(int i=0;i<=(n);i++) 36  37 #define for1(i,n) for(int i=1;i<=(n);i++) 38  39 #define for2(i,x,y) for(int i=(x);i<=(y);i++) 40  41 #define for3(i,x,y) for(int i=(x);i>=(y);i--) 42  43 #define for4(i,x) for(int i=head[x],y=e[i].go;i;i=e[i].next,y=e[i].go) 44  45 #define for5(n,m) for(int i=1;i<=n;i++)for(int j=1;j<=m;j++) 46  47 #define mod 100000009 48  49 using namespace std; 50  51 inline int read() 52  53 { 54  55     int x=0,f=1;char ch=getchar(); 56  57     while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();} 58  59     while(ch>=0&&ch<=9){x=10*x+ch-0;ch=getchar();} 60  61     return x*f; 62  63 } 64 int tot,p[maxn],mu[maxn]; 65 bool v[maxn]; 66 void get() 67 { 68     mu[1]=1; 69     for2(i,2,maxm) 70     { 71         if(!v[i])p[++tot]=i,mu[i]=(i-(ll)i*i)%mod; 72         for1(j,tot) 73         { 74             int k=i*p[j]; 75             if(k>maxm)break; 76             v[k]=1; 77             if(i%p[j])mu[k]=(ll)mu[p[j]]*mu[i]%mod; 78             else {mu[k]=(ll)p[j]*mu[i]%mod;break;} 79         } 80     } 81     for1(i,maxm)mu[i]=(mu[i]+mu[i-1])%mod; 82 } 83 inline int sum(int n,int m) 84 { 85     return ((ll)n*(n+1)/2%mod)*((ll)m*(m+1)/2%mod)%mod; 86 } 87  88 int main() 89  90 { 91  92     freopen("input.txt","r",stdin); 93  94     freopen("output.txt","w",stdout); 95     get(); 96  97     int T=read(); 98     while(T--) 99     {100         int n=read(),m=read(),ans=0;if(n>m)swap(n,m);101         for(int i=1,j;i<=n;i=j+1)102         {103             j=min(n/(n/i),m/(m/i));104             ans=(ans+(ll)(mu[j]-mu[i-1])*sum(n/i,m/i)%mod)%mod;105         }106         printf("%d\n",(ans+mod)%mod);107     }108 109     return 0;110 111 }  
View Code

 

BZOJ2693: jzptab