Advertisement
viraco4a

Prime 3

Feb 20th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06_PrimeChecker
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. long n = long.Parse(Console.ReadLine());
  14. Console.WriteLine(IsPrime(n));
  15. }
  16.  
  17. private static bool IsPrime(long n)
  18. {
  19. if (n == 2)
  20. {
  21. return true;
  22. }
  23. if (n % 2 == 0 || n == 1)
  24. {
  25. return false;
  26. }
  27. for (int i = 3; i <= (long)Math.Sqrt(n); i+=2)
  28. {
  29. if (n % i == 0)
  30. {
  31. return false;
  32. }
  33. }
  34. return true;
  35. }
  36.  
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement