You are viewing a single comment's thread. Return to all comments →
C#
int T = Convert.ToInt32(Console.ReadLine()); if(T >= 1 && T <= 30) { for(int i=0; i < T; i++) { int n = Convert.ToInt32(Console.ReadLine()); if(n>=1 && n <= 2000000000) { bool isPrime = true; int j=2; int sqt = Convert.ToInt32(Math.Sqrt(n)); while(j<=sqt) { int r = n % j; if(r==0) { isPrime = false; break; } j++; } if(n ==1 || isPrime == false) { Console.WriteLine("Not prime"); }else{ Console.WriteLine("Prime"); } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Day 25: Running Time and Complexity
You are viewing a single comment's thread. Return to all comments →
C#