Programmers/Level 1
[프로그래머스 1] 콜라츠 추측 (C/C++)
워니-
2019. 10. 19. 03:06
#include <string> #include <vector> #include <iostream> using namespace std; int solution(int num) { int answer = 0; long long n = num; while(1) { if(n == 1) { break; } if(answer >= 500) { return -1; } if(n % 2 == 0) { n /= 2; } else { n *= 3; n += 1; } answer++; } return answer; } | cs |