Quick actions

cmd+k|ctrl+k

Navigation

Languages

Longest Collatz

Snippet info

Language

Java

Visibility

public

Author

kylemcn1

Created

2017-01-06T01:12:15Z

Updated

2017-01-06T01:12:15Z

class Main {

	public static void main(String[] args) {
		int x = 910106;
		int n = 0;
		int count = 0;
		int max = 1;
		int maxn =1;
		//while (x<1000000) {
			
			
			x+=1;
			n=x;
			count=0;
			
			while (n>1) {
				if(n%2==0) {
					
					n/=2;
				}
				
				else {
					
					n=3*n+1;
				}
				
				count+=1;
		System.out.println(n);
			}
			if(count>max) {
				max=count;
				maxn=x;
				System.out.println(maxn + " " + max);
			}
			
		//}
		//System.out.println(maxn);
		
	}
}
INFO