Intersection of fibonacci sequence and prim numbers
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

prim.c 389B

12345678910111213141516171819202122232425262728293031
  1. #include <stdio.h>
  2. #include <stdbool.h>
  3. #include <limits.h>
  4. #define typ long long int
  5. bool is_it_a_prim(typ* x){
  6. int k = 2;
  7. while(k < *x){
  8. if(*x % k == 0)
  9. return false;
  10. k++;
  11. }
  12. return true;
  13. }
  14. int main(void){
  15. typ fn = 0, fn_1 = 1, fn_2 = 0;
  16. int i = 2;
  17. while(fn < LLONG_MAX)
  18. {
  19. fn = fn_1 + fn_2;
  20. if(is_it_a_prim(&fn))
  21. printf("%d\t%llu\n",i ,fn);
  22. fn_2 = fn_1;
  23. fn_1 = fn;
  24. i++;
  25. }
  26. return 0;
  27. }