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.
Woah. That was easier than I thought. I don't know maybe it's because my solution is simple. C# solution
I get the list of primes for the first 10000.
Just put.
publicstaticvoidgetPrimes(List<int>Primes){for(inti=3;Primes.Count<=10000;i+=2){boolisPrime=true;if(i==3){Primes.Add(3);}foreach(intprimeinPrimes){if(i%prime==0){isPrime=false;break;}}if(isPrime){Primes.Add(i);}}}staticvoidMain(String[]args){intt=Convert.ToInt32(Console.ReadLine());//get primesList<int>Primes=newList<int>();Primes.Add(2);//add the primes to the listmyFunc.getPrimes(Primes);for(inta0=0;a0<t;a0++){intn=Convert.ToInt32(Console.ReadLine());Console.WriteLine(Primes[n-1]);}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #7: 10001st prime
You are viewing a single comment's thread. Return to all comments →
Woah. That was easier than I thought. I don't know maybe it's because my solution is simple. C# solution