Connection Status:
Competition Arena > QuadraticLaw
SRM 635 · 2014-08-25 · by Xellos0 · Math, Search
Class Name: QuadraticLaw
Return Type: long
Method Name: getTime
Arg Types: (long long)
Problem Statement

Problem Statement

"Němec's quadratic law: how many minutes the teacher was late to the lesson, that many minutes squared he'll end the lesson earlier."


In other words, if the teacher is t minutes late (for some non-negative integer t), he should end the lesson t2 minutes early. Of course, this means the teacher can't be too late, because a lesson can't end before even starting. It is, however, possible for the teacher to arrive and end the lesson immediately (in fact, he then only arrives to tell the students that the lesson's cancelled).


You're given a long d. The lesson was supposed to take d minutes. Compute and return the largest non-negative integer t such that the teacher can be t minutes late.

Constraints

  • d will be between 1 and 1,000,000,000,000,000,000, inclusive.
Examples
0)
1
Returns: 0

The lesson was supposed to take 1 minute. The teacher can only be 0 minutes late, in which case he ends the lesson 0 minutes early (i.e. he arrives and ends the lecture on time).

1)
2
Returns: 1

It's possible for the teacher to be 1 minute late and end the lecture 1 minute early (so there's no lecture at all).

2)
5
Returns: 1
3)
6
Returns: 2
4)
7
Returns: 2

Submissions are judged against all 62 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class QuadraticLaw with a public method long long getTime(long long d) · 62 test cases · 2 s / 256 MB per case

Submitting as anonymous