ural 1153. Supercomputer
2024-10-12 04:24:22
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
最新文章
- SQL语句优化
- initWithCoder与initWithFrame的区别
- IOS开发基础知识--碎片13
- pwnable.kr-random
- [开发笔记]-MarkDown语法
- IIS限制ip访问
- BZOJ 2433 智能车比赛(计算几何+最短路)
- RPI学习--webcam_用fswebcam抓取图片
- Microsoft Visual C++ Runtime error解决方法
- oracle中怎么查看存储过程的源码
- 高级I/O之STREAMS
- mod_rewrite模块详解
- Python Challenge 第四题
- kafka和mqtt的区别是什么?
- robotframework接口之上传图片
- RPC框架-RMI、RPC和CORBA的区别
- Ubuntu更改主目录文件名为英文
- 【代码审计】YzmCMS_PHP_v3.6 代码执行漏洞分析
- D. Who killed Cock Robin 湖北省大学程序设计竞赛
- 求组合数的O(n^2)和O(n)解法及模板