Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ProjectEuler
- {
- public static void main(String[] args) throws Exception
- {
- System.out.println(m1());
- }
- public static int m1() throws Exception
- {
- int i = 2;
- int ans = 0;
- int chain = 0;
- int maxChain = 0;
- for(; i < 1000000; i++)
- {
- int num = i;
- while(num != 1)
- {
- if(num % 2 == 0)
- num /= 2;
- else
- num = num*3 + 1;
- chain++;
- }
- if(chain > maxChain)
- {
- ans = i;
- maxChain = chain;
- }
- }
- return ans;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement