Mr.A was studying about fractions in his mathematics lecture. He learned that every fraction can be represented in reduced form.
A reduced form of fraction a/b can be represented as p/q such that gcd(p,q)=1 where gcd is greatest common divisor.
For example , reduced form of fraction 2/4 is 1/2.
A fraction a/b is called good fraction if its reduced form p/q satisfies the following conditions :
For example , some of the good fractions are (1/3),(2/2),(2/6),...
but (2/5),(4/10),(3/1) are not good fractions.
Now, Mr.A was given an undirected graph with N nodes and M edges. The given graph does not have any multiple edges or self loops.
Now, task assigned to Mr.A was to find answer for every node i ,
Let s be set of numbered/indexed nodes which are not adjacent to node i .
Calculate number of good fractions a/b where 1≤a≤N and 1≤b≤N such that their reduced form p/q satisfies the following conditions ,
Mr. A is stuck in this task, please help him.
Example
Consider n = 3, m = 1.
Edges:
You must determine the output as mentioned above.
The output is 0 0 1.
For node 1: 0
set s is (2,3)
(2/2),(3/3)... are good fractions but in their reduced form, it becomes (1/1) but the numerator is not present in set (s).
For node 2: 0
As q is even
For node 3: 1
set s is (1)
(1/3) is the only good fraction.
Function description
Complete the solve function provided in the editor. This function takes the following 3 parameters and returns the output as mentioned above.
Input Format:
Note: This is the input format that you must use to provide custom input (available above the Compile and Test button).
Output Format:
For each node i , print the output as mentioned above.
Constraints:
1≤T≤5
1≤N≤100,0000≤M≤min(N∗(N−1)2,100000)
Code snippets (also called starter code/boilerplate code)
This question has code snippets for C, CPP, Java, and Python.
For node 1:0
set s is (2,3,4,5,6,8,9,10,11,12,13,14,15)
(2/2),(3/3)... are good fractions but in their reduced form , it becomes (1/1) but numerator is not present in set (s).
For node 7:2
set s will be (3,4,8,9,10,11,12,13,14,15)
(3/7),(6/14) are only good fractions satisfying.
(1/7),(2/14),(5/7),(10/14) are also good fractions but after reducing it , it becomes (1/7),(1/7),(5/7),(5/7) but 1 and 5 do not belong to set s.