Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

这个题一个非常重要的优化

Posted by runformydream at 2009-09-07 12:37:39 on Problem 1619
此题最重要的优化源于一个最想不到的方法,就是在求prime数的时候,记录该数的一个因子就可以了
这样使我的程序从15S 直线286MS,神啊,哈哈
贴下求prime的关键代码
for(i=2;i<N;i++){
         if(!isPrime[i]){
              next[i]=i;
              for(j=i;j<N;j+=i){
                  //pData[j]=i;表示一个数j的一个因子,只要记录任意一个因子即可
                  pData[j]=i;              
                  isPrime[j]=true;
              }
         }
     }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator