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:求助(Time Limit Exceed)In Reply To:求助(Time Limit Exceed) Posted by:zhaohuazhaoshi at 2005-04-23 17:32:22 > #include<iostream.h> > #include<math.h> > void main() > { > long a,i,j,p=0,b; > while(1) > { > cin>>a; > if(a==0) > break; > else > { > b=int(sqrt(a)); > //cout<<b; > for(i=2;i<a;i++) > for(j=2;j<=b;j++) > { > if(a%j==0&&i%j==0) > { > //cout<<i<<' '<<j<<endl; > p++; > break; > } > } > cout<<a-p-1<<endl; > p=0; > } > } > } O(n^2)的,不TLE才怪 Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator