반응형
public class Main {

	public static void main(String[] args) {

		int n = 0;
		int rangeCount = 0;
		int answer = 0;
		long one = 0L;
		int temp = 0;

		while (n <= 1000000) {

			n++;
			one = n;
			temp = 0;

			while (one != 1) {

				if (one % 2 == 0) {

					one = one / 2;
					temp++;

				} else {

					one = 3 * one + 1;
					temp++;

				}

			}

			if (rangeCount < temp) {

				rangeCount = temp;
				answer = n;

			}

		}

		System.out.println("걸린 과정 = " + rangeCount);
		System.out.println("해당 우박수 = " + answer);

	}

}
반응형

+ Recent posts