NEFU OJ 2 猜想

關鍵點:

合數:可以分解成任意質數的乘積

求出質數表,然後處理輸入

#include<iostream>
#include<stdio.h>
using namespace std;
#define SIZE (1<<24)
int sushuVec[1080000] ;

bool sushuB[SIZE+1];
int totalnum;

void getSushuVec()
{
	totalnum = 0;
	memset(sushuB,true,sizeof(sushuB));  
    memset(sushuVec,0,sizeof(sushuVec));
	for(int i=2;i<=SIZE;++i)
	{
		if(sushuB[i] == true)
		{
			sushuVec[totalnum] = i;
			++totalnum;
		}
		for(int j=0;j<totalnum && i*sushuVec[j]<=SIZE;++j)
		{
			sushuB[ i*sushuVec[j] ] =false;
			if(i%sushuVec[j] == 0)
				break;
		}
	}
}

int main()
{
	int a,result = 0;
	getSushuVec();
	while(cin>>a)
	{	
			if(a == EOF)
				break;
			for(int i=0;sushuVec[i] <=(a>>1);++i)
			{
				if(sushuB[a-sushuVec[i] ])
					++result;
			}  
			printf("%d",result);
			result =0;                     
	}
	return 1;
}


發佈了73 篇原創文章 · 獲贊 0 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章