Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Primes_in_Given_Range
- {
- static void Main(string[] args)
- {
- long firstNum = long.Parse(Console.ReadLine());
- long lastNum = long.Parse(Console.ReadLine());
- List<long> primes = new List<long>();
- for (long num = firstNum; num <= lastNum; num++)
- {
- bool primeOrNot = isPrime(num);
- if (primeOrNot) primes.Add(num);
- }
- Console.WriteLine(string.Join(", ", primes));
- }
- private static bool isPrime(long n)
- {
- int boundary = (int)Math.Floor(Math.Sqrt(n));
- if (n == 0) return false;
- if (n == 1) return false;
- if (n == 2) return true;
- for (int i = 2; i <= boundary; ++i)
- {
- if (n % i == 0) return false;
- }
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement