标题: [求助]奇怪的问题,究竟是哪儿不对. [打印本页] 作者: ~~精灵小姐$ 时间: 2009-11-3 00:53 标题: [求助]奇怪的问题,究竟是哪儿不对. //找在10000内的质素里等差最大的等差数列 如3 5 7差为2
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int main(int argc, char* argv[])
{
const int SIZE = 10000;
int num[SIZE+1]; //一个栅栏,即num[0];
num[0]=0;
num[1]=0;
for(int m=2;m<=SIZE;m++) //set all the num 1
num[m]=1;
int pp=sqrt(SIZE)+1;
for (int a=2;a!=pp;a++)
for(int b=2;b<=sqrt(a);b++) //find the prime number in sqrt(SIZE) and set others 0
if(a%b==0)
{
num[a]=0;
break;
}
for(int i=1;i!=pp;i++) // find tne prime number in SIZE and set them 1
{
if(num[i]==0)
continue;
for (int j=2;j<=SIZE / i;j++)
num[i*j]=0;
}
vector<int> PN;
for(int n=1;n<SIZE;n++) //save the prime number in vector PN
if(num[n]==1)
PN.push_back(n);
vector<int>::iterator Pb=PN.begin();
vector<int>::reverse_iterator Pe=PN.rbegin();
int aa[4]={1,1,1,1};
vector<int> L(aa,aa+4);
int abc=PN.size()/2;
for (int N=0;N < abc;N++,Pb++)
{
for (int M=0;M < abc;M++,Pe++)
{