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.
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;classSolution{staticvoidMain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution */intt=int.Parse(Console.ReadLine());List<int>possiblePrimes=newList<int>();for(inti=0;i<t;i++){possiblePrimes.Add(int.Parse(Console.ReadLine()));}foreach(intpinpossiblePrimes){stringisPrime="Prime";if(p==1||(p%2==0&&p!=2))isPrime="Not prime";else{intstartAt=(int)Math.Sqrt(p);for(inti=startAt;i>2;i--){if(i%2==0)continue;elseif(p%i==0){isPrime="Not prime";break;}}}Console.WriteLine(isPrime);}}}
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 →
In C#