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 106040202 at 2011-08-11 09:56:19 on Problem 1423
#include<stdio.h>
int a[1000];
#include<math.h>
int su(int n)
{
    int i;
    if(n==1)return 0;
    else if(n==2)return 1;
    else {
        for(i=2;i<=(int)sqrt(n);i++)
            if(n%i==0){return 0;break;}
            return 1;
    }
}
int main(){
int m;
int i,j;
int max;
while(scanf("%d",&m)!=EOF)
{
	for(i=0;i<m;i++){
		scanf("%d",&a[i]);
max=0;
	for(j=2;j<a[i];j++){
		if(su(j)==1){
			if(j>max) max=j;
		}
	}

	printf("%d\n",max);
	}
}

	return 0;
}

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