#include <stdio.h>
int main(void) {
printf("0 é primo %s\n", IsPrime
(0) ? "sim" : "nao"); printf("1 é primo %s\n", IsPrime
(1) ? "sim" : "nao"); printf("3 é primo %s\n", IsPrime
(3) ? "sim" : "nao"); printf("2 é primo %s\n", IsPrime
(2) ? "sim" : "nao"); printf("4 é primo %s\n", IsPrime
(4) ? "sim" : "nao"); printf("5 é primo %s\n", IsPrime
(5) ? "sim" : "nao"); printf("7 é primo %s\n", IsPrime
(7) ? "sim" : "nao"); printf("9 é primo %s\n", IsPrime
(9) ? "sim" : "nao");
return 0;
}
/* Retorna 1 para numeros primo ou 0 para numeros que nao sao primos.*/
int IsPrime(unsigned int number) {
if (number <= 1) return 0; // se o numero for menor ou igual a 1 então nao é primo.
unsigned int i;
for (i = 2; i * i <= number; i++) {
if (number % i == 0) return 0;
}
return 1;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CgppbnQgbWFpbih2b2lkKSB7CiAgICBwcmludGYoIjAgw6kgcHJpbW8gJXNcbiIsIElzUHJpbWUoMCkgPyAic2ltIiA6ICJuYW8iKTsKICAgIHByaW50ZigiMSDDqSBwcmltbyAlc1xuIiwgSXNQcmltZSgxKSA/ICJzaW0iIDogIm5hbyIpOwogICAgcHJpbnRmKCIzIMOpIHByaW1vICVzXG4iLCBJc1ByaW1lKDMpID8gInNpbSIgOiAibmFvIik7CiAgICBwcmludGYoIjIgw6kgcHJpbW8gJXNcbiIsIElzUHJpbWUoMikgPyAic2ltIiA6ICJuYW8iKTsKICAgIHByaW50ZigiNCDDqSBwcmltbyAlc1xuIiwgSXNQcmltZSg0KSA/ICJzaW0iIDogIm5hbyIpOwogICAgcHJpbnRmKCI1IMOpIHByaW1vICVzXG4iLCBJc1ByaW1lKDUpID8gInNpbSIgOiAibmFvIik7CiAgICBwcmludGYoIjcgw6kgcHJpbW8gJXNcbiIsIElzUHJpbWUoNykgPyAic2ltIiA6ICJuYW8iKTsKICAgIHByaW50ZigiOSDDqSBwcmltbyAlc1xuIiwgS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