Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- namespace PrimePairs
- {
- class Program
- {
- static void Main()
- {
- int firstStart = int.Parse(Console.ReadLine());
- int secondStart = int.Parse(Console.ReadLine());
- int firstStep = int.Parse(Console.ReadLine());
- int secondStep = int.Parse(Console.ReadLine());
- int firstStop = firstStart + firstStep;
- int secondStop = secondStart + secondStep;
- List<int> allNums = new List<int>(256);
- for (int i = firstStart; i <= firstStop; i++)
- {
- for (int j = secondStart; j <= secondStop; j++)
- {
- if (IsPrime(i) && IsPrime(j))
- {
- allNums.Add(i * 100 + j);
- }
- }
- }
- foreach (var num in allNums)
- {
- Console.WriteLine(num);
- }
- }
- private static bool IsPrime(int n)
- {
- if (n < 2)
- {
- return false;
- }
- else if (n == 2 || n == 3)
- {
- return true;
- }
- else
- {
- for (int i = 2; i <= Math.Sqrt(n); i++)
- {
- if (n % i == 0)
- {
- return false;
- }
- }
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement