We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
C#CsharpstaticvoidMain(String[]args){introw=int.TryParse(Console.ReadLine(),outintinputRow)?inputRow:0;while(row>0){int.TryParse(Console.ReadLine(),outintrec);if(rec>1){boolisPrime=true;// Optimized primality test: check divisors only up to the square rootfor(inti=2;i*i<=rec;i++){if(rec%i==0){isPrime=false;break;}}stringresult=isPrime?"Prime":"Not prime";Console.WriteLine(result);}else{Console.WriteLine("Not prime");}row--;}}
Cookie support is required to access HackerRank
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 →