Advertisement
Soulfood

Untitled

Oct 20th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. using System;
  2.  
  3. namespace SumPrimeNonPrime
  4. {
  5. class SumPrimeNonPrime
  6. {
  7. static void Main()
  8. {
  9.  
  10. string input = Console.ReadLine();
  11. int nativeSum = 0;
  12. int nonNativeSum = 0;
  13. bool isPrimeNaive = false;
  14.  
  15. while (input != "stop")
  16. {
  17. int N = int.Parse(input);
  18.  
  19. if (N == 0 || N == 1)
  20. {
  21. nonNativeSum += N;
  22. input = Console.ReadLine();
  23. }
  24. else
  25. {
  26. for (int a = 2; a <= N / 2; a++)
  27. {
  28. if (N % a == 0)
  29. {
  30. nonNativeSum += N;
  31. return;
  32. }
  33.  
  34. }
  35. nativeSum += N;
  36. input = Console.ReadLine();
  37. }
  38.  
  39. //if (N < 0)
  40. //{
  41. // continue;
  42. //}
  43.  
  44. //for (int i = 2; i <= Math.Sqrt(N); i++)
  45. //{
  46. // if (N % i == 0)
  47. // {
  48. // isPrimeNaive = false;
  49. // break;
  50. // }
  51. //}
  52.  
  53.  
  54. //if (isPrimeNaive)
  55. //{
  56. // nativeSum += N;
  57. // }
  58. //else
  59. //{
  60. // nonNativeSum += N;
  61. //}
  62. //input = Console.ReadLine();
  63. }
  64.  
  65. Console.WriteLine($"Sum of all prime numbers is: {nativeSum}");
  66. Console.WriteLine($"Sum of all non prime numbers is: {nonNativeSum}");
  67. }
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement