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
牛客网
牛客企业服务