#! ruby # yukicoder My Practice # author: Leonardone @ NEETSDKASU require "bigdecimal" require "bigdecimal/util" K = 2000 BigDecimal::limit K def bd(x); BigDecimal::new(x, K); end b = bd("10005").sqrt(K).mult(bd("426880"), K) c = bd("13591409") d = bd("545140134") e = bd("640320") p1 = bd(1) m1 = bd(-1) v = bd(0) 50.times do |n| x = n.even? ? p1 : m1 (3 * n + 1).upto(6 * n) {|i| x = x.mult(i, K)} x = x.mult c.add(d.mult(n, K), K), K y = p1 1.upto(n) {|i| y = y.mult(i, K) } x = x.div y.power(3, K), K x = x.div e.power(3 * n, K), K v = v.add x, K end q = b.div(v, 20000).split[1] z = gets if z[0] != '3' puts "%s 3" % [z[0]] exit end 1.upto(20000) do |i| if q[i] != z[i + 1] puts "%s %s" % [z[i + 1], q[i]] exit end end