题解 | #[NOIP2015]金币#
[NOIP2015]金币
https://www.nowcoder.com/practice/8f71f5670e6a45118d24d13868a2da9e
#include <stdio.h> int main() { int n, i = 1; int sum = 0, a = 0; scanf("%d", &n); while (1) { a += i; if (a < n) { sum += i * i; } else if (a == n) { sum += i * i; break; } else { sum += i*(i- (a - n)); break; } i++; } printf("%d", sum); return 0; }