Problem Statement
NOTE: This problem statement contains subscripts/superscripts that may not display properly if viewed outside of the applet.
For positive integers h and r (1 <= r <= h) we define sequence Fh,r as {1, 2, 3, ..., h-1, h, h-1, h-2, ..., r+1, r}. Let S(Fh,r) be the the sum of all numbers in Fh,r and N(Fh,r) - the length of Fh,r.
For example, F3,2 is {1, 2, 3, 2}, S(F3,2) = 1 + 2 + 3 + 2 = 8, and N(F3,2) = 4. F5,5 is {1, 2, 3, 4, 5}, S(F5,5) = 15, and N(F5,5) = 5.
You are given a
Definition
- Class:
- AnEasyProblem
- Method:
- solve
- Parameters:
- long
- Returns:
- int
- Method signature:
- int solve(long sum)
- (be sure your method is public)
Constraints
- sum will be between 1 and 1,000,000,000,000(10^12).
Examples
6
Returns: 3
When h = r = 3, S(Fh,r) = 6 and N(Fh,r) = 3. There is no other h,r satisfing S(Fh,r) = 6. So you should return 3.
7
Returns: -1
100
Returns: 15
1000000000000
Returns: 1428571
999999911791
Returns: 1414213
47124365373
Returns: 308634
4736204061
Returns: 97326
140103954579
Returns: 529461
816163944355
Returns: 1300945
23017224220
Returns: 215155
161346308278
Returns: 572647
435778978723
Returns: 1195897
577650171865
Returns: 1108929
873825006753
Returns: 1360434
101591406
Returns: 14507
35407220029
Returns: 273778
623444060645
Returns: 1141573
863856839528
Returns: 1366675
20961597040
Returns: 217215
44572429578
Returns: 343004
173156982615
Returns: 605250
461420359333
Returns: 1295289
835409478789
Returns: 1657701
36486315918
Returns: 286059
146992497634
Returns: 592755
372870554536
Returns: 868983
401123360743
Returns: 900665
7112113064
Returns: 138040
292540696929
Returns: 828029
660520945594
Returns: 1240683
445815107724
Returns: 1167708
25895913676
Returns: 258507
83726282881
Returns: 412746
721546056148
Returns: 1254560
205166123940
Returns: 643968
530601417714
Returns: -1
361617111880
Returns: -1
954650182726
Returns: -1
133398683218
Returns: 548367
322042233207
Returns: -1