document.write( "Question 1062750: Write a program to print the following series
\n" ); document.write( "2 5 11 17 23 31 41 47 59 ...
\n" ); document.write( "
\n" ); document.write( "

Algebra.Com's Answer #677764 by Edwin McCravy(20059)\"\" \"About 
You can put this solution on YOUR website!
\r\n" );
document.write( "The sequence is the 1st prime, the 3rd prime, the 5th prime, etc., i.e.\r\n" );
document.write( "every other prime.\r\n" );
document.write( "\r\n" );
document.write( "The only language I know is LibertyBasic. Here is the program in that\r\n" );
document.write( "language. The ' indicates a comment line.\r\n" );
document.write( "--------------------------------------------------------------------------\r\n" );
document.write( "\r\n" );
document.write( "           'We begin by printing the first term. The only term that's even.\r\n" );
document.write( "           'and setting the prime count = 1\r\n" );
document.write( "\r\n" );
document.write( "print 2;\" \";\r\n" );
document.write( "count = 1\r\n" );
document.write( "\r\n" );
document.write( "          'Now we need try only odd numbers n from 5 to 100. That's why the\r\n" );
document.write( "          'step 2\" in the next executable line. If we want numbers higher\r\n" );
document.write( "          'than 100, then we change the 100 to a higher number.\r\n" );
document.write( "\r\n" );
document.write( "for n = 3 to 100 step 2\r\n" );
document.write( "\r\n" );
document.write( "pr = 1   \r\n" );
document.write( "          'We test each n to see if it is prime. We use 1 or 0\r\n" );
document.write( "          'values of \"pr\" to indicate whether n is prime or not\r\n" );
document.write( "          'if pr=1 it is prime, and if pr=0 it is not prime\r\n" );
document.write( "          'We started above by setting pr=1, for we change pr to 0\r\n" );
document.write( "          'if n is not prime. Since n is odd, we only\r\n" );
document.write( "          'need to see if n is divisible by odd numbers,\r\n" );
document.write( "          'which is why the \"step 2\" in the next line.\r\n" );
document.write( "\r\n" );
document.write( "for k = 3 to n-1 step 2\r\n" );
document.write( "\r\n" );
document.write( "          'the next line makes pr=0 if n is divisible by k\r\n" );
document.write( "\r\n" );
document.write( "if n mod k = 0 then pr=0\r\n" );
document.write( "\r\n" );
document.write( "next k\r\n" );
document.write( "\r\n" );
document.write( "          'if n is not prime the next line skips to 1 for the next n value\r\n" );
document.write( "\r\n" );
document.write( "if pr = 0 then 1\r\n" );
document.write( "\r\n" );
document.write( "          'if n is prime, we increase the prime count by 1\r\n" );
document.write( "\r\n" );
document.write( "count = count+1\r\n" );
document.write( "\r\n" );
document.write( "          'the next line determines whether the count is even or\r\n" );
document.write( "          'odd.  If it's odd, we print n; if even we skip to 1\r\n" );
document.write( "\r\n" );
document.write( "if count mod 2 = 0 then 1 \r\n" );
document.write( "\r\n" );
document.write( "print n;\" \";\r\n" );
document.write( "\r\n" );
document.write( "1 next n\r\n" );
document.write( "\r\n" );
document.write( "print \"...\"\r\n" );
document.write( "\r\n" );
document.write( "-----------------------------------------\r\n" );
document.write( "\r\n" );
document.write( "Edwin
\n" ); document.write( "
\n" );