int n ; while (cin >> n) { n = n > 0 ? n : 0 - n; int index = 1; int sum = 0; while (sum < n) { sum += index; index++; } if ((sum - n) % 2 == 0) { cout << index - 1 << endl; } else { if (index % 2 == 1) { cout << index << endl; } else { cout << index + 1 << endl; } } }
点赞 3

相关推荐

05-09 14:45
门头沟学院 Java
点赞 评论 收藏
分享
06-02 15:53
阳光学院 Java
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务