The 3n + 1 problem (콜라츠 추측)
문제 출처 : http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=36 * http://ko.wikipedia.org/wiki/%EC%BD%9C%EB%9D%BC%EC%B8%A0_%EC%B6%94%EC%B8%A1 #include <stdio.h> long getMaxCycleLength( long i, long j) { long n, temp; long maxCycleLength = 0 ; if (j < i) { temp = i; i = j; j = temp; } for (n = i; i <= j; i++) { long cycleLengh = 1 ; n = i; while (n != 1 ) { if (n% 2 == 0 ) n >>= 1 ; else n = n* 3 + 1 ; cycleLengh++; } ...
댓글
댓글 쓰기