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

0ms做法

Posted by 20121181jj at 2014-02-14 21:34:22 on Problem 2909
In Reply To:一次ac,不过要16ms,求0ms做法 Posted by:TSERROF at 2012-09-10 14:54:31
#include<iostream>
#include<cmath>
#include<cstring>
using namespace std;
bool b[40000];
int a[40000]={0},len=0,n;
bool f(int n){
	for(int i=2;i*i<=n;i++)
	  if(n%i==0) return false;
	  return true;
}
int main(){
	memset(b,false,sizeof(b));
	for(int i=2;i<=pow(2,15);i++)
	  if(f(i)){
	  	a[len++]=i;
	  	b[i]=true;
	  }
    while(cin>>n&&n>=4&&n<pow(2,15)){
    	int num=0;
    	for(int i=0;a[i]<=n/2;i++)
    	  if(b[a[i]]&&b[n-a[i]]) num++;
    	cout<<num<<endl;
    }  
    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