1153. Supercomputer
Time limit: 2.0 second
Memory limit: 64 MB
Memory limit: 64 MB
To check the speed of JCN Corporation new supercomputer it was decided to figure out the sum of first N (N < 10600) positive integers. Unfortunately, by the time the calculation was finished the Chief Programmer forgot the value of N he entered. Your task is to write the program (for personal computer), which would determine the value of N by the result calculated on supercomputer.
Note: JCN Corporation manufactures only reliable computers, and its programmers write only correctly working programs.
Input
One line containing the result of calculations on the supercomputer.
Output
Выведите N, the number entered by Chief Programmer.
Sample
input | output |
---|---|
28 |
7 |
Problem Author: Eugene Bryzgalov
Problem Source: Ural Collegiate Programming Contest, April 2001, Perm, English Round
Problem Source: Ural Collegiate Programming Contest, April 2001, Perm, English Round
Tags: none (hide tags for unsolved problems)
Difficulty: 314
题意:给出一个数,这个数是1+2+3+。。。+n的结果,问n
分析:显然输入的数等于n*(n+1)/2
解出这个数就行,直接求根也好,二分也罢,写好高精度就好
然而我用python,不用写高精。。。
(python的math库大数开根貌似会错)
import math a = input()
a = a*2 left = 1
right = a
while(left <= right) :
mid = (left+right)/2
k = mid*(mid+1)
if k == a :
print mid
break
elif k > a :
right = mid-1
else :
left = mid+1