fork(2) download
  1. import java.io.*;
  2. import java.util.*;
  3. class CLATTK{
  4. public static void main(String args[])throws Exception{
  5. Scanner sc = new Scanner(System.in);
  6. int T = sc.nextInt();
  7. while(T-->0){
  8. int H = sc.nextInt();
  9. int W = sc.nextInt();
  10. double out = calculate(H, W);
  11. System.out.printf("%.7f%n",out);
  12. }
  13. }
  14.  
  15. static double calculate(int H, int W){
  16. long sum = W*W*(H-1);
  17. long a = W-1;
  18. long b = W-(H-1);
  19. long n = W-H;
  20. if(n>0)
  21. sum += 2*(n*a*b + n*(n+1)*(2*n+1)/6 - (a+b)*n*(n+1)/2);
  22. return (double)sum/(W*W);
  23. }
  24. }
  25.  
Success #stdin #stdout 0.14s 321344KB
stdin
2
2 2
2 3
stdout
1.0000000
1.2222222