Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace PrimeGenerator
- {
- class MainClass
- {
- static void generatePrimes (long min, long max)
- {
- bool[] prime = new bool[max + 1];
- for (long i=2; i<max+1; i++)
- prime [i] = true;
- for (long i=2; i<max+1; i++) {
- if (prime [i]) {
- if (i>=min)
- Console.WriteLine (i);
- for (long j=i*2; j<max+1; j+=i)
- prime [j] = false;
- }
- }
- Console.WriteLine ();
- }
- public static void Main (string[] args)
- {
- int testCases = Convert.ToInt32 (Console.ReadLine ());
- long[] min = new long[testCases];
- long[] max = new long[testCases];
- for (int i=0; i<testCases; i++) {
- string input = Console.ReadLine ();
- min [i] = Convert.ToInt64 (input.Split (' ') [0]);
- max [i] = Convert.ToInt64 (input.Split (' ') [1]);
- }
- for (int i=0; i<testCases; i++)
- generatePrimes (min [i], max [i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement