Waterloo 2022 Fall C - Squaring the Triangle

View as PDF

Submit solution

Points: 17
Time limit: 5.0s
Memory limit: 256M

Author:
Problem type
2022 Fall Waterloo Local Contest, Problem C

Wesley creates a graph G that contains N vertices. For each pair of vertices {u,v}, there is a probability of pq that an edge exists between u and v. The probabilities are independent of each other.

Let (G) denote the number of triangles in G. A triangle is a set of 3 vertices that are connected by 3 edges.

Please help Wesley find the expected value of ((G))2.

Input Specification

Line 1 contains integer T (1T106), the number of cases.

T lines follow. The ith line contains integers N,p,q (3N106,1p<q106), separated by spaces.

Output Specification

Output T lines, one line for each case.

Suppose the answer to the ith case is PQ, in lowest terms. Output PQ1(mod109+7). That is, output a number R such that 0R<109+7 and PRQ(mod109+7).

Sample Input

Copy
2
3 1 2
4 1 2

Sample Output

Copy
125000001
875000007

Note

The original problem did not have a sample.


Comments

There are no comments at the moment.