Click here to Skip to main content
15,892,965 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
Daniel Pfeffer9-May-18 9:41
professionalDaniel Pfeffer9-May-18 9:41 
GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
PIEBALDconsult9-May-18 7:44
mvePIEBALDconsult9-May-18 7:44 
GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
Randor 9-May-18 9:56
professional Randor 9-May-18 9:56 
GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
Kornfeld Eliyahu Peter9-May-18 10:11
professionalKornfeld Eliyahu Peter9-May-18 10:11 
GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
CPallini9-May-18 11:21
mveCPallini9-May-18 11:21 
GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
PIEBALDconsult9-May-18 11:36
mvePIEBALDconsult9-May-18 11:36 
GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
CPallini9-May-18 21:23
mveCPallini9-May-18 21:23 
GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
dan!sh 9-May-18 22:37
professional dan!sh 9-May-18 22:37 
About 4 of years back while solving Project Euler problems. I ended up writing this:
public class NthPrimeNumber
{
    public string GetNumber()
    {
        long number = 0;

        // All prime numbers are denoted by 6n+1 or 6n-1 format. So, assumming for 
        // 10001st number, n is 100000 (in fact it will be lesser than this)
        bool[] isComposite = new bool[1000002];

        // Since this method will find more than 10001 prime numbers, track how many have been
        // found already and once we have 10001 as the count, stop
        int primeNumberCount = 0;
        int upperBoundRoot = (int)Math.Sqrt(1000001);

        for (int i = 2; i <= upperBoundRoot; i++)
        {
            if (!isComposite[i])
            {
                primeNumberCount++;
                if (primeNumberCount == 10001)
                {
                    number = i;
                    break;
                }
                for (int k = i * i; k <= 1000001; k += i)
                    isComposite[k] = true;
            }
        }

        // if the count is not 10001 yet, there are more numbers to find
        for (int i = upperBoundRoot; i < 1000001; i++)
        {
            if (!isComposite[i])
            {
                primeNumberCount++;

                if (primeNumberCount == 10001)
                {
                    number = i;
                    break;
                }
            }
        }

        return number.ToString();
    }
}
"It is easy to decipher extraterrestrial signals after deciphering Javascript and VB6 themselves.", ISanti[^]

GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
Alexander DiMauro10-May-18 2:25
Alexander DiMauro10-May-18 2:25 
GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
sandyson10-May-18 2:51
sandyson10-May-18 2:51 
GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
ventureaaron10-May-18 3:20
ventureaaron10-May-18 3:20 
GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
TrinityRaven10-May-18 4:03
TrinityRaven10-May-18 4:03 
GeneralRe: When (or not) did you learn about the Sieve of Eratosthenes Pin
Kirk 1038982110-May-18 5:54
Kirk 1038982110-May-18 5:54 
GeneralHow to make ISO image of an XBox360 game disc? Pin
swampwiz9-May-18 5:27
swampwiz9-May-18 5:27 
GeneralRe: How to make ISO image of an XBox360 game disc? Pin
OriginalGriff9-May-18 5:38
mveOriginalGriff9-May-18 5:38 
GeneralRe: How to make ISO image of an XBox360 game disc? Pin
lopatir9-May-18 5:50
lopatir9-May-18 5:50 
GeneralRe: How to make ISO image of an XBox360 game disc? Pin
Gary Wheeler9-May-18 6:43
Gary Wheeler9-May-18 6:43 
GeneralRe: How to make ISO image of an XBox360 game disc? Pin
dandy729-May-18 7:05
dandy729-May-18 7:05 
GeneralRe: How to make ISO image of an XBox360 game disc? Pin
swampwiz9-May-18 7:08
swampwiz9-May-18 7:08 
GeneralRe: How to make ISO image of an XBox360 game disc? Pin
dandy729-May-18 7:13
dandy729-May-18 7:13 
GeneralRe: How to make ISO image of an XBox360 game disc? Pin
swampwiz9-May-18 14:48
swampwiz9-May-18 14:48 
GeneralRe: How to make ISO image of an XBox360 game disc? Pin
dandy7210-May-18 3:06
dandy7210-May-18 3:06 
GeneralRe: How to make ISO image of an XBox360 game disc? Pin
Richard MacCutchan9-May-18 7:16
mveRichard MacCutchan9-May-18 7:16 
GeneralRe: How to make ISO image of an XBox360 game disc? Pin
swampwiz9-May-18 14:44
swampwiz9-May-18 14:44 
GeneralRe: How to make ISO image of an XBox360 game disc? Pin
Richard MacCutchan9-May-18 22:09
mveRichard MacCutchan9-May-18 22:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.