Advertisement
viraco4a

06.PrimeNumbers

Mar 12th, 2018
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace PrimePairs
  5. {
  6. class Program
  7. {
  8. static void Main()
  9. {
  10. int firstStart = int.Parse(Console.ReadLine());
  11. int secondStart = int.Parse(Console.ReadLine());
  12. int firstStep = int.Parse(Console.ReadLine());
  13. int secondStep = int.Parse(Console.ReadLine());
  14. int firstStop = firstStart + firstStep;
  15. int secondStop = secondStart + secondStep;
  16. List<int> allNums = new List<int>(256);
  17. for (int i = firstStart; i <= firstStop; i++)
  18. {
  19. for (int j = secondStart; j <= secondStop; j++)
  20. {
  21. if (IsPrime(i) && IsPrime(j))
  22. {
  23. allNums.Add(i * 100 + j);
  24. }
  25. }
  26. }
  27. foreach (var num in allNums)
  28. {
  29. Console.WriteLine(num);
  30. }
  31. }
  32.  
  33. private static bool IsPrime(int n)
  34. {
  35. if (n < 2)
  36. {
  37. return false;
  38. }
  39. else if (n == 2 || n == 3)
  40. {
  41. return true;
  42. }
  43. else
  44. {
  45. for (int i = 2; i <= Math.Sqrt(n); i++)
  46. {
  47. if (n % i == 0)
  48. {
  49. return false;
  50. }
  51. }
  52. }
  53. return true;
  54. }
  55.  
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement