fork download
  1. import math
  2.  
  3. tc = int(input())
  4.  
  5. def pw(a, b):
  6. res = 1
  7. while b > 0:
  8. if b % 2 == 1: res = res * a
  9. a = a * a
  10. b = b // 2
  11. return res
  12.  
  13. def solve():
  14. n, k = map(int, input().split())
  15. a, b = (k-n+1)*pw(k+1,n-1), pw(k,n)
  16.  
  17. t = math.gcd(a, b)
  18. a = a // t
  19. b = b // t
  20. print(a, b)
  21.  
  22. for i in range(0,tc):
  23. solve()
Success #stdin #stdout 0.11s 14188KB
stdin
40 
1 6 
1 7 
1 8 
1 9 
1 10 
2 6 
2 7 
2 8 
2 9 
2 10 
3 6 
3 7 
3 8 
3 9 
3 10 
4 6 
4 7 
4 8 
4 9 
4 10 
5 6 
5 7
5 8 
5 9 
5 10 
6 6 
6 7 
6 8 
6 9 
6 10 
7 7 
7 8 
7 9 
7 10 
8 8 
8 9 
8 10 
9 9 
9 10 
10 10 
stdout
1 1
1 1
1 1
1 1
1 1
35 36
48 49
63 64
80 81
99 100
49 54
320 343
243 256
700 729
121 125
343 432
2048 2401
3645 4096
2000 2187
9317 10000
2401 3888
12288 16807
6561 8192
50000 59049
43923 50000
16807 46656
65536 117649
177147 262144
400000 531441
161051 200000
262144 823543
531441 1048576
1000000 1594323
1771561 2500000
4782969 16777216
20000000 43046721
58461513 100000000
100000000 387420489
214358881 500000000
2357947691 10000000000