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

要考虑 1 1

Posted by 810974380 at 2009-08-24 14:55:13 on Problem 3048
线性筛素数~


附代码(供参考) 大牛们看了不要笑话~

Problem: 3048  User: 810974380 
Memory: 236K  Time: 0MS 
Language: C++  Result: Accepted 

Source Code 
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
#define Max 30001
bool flag[Max];int i,j,n,s[5001];
void getp()
{ 
  memset(flag,true,sizeof(flag));
  for(i=3;i<1000;i+=2)
  {
	if(flag[i])
	for(j=3;i*j<=Max;j+=2)
	if(flag[i])
	flag[i*j]=false;
  }
	for(i=4;i<=Max;i+=2)
	flag[i]=false;
}
int main()
{ getp();
  scanf("%d",&n);
  for(i=0;i<n;i++)
  scanf("%d",&s[i]);
  sort(s,s+n);
  for(i=s[n-1];i>=1;i--)
    {
	  for(j=n-1;j>=0;j--)
	  {
		if((flag[i])&&s[j]%i==0) break;
	  }
	  if((flag[i])&&s[j]%i==0) break;
    }
  printf("%d\n",s[j]);
  system("pause");
  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