Skip to content

Instantly share code, notes, and snippets.

@lnds
Created May 2, 2012 01:42
Show Gist options
  • Select an option

  • Save lnds/2572943 to your computer and use it in GitHub Desktop.

Select an option

Save lnds/2572943 to your computer and use it in GitHub Desktop.
solución problema de Siracusa
#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