void antprimo(int n) { int i, j=0, count =0; if(primo(n)) { for(i=n-1; i>=2; i--) { if(primo(i) && count<2) count++; } } int v[count]; for(i=n-1; i>=2; i--) { if(primo(i)) { v[j] = i; j++; } if(j>=count) break; } printf("\nOs dois primos antecessores são:\n"); imprimevetor(v, count); }
void cria_num_primos(int *p,int *q){ do{ *p = rand_int(NUM_MAX); }while(primo(*p) == 0); do{ *q = rand_int(NUM_MAX); }while((primo(*q) == 0)&&(*p != *q)); //printf("numero primos %ld %ld\n",*p,*q); }
main (int argc, char *argv[] ) { if (argc != 2) { printf("Too few arguments supplied.\n"); return 0; } int nth = atoi(argv[1]); // Cria vetor do tamanho maximo para salvar os primos int primes[SIZE]; // Primeiro primo é o numero 2 primes[0] = 2; int i = 3; int count = 1; if (nth <= 6) { while (count < nth) { while (primo(i++, primes, count) == 0); count++; } } else { // Acha a estimativa inferior para Pn com base em n de forma paralela int logn = log(nth); int loglogn = log(logn); int estimate = nth*(logn + loglogn - 1); #pragma omp parallel \ shared (estimate) \ private (i) #pragma omp for reduction (+ : count) for (i = 3; i < estimate; i++) { if (primo(i++, primes, count)) count++; } while (count < nth) { while (primo(i++, primes, count) == 0); count++; } } printf("%d\n", i - 1); }
int main(){ int i, j; char atual; std::map<char, int> letras; for(i = 1, atual = 'a'; i < 27; i++, atual++) { letras[atual] = i; } for(atual = 'A'; i < 53; i++, atual++) { letras[atual] = i; } std::vector<int> primos; primos.push_back(2); for(i = 3; i < MAXIMO; i++) { for(j = 0; j < primos.size(); j++) { if(i % primos[j] == 0) break; } if(j == primos.size()) primos.push_back(i); } std::string palavra; while(std::cin >> palavra) { int valor = strToInt(palavra, letras); if(primo(valor, primos)) { std::cout << "It is a prime word.\n"; } else { std::cout << "It is not a prime word.\n"; } } return 0; }
int main() { long i,acu; clock_t begin, end; double time_spent; begin = clock(); acu = 0; for(i=2;i<=2000000;i++){ printf("\n %ld",i); if(primo(i)== 1){ acu = acu + i; } } end = clock(); time_spent = (double)(end-begin) / CLOCKS_PER_SEC; printf("\n La suma de los primos es:%ld",acu); printf("\n Tiempo de ejecucion:%f", time_spent); return 0; }
int main() { int desde, hasta; scanf("%d %d",&desde, &hasta); printf("%d", primo(desde, hasta)); return 0; }
int main(int argc, char const *argv[]) { int i, n; int count; if(argc < 2) return 1; n = atoi(argv[1]); count = 0; if(n >= 2) count++; #pragma omp parallel for \ default(shared) private(i) \ reduction(+:count) for (i = 3; i < n; i+=2) { if (primo(i)){ count++; } } printf("%d\n", count); }
int main() { Entero_grande i, n; #ifdef _OPENMP double t1 = omp_get_wtime(); #endif int numberOfThreads; #pragma omp parallel numberOfThreads = omp_get_num_threads(); n = 2; /* Por el 1 y el 2 */ #pragma omp parallel for schedule(runtime) for (i = 3; i <= N; i += 2){ if (primo(i)) { #pragma omp atomic n++; } } #ifdef _OPENMP double t2 = omp_get_wtime(); printf("looptime: %f seconds \n", t2-t1); #endif printf("Entre el 1 y el %llu hay %llu numeros primos.\n", N, n); return 0; }
int main(int argn, char** argv) { unsigned long int i = 0, t = 0, n = 0; unsigned short n_threads = omp_get_max_threads(); printf("using %u threads.\n", n_threads); omp_set_num_threads(n_threads); if (argn != 2) { printf("Please pass a value as argument to the program and no other arguments.\n"); return 0; } n = strtol(argv[1], NULL, 0); if (n <= 1) { printf("Please pass a valid value (larger than 1, which is not prime) as argument to the program, the argument passed was '%s'.\n", argv[1]); return 0; } #pragma omp parallel for for (i = 2; i <= n; ++i) #pragma omp critical t += primo(i); printf("Existem %ld números primos entre 1 e %ld (inclusos).\n", t, n); return 0; }
void main(int argc, char const *argv[]) { int vetor[11], i, totalPrimos = 0, fila; struct msg msg; fila = msgget(KEY,0600|IPC_CREAT); srand(time(NULL)); for (i = 0; i < 11; i++) { vetor[i] = rand() % 10; } pid_t p1, p2; p1 = fork(); if (p1 > 0) { p2 = fork(); if (p2 > 0) { int cont = 0; msgrcv(fila,&msg,sizeof(msg.totalPrimos),0,0); cont = msg.totalPrimos; msgrcv(fila,&msg,sizeof(msg.totalPrimos),0,0); cont += msg.totalPrimos; wait(NULL); wait(NULL); msgctl(fila, IPC_RMID, NULL); printf("Total de primos = %d\n", cont); } else { for (i = (N/2); i < N; i++) { totalPrimos += primo(vetor[i]); } msg.totalPrimos = totalPrimos; msg.totalPrimos = 1; msgsnd(fila,&msg,sizeof(msg.totalPrimos),0); } } else { for (i = 0; i < (N/2); i++) { totalPrimos += primo(vetor[i]); } msg.totalPrimos = totalPrimos; msgsnd(fila,&msg,sizeof(msg.totalPrimos),0); } }
main(){ int num; do { printf("Digite um numero inteiro e positivo: "); scanf("%d", &num); } while (num <= 0); primo(num); }
void main (){ int primo (int); //PROTOTIPO int n,y; clrscr(); printf("DIGITE UN NUMERO\n"); scanf("%d",&n); y=primo(n); if (y) printf("PRIMO\n"); else printf("NO ES PRIMO\n"); getch(); }
void sucprimo(int n) { int i, j=0; int v[2]; for(i=n+1; j<2; i++) { if(primo(i)) { v[j] = i; j++; } } printf("\nOs dois primos antecessores são:\n"); imprimevetor(v, 2); }
int main(int argc, char const *argv[]) { int i, n; int count; if(argc < 2) return 1; n = atoi(argv[1]); count = 0; for (i = 2; i < n; ++i) { if (primo(i)){ count++; } } printf("%d\n", count); }
int main(){ int valor,prm; printf("Dame el numero: "); scanf("%d",&valor); prm=primo(valor); if(prm==2) { printf("El numero es primo"); } else { printf("El numero es compuesto"); } return 0; }
int main(void) { unsigned int bcd_max = 0; // Capacidade inicial BCD unsigned int i, received; // indexadores de linhas e colunas for(i=0; i < MAXINT ; i++){ bcd_max = bcdRSt(); while(bcd_max <= 0){ // pooling? bcd_max = bcdRSt(); } // leitura do buffer received = bcdRRd(); primo(received); } return 0; }
int main() { Entero_grande i, n; int numberOfThreads; #pragma omp parallel numberOfThreads = omp_get_num_threads(); n = 2; /* Por el 1 y el 2 */ #pragma omp parallel for private(i) //reduction(+:n) for (i = 3; i <= N; i += 2) { if (primo(i)) { #pragma omp atomic n++; } } printf("Entre el 1 y el %llu hay %llu numeros primos.\n", N, n); return 0; }
main(int argc, char *argv[ ]){ int n = atoi (argv[1]); int i; int nPrimos = 1; if (n == 2) { printf("0"); return 0; } #pragma omp parallel for \ default(shared) private(i) \ schedule(static,10) \ reduction(+:nPrimos) for (i = 3; i < n; i = i + 2) { if (primo (i)) { nPrimos++; } } /*for (i = 3; i < n; i = i + 2) { if (primo (i)) { nPrimos++; } }*/ printf("%d\n", nPrimos); /*int n = 104395301; if (primo(n)) printf("%d é primo.\n", n); else printf("%d não é primo.\n", n);*/ }
int contarEspecial(int vet[], int numElementos, int *qtPares, int *qtImpares, int *qtPrimos, int *qtFibonacci) { int i,zero = 0; *qtPares = zero; *qtImpares = zero; *qtPrimos = zero; *qtFibonacci = zero; for(i=0;i<numElementos;i++) { //verifica pares e impares if (vet[i] % 2 == 0) (*qtPares)++; else (*qtImpares)++; //verifica se é primo if (primo(vet,i)) (*qtPrimos)++; //verifica se é de fibonacci if(fibonacci(vet,i)) (*qtFibonacci)++; } }
int main() { int num; /* Lê o número */ printf("Entre com o numero: "); scanf("%d", &num); /* Através de uma função, verifica e imprime se um número é par ou primo */ if ((num%2) == 0 && num != 0) { printf("O numero e par\n"); } else if (primo(num)) printf("Primo\n"); else printf("Nao e primo\n"); system("PAUSE"); return 0; }