fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. class Number {
  11. int a, b;
  12.  
  13. Number (int a, int b) {
  14. this.a = a;
  15. this.b = b;
  16. }
  17.  
  18. private int GCD(int a, int b) {
  19. if (b == 0) {
  20. return a;
  21. }
  22. return GCD(b, a % b);
  23. }
  24.  
  25. public Number applyGCD() {
  26. int temp = GCD(this.a, this.b);
  27. return new Number(this.a / temp, this.b / temp);
  28. }
  29.  
  30. public Number mul(Number num) {
  31. return new Number(this.a * num.a, this.a * num.a).applyGCD();
  32. }
  33.  
  34. public Number add(Number num) {
  35. return new Number(this.a * num.b + this.b * num.a, this.b * num.b).applyGCD();
  36. }
  37.  
  38. public Number sub(Number num) {
  39. Number temp = new Number(-num.a, num.b);
  40. return this.add(temp);
  41. }
  42.  
  43. public Number divide(Number num) {
  44. Number temp = new Number(num.b, num.a);
  45. return this.mul(temp);
  46. }
  47.  
  48. public String toString() {
  49. return "[" + this.a + "/" + this.b + "]";
  50. }
  51. }
  52.  
  53. public void run() {
  54. Number x2 = new Number(17, 4);
  55. Number x1 = new Number(4, 1);
  56. Number x0 = null;
  57. Number n108 = new Number(108, 1);
  58. Number n815 = new Number(815, 1);
  59. Number n1500 = new Number(1500, 1);
  60. for (int i = 0; i < 28; i++) {
  61. x0 = x1;
  62. x1 = x2;
  63. x2 = n108.add((n815.sub(n1500.divide(x0))).divide(x0)).applyGCD();
  64. }
  65. System.out.println(x2.applyGCD());
  66. }
  67.  
  68. public static void main (String[] args) throws java.lang.Exception
  69. {
  70. new Ideone().run();
  71. }
  72. }
Success #stdin #stdout 0.06s 380160KB
stdin
Standard input is empty
stdout
[109/1]