### Having Trouble with C++ Checker

Hi people,

I have problems with the following code. It is supposed to expand on the green tao theorem.

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106`` ``````// Efficent Prime Check 1.cpp : Defines the entry point for the console application. //Created by Sutton Shin //(C) Sutton Shin //Written in the C++ Language // \\\ ||||/// // |// // | // |0 0 | // |- -| // ------ // | | // / \ // / \ // | C++ | // | Guy | // | | // -------- // || || // -- -- // |_* |_* #include "stdafx.h" #include #include //test whether a number x appears in a sequence p[0], p[1]...p[l]. int test (int x, int a[], int l){ int v=0; for (int i=0; i> num; bool isPrime=true; for ( int i = 2; i <= num; i++) { for ( int j = 2; j > l; d=1; for (i=2; il-1){ break; } } std::cout <<"length of the algebraic sequence is:"<< cont << std::endl; for (i=0;i::max(), '\n' ); return 0; } ``````

The code does not even execute as required, and i cannot find out what is wrong.
Last edited on
closed account (ShpjE3v7)
Try it:
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081`` ``````#include "stdafx.h" #include #include using namespace std; int test(int x, int a[], int l) { int v = 0; for(int i = 0; i < l; i++) { if(a[i] == x) { break; v = 1; } } return v; } int main() { cout << "Enter a number and I will generate the prime numbers up to that number: " << endl; int a, d, i, j, num, cont = 1, N = 10000, l, p[N]; for(i = 1; i < N; i++) { p[i]=0; } cin >> num; bool isPrime = true; for(i = 2; i <= num; i++) { for(j = 2; j < sqrt(i) + 1; j++) { if( i % j == 0 ) { break; isPrime = false; } } if(isPrime) { if(cont < N) { p[cont] = i; cont = cont + 1; } cout << "p("<< cont - 1 << ")="<< p[cont] << endl << "Prime: " << i << endl; } isPrime = true; } cout << "Enter an int number l and I will generate an algebraic prime number sequences with length l."<< endl; cin >> l; d = 1; for(i = 2; i < l; i++) { d = d * i; } cont = 1; for(i = 1; i < 100; i++) { a = p[i]; while(test(a + d * cont, p, N) == 1) { cont = cont + 1; } if(cont > l - 1) { break; } } cout << "Length of the algebraic sequence is: "<< cont << endl; for(i = 0; i < cont; i++) { cout << "a("<< i + 1 << ")=" << a + i * d << endl; } cout << "Press ENTER to continue..."; cin.ignore(numeric_limits < streamsize > max(), "\n"); return 0; }``````
Last edited on
it still does not work.
Topic archived. No new replies allowed.