poj-1844-Sum
来源:互联网 发布:百度知道评论软件 编辑:程序博客网 时间:2024/05/17 01:06
Sum
Time Limit: 1000MS Memory Limit: 30000KTotal Submissions: 10171 Accepted: 6677
Description
Consider the natural numbers from 1 to N. By associating to each number a sign (+ or -) and calculating the value of this expression we obtain a sum S. The problem is to determine for a given sum S the minimum number N for which we can obtain S by associating signs for all numbers between 1 to N.
For a given S, find out the minimum value N in order to obtain S according to the conditions of the problem.
For a given S, find out the minimum value N in order to obtain S according to the conditions of the problem.
Input
The only line contains in the first line a positive integer S (0< S <= 100000) which represents the sum to be obtained.
Output
The output will contain the minimum number N for which the sum S can be obtained.
Sample Input
12
Sample Output
7
Hint
The sum 12 can be obtained from at least 7 terms in the following way: 12 = -1+2+3+4+5+6-7.#include<iostream>using namespace std;int main(){ int n,i,j; while(cin>>n) { int sum=0; for(i=1;i<=n;i++) { sum+=i; if((sum>=n)&&(sum-n)%2==0) { j=i; break; } } cout<<j<<endl; } return 0;}
0 0
- POJ 1844 Sum
- poj 1844 Sum
- poj 1844 Sum
- poj 1844 sum
- poj 1844 Sum
- poj 1844 Sum
- POJ 1844 Sum
- POJ 1844 Sum
- poj 1844 sum (数学)
- poj 1844 Sum 【数学】
- poj-1844-Sum
- POJ 1844 Sum
- [POJ]1844 Sum
- POJ 1844 sum
- POJ 1844 Sum 笔记
- POJ 1844 Sum【简单数学】
- POJ 1844 Sum(数学)
- poj 1844 Sum ( 数学思维 )
- 深入理解HTTP协议
- 回调函数透彻理解Java
- 『什么找茬』获得PP助手首位推荐
- jsp分页(结合js)
- 读入优化的模板
- poj-1844-Sum
- JS 在 对table 的操作 例如 动态增加行的关键函数
- HDU 4976 A simple greedy problem. DP
- Bootstrap3.0学习第六轮(表单)
- JQuery Camera 插件参数
- 日志分割
- Servlet过滤器
- ListView与ExpandableListView设置分割线 divider
- 拓扑排序