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
  1. 28
  1. 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库大数开根貌似会错)
 
  1. import math
  2.  
  3. a = input()
  4. a = a*2
  5.  
  6. left = 1
  7. right = a
  8. while(left <= right) :
  9. mid = (left+right)/2
  10. k = mid*(mid+1)
  11. if k == a :
  12. print mid
  13. break
  14. elif k > a :
  15. right = mid-1
  16. else :
  17. left = mid+1

ural 1153. Supercomputer的更多相关文章

  1. URAL - 1153 Supercomputer 大数开方

    题意:给定m,m = n * (n+1) / 2,计算n值. 思路:n = SQRT(m*2) 注意m很大,需要自己实现大数开方.我用的是自己写的大数模板:大数模板 AC代码 #include < ...

  2. centos mysql 大量数据导入时1153 错误:1153 - Got a packet bigger than 'max_allowed_packet' bytes

    参考:http://stackoverflow.com/questions/93128/mysql-error-1153-got-a-packet-bigger-than-max-allowed-pa ...

  3. 后缀数组 POJ 3974 Palindrome && URAL 1297 Palindrome

    题目链接 题意:求给定的字符串的最长回文子串 分析:做法是构造一个新的字符串是原字符串+反转后的原字符串(这样方便求两边回文的后缀的最长前缀),即newS = S + '$' + revS,枚举回文串 ...

  4. ural 2071. Juice Cocktails

    2071. Juice Cocktails Time limit: 1.0 secondMemory limit: 64 MB Once n Denchiks come to the bar and ...

  5. ural 2073. Log Files

    2073. Log Files Time limit: 1.0 secondMemory limit: 64 MB Nikolay has decided to become the best pro ...

  6. ural 2070. Interesting Numbers

    2070. Interesting Numbers Time limit: 2.0 secondMemory limit: 64 MB Nikolay and Asya investigate int ...

  7. ural 2069. Hard Rock

    2069. Hard Rock Time limit: 1.0 secondMemory limit: 64 MB Ilya is a frontman of the most famous rock ...

  8. ural 2068. Game of Nuts

    2068. Game of Nuts Time limit: 1.0 secondMemory limit: 64 MB The war for Westeros is still in proces ...

  9. ural 2067. Friends and Berries

    2067. Friends and Berries Time limit: 2.0 secondMemory limit: 64 MB There is a group of n children. ...

随机推荐

  1. svn提交时强制添加注释 (转)

    SVN提交时,如果没有注释,在查阅历史时,会非常不方便.因此我们需要有一个让程序员提交代码时,强制添加注释的规则.下面看看在SVN中怎么实现. 1. 推荐使用VisualSVN作为服务端(免费下载地址 ...

  2. 秀尔算法:破解RSA加密的“不灭神话”

    RSA加密 VS 秀尔算法 作为RSA加密技术的终结者——“太多运算,无法读取”的秀尔算法(Shor’s algorithm)不是通过暴力破解的方式找到最终密码的,而是利用量子计算的并行性,可以快速分 ...

  3. angular js 自定义指令

    我们有些时候需要把后台返回过来的带有html标签的字符串binding到界面中一个指定的div或者其他的控制器中. 使用普通ng-bind不会自动解析出html语句. js中这样定义: app.dir ...

  4. error adding symbols: DSO missing from command line collect2: error: ld returned 1 exit status

    Windows服务器Azure云编译安装MariaDB教程 www.111cn.net 编辑:future 来源:转载 安装MariaDB数据库最多用于linux系统中了,下文给各位介绍在Window ...

  5. 查看daemon使用技巧

    una ~ # ps -ef|egrep "*d$"或"[a-z]d"               //查看现有的服务器上都有哪些服务器进程.root 3509 ...

  6. 在windows下用cygwin和eclipse搭建cocos2dx(2.1.4)的android开发环

    一.准备工作 需要下载和安装以下内容,请根据自己的操作系统选择x86和x64(我的是64位win7,我就拿64位说事) 1.jdk-7u25-windows-x64.exe(下载完后直接安装,一直下一 ...

  7. static-const 类成员变量

    [本文链接] http://www.cnblogs.com/hellogiser/p/static-const.html [分析] const数据成员必须在构造函数初始化列表中初始化; static数 ...

  8. 【python】在python中调用mysql

    资料:http://www.runoob.com/python/python-mysql.html 例子: 假设有数据路HTMLHASH, 其中有表htmlhash, 表中包括两个varchar(10 ...

  9. JSON和GSON操作json数据

    1,JSON操作json import net.sf.json.JSONArray; import net.sf.json.JSONObject; //json操作数据 public static S ...

  10. 高效开发 Android App 的 10 个建议(转)

    文章写的非常好,值得大家好好研究研究,仔细分析一下. 引文地址: http://www.cnblogs.com/xiaochao1234/p/3644989.html 假如要Google Play上做 ...