Created
May 2, 2012 01:42
-
-
Save lnds/2572943 to your computer and use it in GitHub Desktop.
solución problema de Siracusa
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 <stdlib.h> | |
| #include <stdio.h> | |
| typedef unsigned long long INT; | |
| INT orbita(INT n) { | |
| INT largo = 0; | |
| do { | |
| n = (n % 2) == 0 ? n / 2 : n*3+1; | |
| largo++; | |
| } while (n>1); | |
| return largo; | |
| } | |
| int main(int argc, char* argv[]) { | |
| INT n = (argc == 2) ? atol(argv[1]) : 0; | |
| INT lmax = 0; | |
| INT index = 0; | |
| for (INT i = n; i >= 1; --i) { | |
| INT l = orbita(i); | |
| if (l > lmax) { lmax = l; index = i; } | |
| } | |
| printf ("%llu\n", index); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment