Created
October 24, 2019 14:38
-
-
Save byyam/0e20d7cf28d0162f9e47e660abd73bd0 to your computer and use it in GitHub Desktop.
collatz conjecture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <limits.h> | |
const int s = 30; | |
bool f(long i) | |
{ | |
int r = 0; | |
for(;;) | |
if (i < 0 || r > s) return false; | |
else if (i == 1) break; | |
else{r ++;i = i % 2 ? 3*i + 1 : i/2;} | |
return (r==s); | |
} | |
int main(){ | |
for(long i = 1; i < LONG_MAX; i++) if (f(i)) printf("%ld ", i); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment