int main ()
{
int n, i;
cin >> n;
for(i=2;i<n;i++)
{
if(n%i==0)
{
cout<<"Not Prime" << endl;
break;
}
}
if(n==i)
{
cout<<"Prime"<<endl;
}
return 0;
}
int main ()
{
int n, i;
cin >> n;
for(i=2;i<n;i++)
{
if(n%i==0)
{
cout<<"Not Prime" << endl;
break;
}
}
if(n==i)
{
cout<<"Prime"<<endl;
}
return 0;
}
Yes this is correct to find whether a number is prime or not but the time complexity is O(N)
Sorry, I didnt get the time complexity part. What do you mean when you say “the time complexity is O(N)”.
Hey Divyam, time complexity is O(N) as you are traversing from 2 to N once. If you haven’t studied the time complexity till now, do watch the videos given in the course in time and space complexity section.