NedyalkoKikov

ElemetsInArra

May 26th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 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 PrimeChecker
  8. {
  9. class PrimeChecker
  10. {
  11. static void Main()
  12. {
  13. long n = long.Parse(Console.ReadLine());
  14. Console.WriteLine(isPrime(n));
  15. }
  16. public static bool isPrime(long n)
  17. {
  18.  
  19. if(n <= 1)
  20. {
  21. return false;
  22. }
  23. int maxDivider = (int)Math.Sqrt(n);
  24. for (long divider = 2; divider <= maxDivider; divider++)
  25. {
  26. if(n % divider == 0)
  27. {
  28. return false;
  29. }
  30.  
  31. }
  32. return true;
  33.  
  34.  
  35. }
  36.  
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment