fork download
  1. require 'bigdecimal'
  2. t=gets.to_i
  3. t.times{
  4. p1,k1=gets.split(" ")
  5. p2=BigDecimal(p1,40)
  6. k2=BigDecimal(k1,40)
  7. t1=BigDecimal("1.0",40)
  8. t0=BigDecimal("0.0",40)
  9. p1=p1.to_f
  10. k1=k1.to_i
  11. ans=1
  12. if k1==1 then
  13. puts 1.0
  14. elsif k1==2 then
  15. puts p1.to_f+2.0*(1.0-p1.to_f)
  16. elsif p2==t0 then
  17. puts k1.to_f
  18. else
  19. #qk=(1-p1)**(k1-1)
  20. #ans=(1.0-qk)/p1+qk
  21. qk=((t1-p2)**(k2-t1))
  22. puts ((1.0-qk)/p2+qk).round(40).to_s("F")
  23. end
  24. }
Success #stdin #stdout 0.01s 6616KB
stdin
7
0.035 407
0.202 122
0.937 325
0.504 75
0.801 309
0.553 3
0.922 371
stdout
28.5714141652601898417863867675558717685975
4.9504950494994677080371991688193505350192
1.067235859124866595517609391675560298826
1.9841269841269841269840982303301167110979
1.248439450686641697877652933832709113608
1.646809
1.0845986984815618221258134490238611713666