Loading ...
Sorry, an error occurred while loading the content.

15341Small prime sequence with 2 4 2 4 gaps

Expand Messages
  • Milton Brown
    Sep 28, 2004
    • 0 Attachment
      Attached is an effiecient small prime program,
      considering only alternates of 2 4 2 4 ..

      Milton L. Brown
      miltbrown@...

      /**
      * Even more efficient prime program
      *
      * @author M. Brown
      * September 17, 2004
      * Add 2 and 4 alternately, check only odd primes
      * This program only checks numbers starting at 5
      * then adding 2 and 4 alternately

      Example Output
      *
      2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97
      101 103 107 109 113 127 131 137 139 149 151 157 163 167 173 179 181 191 193
      197 199
      */
      public class Prime
      {
      public static void main(String[] args)
      {
      System.out.println(" ");
      System.out.println("2 3 5 ");
      int i, j, n=5,k=1,m=1;
      for (j=1;j<333;j++)
      {
      if ((j%33)==0) System.out.println(" ");
      n += 2;
      if ((j%2)==0) n += 2;
      m=1;
      for ( i=3; i*i<=n; i+=2)
      if ((m =(n%i)) == 0) break;
      if (m != 0) System.out.print(n+" ");
      };
      }
      }