Continuing the wonderful community solutions to Project Euler.

This is Problem 7, 10001st prime.

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10,001st prime number?

Continuing the wonderful community solutions to Project Euler.

This is Problem 7, 10001st prime.

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10,001st prime number?

For further actions, you may consider blocking this person and/or reporting abuse

Shiivam Agnihotri -

Mustafa COSKUNCELEBI -

FuturisticGeeks -

Brendan -

## Top comments (12)

Hey, I want to make sure we're following their rules and guidelines. I had reviewed the copyright page (and the related license) and I was confident we were following their preferred attribution requests and other specifications.

Can you point me in the right direction here if I'm missing something?

Read through their about page. They have a few points addressing sharing questions & solutions. Specifically, question 13 and the disclaimer at the bottom.

I know that in the past, they were "blocking" people who shared solutions online. It seems like they have realized that that is not a feasible goal, but it is still important to respect their objectives.

Found it!

Thanks for this. The "logged-out" version of the page wasn't showing this question+answer for some reason.

In recognition of this preferred policy, I'll discontinue the series here on DEV.

Thanks to you, @brandelune , and @gcvancouver for making me aware of this policy. I'll start posting questions from a different source in the coming days.

JS

JavaScript:

If some is wondering what in the world I'm doing to compute

`n`

, it's about this: every prime number larger than 3 is of the form 6k± 1. With a little manipulation it could be rewritten as 3/2 + 3h+ (-1)^{h + 1}/ 2.Python

Using sieve of Eratosthenes method

class Sieve {

val magicnum: Int = 10001

fun buildSieve(startNumber: Int = 1, endNumber: Int = 100000): ArrayList {

var map = arrayListOf(NumObjects("na", 0))

for (i in startNumber..endNumber) {

map.add(NumObjects("na", i))

}

return map

}

}

class NumObjects(hit:String,num:Int){

var hit: String = hit

var num: Int = num

}

Rust Solution: Playground

Got it to 17s, from 34s using the lazy iterators, was still using

`2..(n/2)`

for checking primes.Got it down to 0.9s by changing the prime check to

`2..(sqrt(n)+1)`

The iterator for checking prime uses

`any(|i| n % i == 0)`

instead of`all(|i| !n % i == 0)`

, so that it may short-circuit when any case returns true. Similar to using a loop with break condition.Still is a brute force technique.

Here is a javascript solution

My solutions in .C

github/nilzoft