题目链接: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; }
时间: 2024-10-11 16:09:15