Wesley's Anger Contest 1 Problem 1 - Simply a Simple Simplex Problem

View as PDF

Submit solution

Points: 4 (partial)
Time limit: 2.0s
Memory limit: 256M

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

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 M 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 u and v is the same as an edge between v and u.

Since solving this problem once is easy, you will be asked to solve it T times!


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 T, M
1 10\% 1 \le T \le 10
1 \le M \le 10
2 40\% 1 \le T \le 1\,000
1 \le M \le 1\,000
3 50\% 1 \le T \le 1\,000
1 \le M \le 10^{18}

Input Specification

There will be multiple test cases.

The first line a single integer T, the number of test cases.

Each test case consists of a single integer M on its own line, the number of edges in the graph.

Note that a 64-bit integer may need to be used to store M. 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 a vertices a simple, undirected graph with M edges can have.

Sample Input


Sample Output


Sample Explanation

One possible graph for the first test case is shown below.

One possible graph for the second test case is shown below.


  • 6
    Togohogo1  commented on Dec. 2, 2019, 9:18 p.m. edited

    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.

    • 8
      skyflaren  commented on Dec. 2, 2019, 9:47 p.m.

      there's some rounding inaccuracies, found that out the hard way XD (sorry)

      try finding a way around using decimals