The ? 1 ? 2 ? ... ? n = k problem
来源:互联网 发布:下载下载淘宝网站 编辑:程序博客网 时间:2024/04/28 21:57
The problem
Given the following formula, one can set operators '+' or '-' instead of each '?', in order to obtain a given k
? 1 ? 2 ? ... ? n = k
For example: to obtain k = 12 , the expression to be used will be:
- 1 + 2 + 3 + 4 + 5 + 6 - 7 = 12
with n = 7
The Input
The first line is the number of test cases, followed by a blank line.
Each test case of the input contains integer k (0<=|k|<=1000000000).
Each test case will be separated by a single line.
The Output
For each test case, your program should print the minimal possible n (1<=n) to obtain k with the above formula.
Print a blank line between the outputs for two consecutive test cases.
Sample Input
212-3646397
Sample Output
72701
0 0
- The ? 1 ? 2 ? ... ? n = k problem
- The ? 1 ? 2 ? ... ? n = k problem
- The ? 1 ? 2 ? ... ? n = k problem
- The ? 1 ? 2 ? ... ? n = k problem
- The ? 1 ? 2 ? ... ? n = k problem
- The ? 1 ? 2 ? ... ? n = k problem
- The ? 1 ? 2 ? ... ? n = k problem
- UVa 10025 - The ? 1 ? 2 ? ... ? n = k problem
- uva 10025 The ? 1 ? 2 ? ... ? n = k problem
- Uva 10025 - The ? 1 ? 2 ? ... ? n = k problem
- uva 10025 The ? 1 ? 2 ? ... ? n = k problem
- uva 10025 - The ? 1 ? 2 ? ... ? n = k problem
- UVa 10025 - The ? 1 ? 2 ? ... ? n = k problem
- UVA - 10025 :The ? 1 ? 2 ? ... ? n = k problem
- 10025 - The ? 1 ? 2 ? ... ? n = k problem
- 第一天 The ? 1 ? 2 ? ... ? n = k problem
- UVA10025 The ? 1 ? 2 ? ... ? n = k problem
- Uva 10025 - The ? 1 ? 2 ? ... ? n = k problem
- 我的2013 - 年终总结 + 浏览器渲染发展的一些思考
- 美工(一)网页颜色搭配技巧 文字字体、字号、字体排版等
- Linux GCC常用命令
- 关于const
- C语言函数参数传递的分析
- The ? 1 ? 2 ? ... ? n = k problem
- gnuradio 中USRP收发速率
- Berkeley DB -- 主从复制(HA)上部
- Box of Bricks
- 基于WPF的Dispatcher应用及探讨(一)
- JSF 与 struts
- c# 主窗体传值给子窗体
- Leetcode: Unique Paths
- JBullet的安装