OFFSET
2,1
COMMENTS
The program below is for C++ and does not work for numbers above a certain point due to integer restrictions.
EXAMPLE
S(3)=109 because 109 is a prime, 109/3 rounded up, or 37, is a prime; 109/3^2 rounded up, or 13, is a prime; 109/3^3 rounded up, or 5, is a prime;109/3^4 rounded up, or 2, is a prime; 109/3^5 rounded up is one.
PROG
#include <iostream> #include <cmath> #include <tchar.h> using namespace std; unsigned long int sqrot; unsigned long int test; void primetest (unsigned long long int& x, bool& t){ sqrot=10000000000; test=2; while(sqrot>test && x>test && x%test!=0){ test=test+1; } if(sqrot==test || x==test){ t=true; }else{ t=false; }} int main() { int a; int b; unsigned int k; unsigned long long int c; unsigned long long int prime; unsigned long long int array[2000]; int number=2; bool t; unsigned int d=1; number=2; while(number>1){ array[1]=1; a=1; b=1; while(a<=b){ prime=number*array[a]; k=number-1; while (prime-k<= prime){ c=prime-k; primetest(c, t); if(t==true){ b++; array[b]=c; if(c>d){ d=c; }else{} }else{} k--; } a++; } cout<<d<<", "; number++; d=1; } cin>>a; return 0; }
Contribution from Max Alekseyev, May 21 2009: (Start)
(PARI) { a(n, q) = local(t, b, r); t=(q-1)*n; b=q*n; r=[]; while(1, t=nextprime(t+1); if(t>b, break); r=concat(r, [t]); ); r }
CROSSREFS
KEYWORD
nonn
AUTHOR
Alex Smith (Indeed123(AT)gmail.com), Feb 15 2007
EXTENSIONS
Corrected and extended by Max Alekseyev, May 21 2009
STATUS
approved