Пример #1
0
int main(int argc, char *argv[]) {
    if (argc < 2) {
        return error(1);
    }
    int n = atoi(argv[1]);
    printf("Prime #%d: %ld\n", n, nthprime(n));
    return 0;
}
Пример #2
0
// calcula los primeros 100 primos y retorna el n esimo
int nthprimeArray (int n) {

  int j, arr[100];
    j = 0;
    
  while (j<100){
    arr[j]= nthprime(j); 
    j=j+1;
  } 
  return arr[n-1];
}
Пример #3
0
static PyObject* primes_nth(PyObject* self, PyObject* args){
    Py_ssize_t n = 0;
    if (!PyArg_ParseTuple(args, "n:primes_nth", &n)) return NULL;
    if (n < 1){
        PyErr_SetString(PyExc_ValueError, "a positive integer is required");
        return NULL;
    }
    switch (n){
        case 1: return PyInt_FromLong(2);
        case 2: return PyInt_FromLong(3);
        case 3: return PyInt_FromLong(5);
        case 4: return PyInt_FromLong(7);
        case 5: return PyInt_FromLong(11);
    }
    NthPrime nthprime(n);
    PrimeSieve ps;
    try {
        ps.generatePrimes(0, n*log(n*log(n)), &nthprime);
    }
    catch (StopPrimeGeneration&) {}
    return nthprime.prime;
}
Пример #4
0
// funcion main 
int main (){
       
        int x, i; 
	init_input("input"); 

// test factorial entero    
        print_string("Factorial Enteros----------------------------------");    
        x=get_int(); // lee la cantidad de veces que ejecutara la funcion  
        i = 0;        
        while (i<x){              
            int aux;         
            aux=get_int(); // lee los datos para invocar a la funcion
            aux = factorial(aux);
            print_int(aux);             
            i++;
	    }
		print_string("---------------------------------------------------------");
		
// test factorial real 
		print_string("Factorial Reales----------------------------------");
        x=get_int();  
        i = 0;
        while (i<x){
            float aux;
            aux=get_float();
            aux = factorialF(aux);
            print_float(aux); 
            i++;
	    }
		print_string("---------------------------------------------------------");

// test factorial array entero    
        print_string("Factorial Array Enteros----------------------------------");    
        x=get_int(); // lee la cantidad de veces que ejecutara la funcion  
        i = 0;        
        while (i<x){              
            int aux;         
            aux=get_int(); // lee los datos para invocar a la funcion
            aux = factorialArray(aux);
            print_int(aux);             
            i++;
	    }
		print_string("---------------------------------------------------------");

// test nthprime entero    
        print_string("Nthprime Enteros----------------------------------");    
        x=get_int(); // lee la cantidad de veces que ejecutara la funcion  
        i = 0;        
        while (i<x){              
            int aux;         
            aux=get_int(); // lee los datos para invocar a la funcion
            aux = nthprime(aux);
            print_int(aux);             
            i++;
	    }
		print_string("---------------------------------------------------------");

// test nthprime array entero    
        print_string("Nthprime Array Enteros----------------------------------");    
        x=get_int(); // lee la cantidad de veces que ejecutara la funcion  
        i = 0;        
        while (i<x){              
            int aux;         
            aux=get_int(); // lee los datos para invocar a la funcion
            aux = nthprimeArray(aux);
            print_int(aux);             
            i++;
	    }
		print_string("---------------------------------------------------------");

// test int2bin entero    
        print_string("Int2Bin Enteros----------------------------------");    
        x=get_int(); // lee la cantidad de veces que ejecutara la funcion  
        i = 0;        
        while (i<x){              
            int aux;         
            aux=get_int(); // lee los datos para invocar a la funcion
            aux = int2bin(aux);
            print_int(aux);             
            i++;
	    }
		print_string("---------------------------------------------------------");

// test gcd entero    
        print_string("GCD Enteros----------------------------------");    
        x=get_int(); // lee la cantidad de veces que ejecutara la funcion  
        i = 0;        
        while (i<x){              
            int aux;// lee los datos para invocar a la funcion
            aux = gcd(get_int(),get_int());
            print_int(aux);             
            i++;
	    }
		print_string("---------------------------------------------------------");

// test test    
        print_string("test----------------------------------");    
        test();
		print_string("---------------------------------------------------------");


// test test1    
        print_string("test1----------------------------------");    
        test1();
		print_string("---------------------------------------------------------");



        close_input();
        return 1;   
}