On 09/11/2012 12:13, Rodrigo Mosconi wrote:
>> #include "primo.h"
>>
>> u_int8_t        eh_primo(u_int32_t numero){
>>         u_int32_t i;
>>
>>         if((numero>2) && ((numero % 2) == 0)){
>>                 return 0;
>>         }
>>
>>         for(i=3; i <= (numero / 2); i = i + 2){
>>                 if((numero % i) == 0){
>>                         return 0;
>>                 }
>>         }
>>         return 1;
>> }
>>
> 
> vc somente precisa testar até sqrt(numero) -- Princípio de Eratóstenes
> -------------------------
> Histórico: http://www.fug.com.br/historico/html/freebsd/
> Sair da lista: https://www.fug.com.br/mailman/listinfo/freebsd
> 

Sim, mas como dito anteriormente, o programa é para demorar mesmo, para
que a vantagens fiquem evidentes.
-------------------------
Histórico: http://www.fug.com.br/historico/html/freebsd/
Sair da lista: https://www.fug.com.br/mailman/listinfo/freebsd

Responder a