1001 The Great ( Easy Confusion)

What is the 1001st prime number ?


The answer is 7927.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

4 solutions

Discussions for this problem are now closed

Farouk Yasser
Jan 16, 2015

Used a python Code: Last num was it

Aryan Gaikwad
Feb 24, 2015

Here is the java version of it -

You can try it out online - https://ideone.com/9lLgk4

static int n = 1;

public static void main (String[] args){
    for(int i=2;;i++)
        if(isPrime(i)) //if it's prime, then check if it's 1001th
            if(++n == 1001){
                System.out.println(i); //if it is, print it out
                return; //stop program execution
        }
}

static boolean isPrime(int n) {
    if (n%2==0) return false;  //cancel out even numbers
    for(int i=3;i*i<=n;i+=2)
        if(n%i==0) return false; //loop out to check if prime
    return true;
}

Simple code I have and run ... solve for n=7950 and count backwards It's in spanish but you enter the number and it output a list of primes and how many elements are there.

#include <stdio.h>

int main(){

unsigned int numero;//limite en los ciclos for
unsigned int n, esPrimo;//n es el ultimo numero que queremos calcular
unsigned int divisor, residuo;//un par de variables para ir probando 
unsigned int contador=0;//un contador para saber cuantos primos obtuvimos 

printf("\n¿Hasta qué número desea conocer los primos?: ");
scanf("%d", &n);

for (numero=2;numero<=n;numero++){
    for(divisor=2;divisor<numero;divisor++){
        esPrimo=1;//damos por hecho que el numero es primo
        residuo=numero%divisor;
        if(residuo==0){
            esPrimo=0;//si entra aquí, sí, se demostró lo contrario 
            break;//así que cierra el 2° ciclo for, sigue con el siguiente numero
        }
        }
        if(esPrimo !=0){ //después de verificar imprime si es cero o no
            printf("%d ",numero);
                contador=contador+1;//y añade a nuestro contador 
    }
}
printf("\n\nEstos son todos los %d numeros primos\n\n",contador);
getchar();
return 0;

}

Anna Anant
Jan 24, 2015

This simply needs computation power (ie Some programming) There are no patterns in prime numbers (at least that we know of) so this is simply a programming test to output the 1001th prime number. you can use any primality test (like Wilson's Primality Test) to check numbers in ascending order until you reach the correct answer.

This is an example of a python code that I just wrote and does that:

import math

prime no = 0 num = 3 while prime no != 1000: if ((math.factorial(num -1)) % num) - num == -1: prime no = prime no + 1 print num num = num + 1

So the answer is 7927

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...