Advertisement
viraco4a

Prime

Feb 20th, 2018
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 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 _10_checkPrime
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14. bool prime = true;
  15. if (n < 2)
  16. {
  17. prime = false;
  18. }
  19. else if (n == 2 || n == 3)
  20. {
  21. prime = true;
  22. }
  23. else
  24. {
  25. for (int i = 2; i <= Math.Sqrt(n); i++)
  26. {
  27. if (n % i == 0)
  28. {
  29. prime = false;
  30. break;
  31. }
  32. }
  33. }
  34. if (prime)
  35. {
  36. Console.WriteLine("Prime");
  37. }
  38. else
  39. {
  40. Console.WriteLine("Not Prime");
  41. }
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement