POJ 2034 反素数,素数筛选,DFS暴力搜索

输入S,T,D,输出从S到T的某种排列中长度不超过D的连续和都为合数,输出其中的一种排列,否则输出没有。。。。

#include
#include
#include
const int maxn=1000+10;
using namespace std;
bool pri[maxn*maxn],p[maxn];
int list[maxn];
int s,t,d;
void ss(){
	for(int i=2;i<=1000;i++)
		if(!pri[i])
			for(int j=i*i;j<=600000;j+=i)pri[j]=true;
}
bool pd(int x,int u){
	if(x<2)return true;
	int sum=u;
	for(int i=x-1;i>x-d&& i>=1;i--){
		sum+=list[i];
		if(!pri[sum])return false;
	}
	return true;
}
bool dfs(int x){
	if(x>t-s+1){
		for(int i=1;i>s>>t>>d; 
		memset(p,0,sizeof(p));
		if(s+t+d==0)return 0;
		if(dfs(1)){
			;
		}else printf("No anti-prime sequence exists.\n");	
	}
	return 0;
}


你可能感兴趣的:(程序代码,算法分享,POJ,数论相关)