Codeforces 92A-Chips
来源:互联网 发布:孕婴店网络宣传广告语 编辑:程序博客网 时间:2024/06/06 02:12
There are n walruses sitting in a circle. All of them are numbered in the clockwise order: the walrus number 2 sits to the left of the walrus number 1, the walrus number 3 sits to the left of the walrus number 2, ..., the walrus number 1 sits to the left of the walrus number n.
The presenter has m chips. The presenter stands in the middle of the circle and starts giving the chips to the walruses starting from walrus number 1 and moving clockwise. The walrus number i gets i chips. If the presenter can't give the current walrus the required number of chips, then the presenter takes the remaining chips and the process ends. Determine by the given n and m how many chips the presenter will get in the end.
The first line contains two integers n and m (1 ≤ n ≤ 50, 1 ≤ m ≤ 104) — the number of walruses and the number of chips correspondingly.
Print the number of chips the presenter ended up with.
4 11
0
17 107
2
3 8
1
In the first sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, four chips to the walrus number 4, then again one chip to the walrus number 1. After that the presenter runs out of chips. He can't give anything to the walrus number 2 and the process finishes.
In the third sample the presenter gives one chip to the walrus number 1, two chips to the walrus number 2, three chips to the walrus number 3, then again one chip to the walrus number 1. The presenter has one chip left and he can't give two chips to the walrus number2, that's why the presenter takes the last chip.
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <queue>#include <stack>using namespace std;int main(){ int n,m; while(~scanf("%d %d",&n,&m)) { for(int i=1;;i++) { if(i%n!=0) i%=n; else i=n; if(m<i) { printf("%d\n",m); break; } m-=i; } } return 0;}
- Codeforces 92A-Chips
- 92A. Chips
- A. Chips
- Codeforces Beta Round #75 (Div. 2)---A. Chips
- 【巧模拟】#75 A. Chips
- Chips
- Codeforces Round #194 (Div. 2) D. Chips
- CF 333 B.Chips CodeForces【伪容斥】
- Codeforces Round #194 (Div. 1) / 333B Chips(贪心+代码优化)
- STL chips
- STL chips
- Multithread chips
- PerfHud chips
- CodeForces-a
- Codeforces 903A A
- chips of wow
- gpu hardware chips[11.20]
- c++/c chips
- Netsniff-NG
- Android APP架构设计——MVC、MVP和MVVM介绍
- ubuntu配置samba
- 12.6static类成员
- 单例模式
- Codeforces 92A-Chips
- Android学习笔记
- 虚拟机克隆后改网卡
- 按F7进行编译时,有些项目无法编译
- git 分支
- URL Schemes
- Android中的命名空间
- js插件怎么写?
- Java设计模式学习02——工厂模式