1153. Supercomputer

Time limit: 2.0 second
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 
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

最新文章

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

热门文章

  1. xcode arc引起的autorelease报错问题
  2. JdbcTemplate三种常用回调方法
  3. Nmap备忘单:从探索到漏洞利用(Part 5)
  4. lucas定理,组合数学问题
  5. 从Trie谈到AC自动机
  6. Thinkphp中eq,neq,gt,lt等表达式缩写
  7. 【Spring】Spring系列6之Spring整合Hibernate
  8. 【转】js onclick用法:跳转到指定URL
  9. 17.把字符串转换成整数[atoi]
  10. scrapy爬虫成长日记之将抓取内容写入mysql数据库