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

Re:求助(Time Limit Exceed)

Posted by JiangLY at 2005-04-23 17:47:39 on Problem 2407
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:
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