码迷,mamicode.com
首页 > 其他好文 > 详细

CodeForces 546 A - Soldier and Bananas

时间:2015-05-27 10:03:12      阅读:206      评论:0      收藏:0      [点我收藏+]

标签:acm   codeforces   

题目链接click here~~

【题目大意】

A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana).

He has n dollars. How many dollars does he have to borrow from his friend soldier to buy w bananas?

【解题思路】

公式:判断(((w+1)*(w)/2)*k-n)是否大于零

代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int k,n,w;
    scanf("%d%d%d",&k,&n,&w);
    printf("%d\n",(((w+1)*(w)/2)*k-n)>0?(((w+1)*(w)/2)*k-n):0);
    return 0;
}


CodeForces 546 A - Soldier and Bananas

标签:acm   codeforces   

原文地址:http://blog.csdn.net/u013050857/article/details/46042479

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!