Advertisement
golergka

Untitled

May 29th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2.  
  3. namespace PrimeGenerator
  4. {
  5.     class MainClass
  6.     {
  7.        
  8.         static void generatePrimes (long min, long max)
  9.         {
  10.            
  11.             bool[] prime = new bool[max + 1];
  12.            
  13.             for (long i=2; i<max+1; i++)
  14.                 prime [i] = true;
  15.            
  16.             for (long i=2; i<max+1; i++) {
  17.                 if (prime [i]) {
  18.                     if (i>=min)
  19.                         Console.WriteLine (i);
  20.                     for (long j=i*2; j<max+1; j+=i)
  21.                         prime [j] = false;
  22.                 }
  23.             }
  24.            
  25.             Console.WriteLine ();
  26.            
  27.         }
  28.        
  29.         public static void Main (string[] args)
  30.         {
  31.             int testCases = Convert.ToInt32 (Console.ReadLine ());
  32.             long[] min = new long[testCases];
  33.             long[] max = new long[testCases];
  34.            
  35.             for (int i=0; i<testCases; i++) {
  36.                 string input = Console.ReadLine ();
  37.                 min [i] = Convert.ToInt64 (input.Split (' ') [0]);
  38.                 max [i] = Convert.ToInt64 (input.Split (' ') [1]);
  39.             }
  40.            
  41.             for (int i=0; i<testCases; i++)
  42.                 generatePrimes (min [i], max [i]);
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement