fork(1) download
  1. #include <iostream>
  2. #include <math.h>
  3. using namespace std;
  4.  
  5. int main() {
  6. long long collatz(long long),n,test,k,count=0;
  7. for(n=2;n<pow(10,7)/2;n++)
  8. {
  9. k=1;
  10. test=n;
  11. while(collatz(test)!=1)
  12. {
  13. test=collatz(test);
  14. k++;
  15. }
  16. if(k%2==1)
  17. count++;
  18. }
  19. cout<<count;
  20. return 0;
  21. }
  22. long long collatz(long long x)
  23. {
  24. return (x%2==0) ? x/2 : 3*x+1;
  25. }
Success #stdin #stdout 12.64s 3412KB
stdin
Standard input is empty
stdout
2497047