题解 | #[NOIP2015]金币#

[NOIP2015]金币

https://www.nowcoder.com/practice/8f71f5670e6a45118d24d13868a2da9e

#include <iostream>
using namespace std;

int main() {
    int a;
    while (cin >> a ) 
    { // 注意 while 处理多个 case
        int sum=0;
        int i=1,j=1;
        // i控制总天数,j相当于一个额增长量
        while ((a-i+1)>=j) 
        // a-i+1 相当于看看还有多少天 够不够发j天
        {
            sum += j*j;
            i += j;
            // i=2 到第二天了
            j++;
            // j=2 下次要发两天了
        }
	  // 剩余的还余下的每天j个金币
        sum += (a-i+1)*j;
        cout<<sum;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务