P13904 [HackerRank] sherlock AND probability
提高-
题目描述

Watson gave a string $\mbox{S}$ to Sherlock. It is $N$ characters long and consists of only 1s and 0s. Now he asks: Given an integer $\mbox{K}$, I'll pick two indices $\boldsymbol{i}$ and $j$ at random between $\mbox{1}$ and $N$, both inclusive. What's the probability that both $S[i]$ and $S[j]$ are 1 and $|i-j|\leq K$?

Input Format

First line contains $\mathbf{T}$, the number of testcases. Each testcase consists of [MATH11] and $\mbox{K}$ in one line and string in second line.

Output Format

Print the required probability as an irreducible fraction. If required answer is 0, output 0/1.

Constraints

$1\leq T\leq10^5$

$1\leq N\leq10^5$

$1\leq K\leq N$

$1\leq\text{Sum of N over all testcases in one file}\leq10^5$

Sample input

2
4 3
1011
4 1
1011

Sample output

9/16
5/16

Explanation

test1: Out of 16 choices, 9 pairs of $(i,j)$ satisfy our condition.

(1,1), (1,3), (1,4), (3,1), (3,3), (3,4), (4,1), (4,3), (4,4)

test2: Out of 16 choices, 5 pairs of $(i,j)$ satisfy our condition.

(1,1), (3,3), (4,4), (4,3), (3,4)

输入格式

见题面

输出格式

见题面

样例输入
2 4 3 1011 4 1 1011
样例输出
9/16 5/16