Hello, I’m working on this task:
To send messages between resistance bases, we use an encryption that requires usage of prime numbers. An integer is called a prime if it is greater than 1 and divisible only by 1 and itself. If you want, you can learn more about prime numbers here. For example, 11 and 13 are prime numbers, but 4 is not. Write a program that reads an integer from the console and detects whether it is prime or not. If the number is prime, the program should output “Prime”; otherwise, “Not prime”. For example:
>14
Not prime
One more example:
>11
Prime
Here is my code:
namespace Modulus
{
class PrimeNumbers
{
static void Main(string[] args)
{
var n = int.Parse(Console.ReadLine());
var m = n / 2;
var flag = 0;
for(int i = 2; i <= m; i++)
{
if(n % i == 0)
{
Console.WriteLine($"{n} is not Prime.");
flag=1;
break;
}
}
if (flag == 0)
{
Console.WriteLine($"{n} is Prime.");
}
}
}
}
Can anyone please help me to solve it?
The results my code produces are correct, but I can’t pass this test