Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace SumPrimeNonPrime
- {
- class SumPrimeNonPrime
- {
- static void Main()
- {
- string input = Console.ReadLine();
- int nativeSum = 0;
- int nonNativeSum = 0;
- bool isPrimeNaive = false;
- while (input != "stop")
- {
- int N = int.Parse(input);
- if (N == 0 || N == 1)
- {
- nonNativeSum += N;
- input = Console.ReadLine();
- }
- else
- {
- for (int a = 2; a <= N / 2; a++)
- {
- if (N % a == 0)
- {
- nonNativeSum += N;
- return;
- }
- }
- nativeSum += N;
- input = Console.ReadLine();
- }
- //if (N < 0)
- //{
- // continue;
- //}
- //for (int i = 2; i <= Math.Sqrt(N); i++)
- //{
- // if (N % i == 0)
- // {
- // isPrimeNaive = false;
- // break;
- // }
- //}
- //if (isPrimeNaive)
- //{
- // nativeSum += N;
- // }
- //else
- //{
- // nonNativeSum += N;
- //}
- //input = Console.ReadLine();
- }
- Console.WriteLine($"Sum of all prime numbers is: {nativeSum}");
- Console.WriteLine($"Sum of all non prime numbers is: {nonNativeSum}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement