Advertisement
shuhan_mirza

uva_100 java

Oct 25th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. package uva_100;
  2.  
  3. import java.util.*;
  4. import java.io.*;
  5.  
  6. public class Uva_100 {
  7.  
  8. public static void main(String[] args) throws IOException{
  9.  
  10. Scanner scan = new Scanner(System.in);
  11.  
  12. int i, j, cycle, a, b, c, max;
  13. long n;
  14. c = 0;
  15.  
  16. while (scan.hasNext())
  17. {
  18. a = scan.nextInt();
  19. b = scan.nextInt();
  20.  
  21. max = 0;
  22.  
  23. if (a > b)
  24. {
  25. c = a;
  26. a = b;
  27. b = c;
  28. }
  29.  
  30. for (i = a; i <= b; i++) {
  31. n = i;
  32. cycle = 1;
  33.  
  34. for (j = 1; j > 0; j++) {
  35. if (n == 1) {
  36. if (a == 1 && b == 1) {
  37. max++;
  38. }
  39. break;
  40. } else if (n % 2 == 0) {
  41. n = n / 2;
  42. cycle++;
  43. } else {
  44. n = (3 * n) + 1;
  45. cycle++;
  46. }
  47.  
  48. if (cycle > max) {
  49. max = cycle;
  50. }
  51. }
  52. }
  53.  
  54. if (c == b) {
  55. System.out.println(String.format("%d %d %d",b, a, max));
  56. } else {
  57. System.out.println(String.format("%d %d %d",a, b, max));
  58. }
  59. }
  60.  
  61. }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement