Home > Back-end >  Algorithm: find 10 of arithmetic progression of prime Numbers (the younger brother of recursive seem
Algorithm: find 10 of arithmetic progression of prime Numbers (the younger brother of recursive seem

Time:10-13

Main idea is to screen out the prime number, again through the prime container every time to find two Numbers have been the tolerance to find out the arithmetic progression

But the results seem disappointing,,,,,,,,,,,,,,,,,,,,,,,
From yesterday until now are doing this thing, you really have no way to put it o brother under






run results below


 # include 
#include
using namespace std;
Typedef vector Ivec;

//recursive
Bool zhaosushu (ivec v, int d, c, int ivec: : iterator pos)
{
If (c==10)//find the number 10, return true output after
return true;

Else if (* (+ + pos)==(* pos) + d)
{//judgment on the conditions for the next number=a + tolerance
+ + pos.//the iterator down one, for the next recursive
+ + c;//count + 1
Return zhaosushu (v, d, c, pos);
}
Else if (* (+ + pos)!=(* pos) + d)
return false;//does not meet the requirements for the arithmetic progression, and returns false, continue to find the next round of the first series, two number
}
Int main ()
{
Int e=1;//is used to control the while loop
Ivec v1.
Ivec v.
While (e)
{
for(int i=0; i<=500; + + I)//in the vector container insert 500 1, because the subscript starting from 0, so use & lt;=number, insert one more 1
{//this part used in prime Numbers within a 500 if can't find, and then inserted in the container 500 1
Valerie plame ush_back (1);
}
Int k=v. considering ();

//Erato stern, sieve method of screening of prime number
For (int I=2; i<=k; + + I)
{
If (v [I])
{
For (int j=2 * I; j{
V [j]=0;//the subscript as composite number assignment to 0;
}
V1. Insert (v1. End (), I);/* the prime number is put into the container to another vector, actually there is a mistake, each performs a while loop,
The while loop will be inserted into the last prime, wanted to change, but the while loop seems to be performed only once
It's no result
*/
}
}

For (ivec: : iterator pos=v1. The begin (); Pos!=v1. End (); + + pos)//the number of the first location arithmetic progression
{
+ + pos.
For (ivec: : iterator pos1=pos; Pos1!=v1. End (); + + pos1)//the number of the second location arithmetic progression
{
Int d=(* pos1) - (* pos);//the tolerance of arithmetic progression
Int c=2;//count number in series, the reason the first and the second to get tolerance, then find the rest of the number 8, so c=2;

If (zhaosushu (v1, d, c, pos1))//parameter for containers of all prime number 1
{//4 parameters for the second number of arithmetic progression of iterator
CoutCout<* pos<& lt;" "& lt; <* pos1 & lt; E=0;//used to jump out of the while loop
}
}
}
}
return 0;
}

CodePudding user response:

Oneself are actually haven't found the problem... You see how much is your tolerance

CodePudding user response:

The twin prime Numbers arithmetic=2, how much arithmetic to find?

CodePudding user response:

10000 the prime difference from 2 to 36

CodePudding user response:

 
Int aa=1, ca=4;
While (+ + aa & lt; 10000) judgment prime Numbers (aa);
Aa=0;
While (prime group [+ + aa]) if ((prime group (aa) - prime group [aa - 1))==ca) cout & lt;

2

4

Poor 14

  • Related