Advertisement
Guest User

P14

a guest
Sep 17th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. public class ProjectEuler
  2. {
  3.  
  4. public static void main(String[] args) throws Exception
  5. {
  6. System.out.println(m1());
  7. }
  8.  
  9. public static int m1() throws Exception
  10. {
  11. int i = 2;
  12. int ans = 0;
  13. int chain = 0;
  14. int maxChain = 0;
  15.  
  16. for(; i < 1000000; i++)
  17. {
  18. int num = i;
  19. while(num != 1)
  20. {
  21. if(num % 2 == 0)
  22. num /= 2;
  23. else
  24. num = num*3 + 1;
  25. chain++;
  26. }
  27.  
  28. if(chain > maxChain)
  29. {
  30. ans = i;
  31. maxChain = chain;
  32. }
  33. }
  34.  
  35. return ans;
  36. }
  37.  
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement