void RSA::generarPyQ() { // cout << "Se van a generar p y q" << endl; srand (time(NULL)); bool salir = false; int k = 1; while (!salir) { long long numero = rand () % 100; if (numero>3) { if (esPrimo(numero)) { if (k==1) { this->p=numero; k++; } else { if (p!=numero) { this->q=numero; salir = true; } } } } } // PARA PRUEBA // this->p=19; // this->q=7; // ============ // cout << "P= " << this->p << endl; // cout << "Q= " << this->q << endl; }
void main(){ printf("Dame 2 numeros: "); scanf("%d",&num1); scanf("%d",&num2); es_hijo=fork(); if(es_hijo == 0){//solo el hijo hara esto int cont[]={0,0,0,0,0,0,0,0,0,0}; for(i=num1;i<=num2;i++){ sprintf(string, "%d",i);//se convierte a String for(j=0;j<strlen(string);j++){//se recorren caracteres cont[(string[j]-'0')]++;}//se incrementa dependiendo de caracter que es } printf("\nSoy hijo, el resultado de digits para %d & %d es:\n",num1,num2); for(i=0;i<10;i++)//se imprime vector con resultados printf("%d ",cont[i]); printf("\n"); } else{ int primos=0; for (i=num1;i<=num2;i++){ primos+=esPrimo(i); } printf("\nSoy Padre, Numeros primos desde %d hasta %d: %d\n",num1,num2,primos); } }
int main(int argc, char *argv[]) { int inicio, fin, i; inicio = atoi(argv[1]); fin = atoi(argv[2]); for (i = inicio; i < fin; i++) if (esPrimo(i)) write(STDOUT_FILENO, &i, sizeof(int)); return 0; }
int obtenerX( int numero , int modulo ){ int num, i, limite; if ( esPrimo( modulo ) ) { limite = funcionDeEulerParaPrimos( modulo ) - 1; } else { limite = funcionDeEuler( modulo ) - 1; } num = 1; for ( i = 0 ; i < limite ; i++ ){ num = num * numero; num = aplicarModulacion( num , modulo); } return num; }
main() { int n, n2=0; printf("Dame el rango que quieres evaluar: "); scanf("%d",&n); //We capture the value while(n != n2) //Run until the end of travel range { if(esPrimo(n)) printf("%d si es primo\n",n); else printf("%d no es primo\n",n); n--; } }
int main() { unsigned int tests, number; scanf("%d\n", &tests); for(unsigned int i = 0; i < tests; ++i){ scanf("%d\n", &number); if(esPrimo(number)){ printf("%s\n","yes"); } else{ printf("%s\n","no"); } } return 0; }
int main() { int num, i, c; printf("Ingrese numero "); scanf("%d",&num); i = 2; c = 1; while(c <= num) { if(esPrimo(i) == 1) { printf("Es primo %d\n",i); c++; } i++; } }
int main (){ int numeroprimo = 0; int a; printf ("Escribe un numero entero positivo: "); scanf ("%d", &numeroprimo); a = esPrimo (numeroprimo); if (a == 0) printf ("El número %d no es primo", numeroprimo); else printf ("El numero %d es primo", numeroprimo); return 0; }
void RSA::elegirD() { // cout << "Se va a calcular d" << endl; bool fin = false; while (!fin) { long long numero = rand () % 100; if (numero>3) { if (esPrimo(numero)) { if ((numero!=this->p) && (numero!=this->q) && (numero<this->phi)) { this->d=numero; fin = true; } } } } // PARA PRUEBA // this->d=73; // =========== this->inicializarMatriz(); }
int main() { int n,i, contadorPrimosEncontrados; printf("Ingrese el valor de 'n' \n"); scanf("%d",&n); printf("Los primeros %d números primos a partir de 1 son: \n", n); i = 1; contadorPrimosEncontrados = 0; while (contadorPrimosEncontrados<n) { if (esPrimo(i) == TRUE) { printf("%d ",i); contadorPrimosEncontrados++; } i++; } return(0); }
int main() { int ejecutando = 1; void *shared_memory = (void *)0; struct communicate *sharedComm; int shmid; printf("Obteniendo memoria compartida ...\n"); //pedimos al SO Memoria compartida del tamaño de la estructura especificada con clave 1234. shmid = shmget((key_t)1234, sizeof(struct communicate), 0666 | IPC_CREAT); if (shmid == -1) { fprintf(stderr, "Error en shmget\n"); exit(EXIT_FAILURE); } //Nos asociamos a la memoria que le pedimos a SO con el shmid qe nos devolvio al crearla printf("Asociando memoria compartida ...\n"); shared_memory = shmat(shmid, (void *)0, 0); if (shared_memory == (void *)-1) { fprintf(stderr, "Error en shmat\n"); exit(EXIT_FAILURE); } printf("Memoria compartida asociada en: %X, con shmid: %d\n", (int)shared_memory,shmid); // hacemos que el aera de memoria compartida tenga la estructura de "sharedComm" sharedComm = (struct communicate *)shared_memory; //creamos proceso hijo! if(!fork()){/////PROCESO HIJO - PRODUCTOR printf("Dame 2 numeros: \n"); scanf("%d",&sharedComm->A); scanf("%d",&sharedComm->B); int i; sharedComm->numPrimos=0; for (i=sharedComm->A;i<=sharedComm->B;i++){ sharedComm->numPrimos+=esPrimo(i); } sharedComm->recibido = 1;//indica al consumidor que está listo if (shmdt(shared_memory) == -1) { fprintf(stderr, "Error en shmdt\n"); exit(EXIT_FAILURE); } printf("Proceso Hijo (Productor) terminó satisfactoriamente \n"); } else{////////////////////////PROCESO PADRE - CONSUMIDOR sharedComm->recibido = 0; while (!sharedComm->recibido); printf("Numeros primos desde %d hasta %d: %d\n\n",sharedComm->A,sharedComm->B,sharedComm->numPrimos); // el proceso se des-asocia del area de memoria compartida if (shmdt(shared_memory) == -1) { fprintf(stderr, "Error en shmdt\n"); exit(EXIT_FAILURE); } if (shmctl(shmid, IPC_RMID, 0) == -1) { fprintf(stderr, "Error en shmctl (IPC_RMID)\n"); exit(EXIT_FAILURE); } } exit(EXIT_SUCCESS); }
int main(){ float valorA, valorB, valorC; float resultado1, resultado2; int leerNumerodivisores; int cantidadDeDivisores; int leerNumeroPrimo; int leerNumeroMultiplo; int leerRangoInferior, leerRangoSuperior; int numeroMenu; do{ numeroMenu = menu(); switch(numeroMenu){ case 1: printf("Ingrese el valor de a, b y c:\n"); do{ scanf("%f", &valorA); if(valorA==0){ printf("Error, ingrese un numero diferente a 0\n"); } }while(valorA==0); scanf("%f", &valorB); scanf("%f", &valorC); if((pow(valorB,2)-4*valorA*valorC)<0){ printf("no tiene solucion dentro de los numeros reales\n"); }else{ resultado1 = (-valorB+sqrt(pow(valorB,2)-4*valorA*valorC))/2*valorA; resultado2 = (-valorB-sqrt(pow(valorB,2)-4*valorA*valorC))/2*valorA; printf("los resultados son %f y %f\n", resultado1, resultado2); } break; case 2: do{ printf("Ingrese un numero\n"); scanf("%d", &leerNumerodivisores); if(leerNumerodivisores<1){ printf("Error, ingrese un numero mayor que 0\n"); } }while(leerNumerodivisores<1); cantidadDeDivisores = divisores(leerNumerodivisores); printf("El numero %d tiene %d divisores\n", leerNumerodivisores, cantidadDeDivisores); break; case 3: printf("Ingrese un numero\n"); do{ scanf("%d", &leerNumeroPrimo); if(leerNumeroPrimo<1){ printf("Error, ingrese un numero mayor que 0\n"); } }while(leerNumeroPrimo<1); if(esPrimo(leerNumeroPrimo)==1){ printf("el numero %d es primo\n\n", leerNumeroPrimo); }else{ printf("el numero %d no es primo\n\n", leerNumeroPrimo); } break; case 4: printf("Ingrese un numero\n"); do{ scanf("%d", &leerNumeroMultiplo); if(leerNumeroMultiplo<1){ printf("Error, ingrese un numero mayor que 0\n"); } }while(leerNumeroMultiplo<1); printf("Ingrese los rangos inferior y superior\n"); do{ scanf("%d", &leerRangoInferior); scanf("%d", &leerRangoSuperior); if(leerRangoInferior>leerRangoSuperior){ printf("Error, el rango inferior debe ser menor o igual que el rango superior\n"); } }while(leerRangoInferior>leerRangoSuperior); multiplos(leerNumeroMultiplo, leerRangoInferior, leerRangoSuperior); break; case 5: printf("¡Hasta otra!\n"); break; } }while(numeroMenu!=5); return 0; }