Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:筛法求质In Reply To:筛法求质 Posted by:yc5_yc at 2012-06-15 21:37:44 > 这题把我写毛了! > 几个重点,总结一下: > 1、筛法求质 > for(int i=2;i<1000000;i++) > if(!A[i]) > for(int j=2*i;j<=1000000;j+=i) > A[j]=1; > A[0]=A[1]=1; > 2、题目层次的优化(极其重要!) > for(i=3;i<=N/2;i+=2) > { > if(!(A[i]) && !(A[N-i])) > { > printf("%d = %d + %d\n",N,i,N-i); > break; > } > } > 还有几个细节问题,如筛法中的 > > A[0]=A[1]=1; > 还有 > for(int i=2;i<1000000;i++) > 第一次我想自作聪明地写成了 > for(int i=2;i<600000;i++) > 以上问题造成了18次WA+TLE的教训! Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator