B - Soldier and Bananas
Problem description
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·kdollars 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?
Input
The first line contains three positive integers k, n, w (1 ≤ k, w ≤ 1000, 0 ≤ n ≤ 109), the cost of the first banana, initial number of dollars the soldier has and number of bananas he wants.
Output
Output one integer — the amount of dollars that the soldier must borrow from his friend. If he doesn't have to borrow money, output 0.
Examples
Input
3 17 4
Output
13
解题思路:等差数列求前w项和,如果够钱,则输出0,否则就输出需要借钱的数目,水过。
AC代码:
#include<bits/stdc++.h>
using namespace std;
int main(){
int k,n,w,r;
cin>>k>>n>>w;
r=((+w)*w/)*k;
if(r<=n)cout<<''<<endl;
else cout<<(r-n)<<endl;
return ;
}
B - Soldier and Bananas的更多相关文章
- Soldier and Bananas
Soldier and Bananas 题目链接:http://acm.hust.edu.cn/vjudge/problem/visitOriginUrl.action?id=173141 题意: 给 ...
- 水题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas
题目传送门 /* 水题:ans = (1+2+3+...+n) * k - n,开long long */ #include <cstdio> #include <algorithm ...
- A - Soldier and Bananas
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description A sold ...
- 【codeforces 546A】Soldier and Bananas
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard ou ...
- 546A. Soldier and Bananas
等差数列: 以k为首相,k为公差,w个数量的和与n的大小关系 输出max(sum-0,0) Java程序 import java.util.Scanner; public class A546 ...
- codeforces水题100道 第五题 Codeforces Round #304 (Div. 2) A. Soldier and Bananas (math)
题目链接:http://www.codeforces.com/problemset/problem/546/A题意:一个人现在有n元,它买第i根香蕉需要i*k元,问他要买w根香蕉的话,需要问他的朋友借 ...
- Codeforces Round #304 (Div. 2) -----CF546
A. Soldier and Bananas A soldier wants to buy w bananas in the shop. He has to pay k dollars for t ...
- codeforcess水题100道
之所以在codeforces上找这100道水题的原因是为了巩固我对最近学的编程语言的掌握程度. 找的方式在codeforces上的PROBLEMSET中过的题最多的那些题里面出现的最前面的10个题型, ...
- Codeforces Round #304 (Div.2)
A. Soldier and Bananas 题意:有个士兵要买w个香蕉,香蕉起步价为k元/个,每多买一个则贵k元.问初始拥有n元的士兵需要借多少钱? 思路:简单题 #include<iostr ...
随机推荐
- 人工机器:NDC-谷歌机器翻译破世界纪录,仅用Attention模型,无需CNN和RNN
终于找到ML日报的微信链接,抄之...................................... 请拜访原文链接:[谷歌机器翻译破世界纪录]仅用Attention模型,无需CNN和RNN. ...
- C++ Rand()各种实现
参考链接:http://www.cplusplus.com/reference/cstdlib/rand/ 使用实例: v1 = rand() % 100; // v1 in the range 0 ...
- (转)OL记载Arcgis Server切片
http://blog.csdn.net/gisshixisheng/article/details/47955787 概述: 本文讲述如何在OpenLayers中调用Arcgis Server切片并 ...
- Python3中替代Python2中cmp()函数的新函数(gt,ge,eq,le,lt)
原文出处:http://blog.csdn.net/Artprog/article/details/52197779 Python3中已经不能使用cmp()函数了,被如下五个函数替代: import ...
- Swoole server函数列表(转载)
swoole_server::__construct swoole_server::set swoole_server::on swoole_server::addlistener swoole_se ...
- Uoj #274. 【清华集训2016】温暖会指引我们前行 LCT维护边权_动态最小生成树
Code: 行#include<bits/stdc++.h> #define ll long long #define maxn 1000000 #define inf 100000000 ...
- 【转载】push to origin/master was rejected错误解决方案
版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/a137151062/article/details/78820806idea中,发布项目到OSChi ...
- 想要远程服务器长时间挂机不断开ssh连接的技巧
使用top命令挂着就好了,top命令执行的“查看系统进程和资源占用”的任务会一直输出动态的数据,一直有数据传输就不会因为长时间挂机而断开ssh链接了,尤其针对于海外服务器,因为高延迟经常出现挂机久了自 ...
- Linux思维导图之文件压缩
- 利用python暴力破解压缩文件密码
import randomimport sysimport zipfileimport timefrom threading import Threadfrom multiprocessing imp ...