Wesley is taking a course on the network simplex algorithm. Unfortunately, a term that comes up often in class is simple graph. When the professor asked him what the minimum number of vertices a simple, undirected graph with edges can have, he was unable to answer. Please help Wesley with this very simple task!
A graph is simple if it contains no self loops (an edge from a vertex to itself) and no multiple edges between any two vertices. Note that an edge between vertices and is the same as an edge between and .
Since solving this problem once is easy, you will be asked to solve it times!
Constraints
For this problem, you will be required to pass all the samples in order to receive any points. In addition, you must pass all previous subtasks to earn points for a specific subtask.
Subtask | Points | |
---|---|---|
|
||
|
||
|
Input Specification
There will be multiple test cases.
The first line contains a single integer , the number of test cases.
Each test case consists of a single integer on its own line, the number of edges in the graph.
Note that a 64-bit integer may need to be used to store . In C++, this can be done with long long
. In Java, this can be done with long
. In Python, the standard int
will suffice.
Output Specification
This problem is graded with an identical
checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n
character and that there are no trailing spaces.
For each test case, output a single integer on its own line, the minimum number of vertices a simple, undirected graph with edges can have.
Sample Input
2
1
4
Sample Output
2
4
Sample Explanation
One possible graph for the first test case is shown below.
One possible graph for the second test case is shown below.
Comments
Did you figure out how to fix it? I am having the same problem
I don't understand how
print(int(math.ceil((1+(math.sqrt(1+8*x)))/2)))
is wrong. I keep on getting WA for Batch 4 Case 5.there's some rounding inaccuracies,
found that out the hard way XD (sorry)try finding a way around using decimals