My test cases are not satisfied with this code

#include
using namespace std;
int main() {
int n;
cin>>n;
int i;
for (i=2;i<=n-1;i++)
{
if(n%i==0)
{
cout<<" not prime";
break;

	}
}
if (i==n)
{
	cout<<"prime"<<endl;
}
return 0;

}

pls provide with the solution

Take as input a number N, print “Prime” if it is prime if not Print “Not Prime”.

you have to print Prime not prime
P should be capital

also run loop till squareroot of n to optimised it
use this condition
for (i=2;i*i<=n;i++)

also instead of int use long long int as no are large

Code with Modifications

i hope this helps
if yes hit a like and don’t forgot to mark doubt as resolved :grinning:
if you have more doubts regarding this feel free to ask

i have not able to solve pls provide with the sol

i have already provided the solution you can see it in previous reply

in this code the mistake is that
you have to check this condition outside the loop
if(i==N){
cout<<“Prime”<<endl;
}

why are we doing i*i instead of just i …pls explain the reason

@suryansh771
Both way is correct but i*i way is more efficient, it is O(sqrt(n))
In number theory,
Composite numbers have the property that it is divisible atleast one divisor <=sqrt(n) and greater than 1
Thus prime number should not have such property, if it does then its not a prime

Proof is also easy if you are interested(try yourself by contradiction),

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.