92A. Chips

来源:互联网 发布:中山瑞达软件 编辑:程序博客网 时间:2024/05/24 03:40

题目—92A


题意分析:有 n 只海象,按 1~n 顺时针编号排序,围成一个圈。有 m 个薯片,从 1 号开始,按顺时针发放,发给当前海象的薯片数量与它的编号一致。如果,当前剩余薯片数量不足以发放给当前海象,则停止发放。问最后剩余的薯片数量。

#include <stdio.h>int main()  {         int n,m,res=0;       scanf("%d %d",&n,&m);       while(m>0){              for(int i=1;i<=n;i++){                     if(m>=i){                            m -= i;                     }else{                            res = m;                            m = -1;       //  while                            i = n+1;      //  for                     }              }       }       printf("%d",res);              return 0;  }  


原创粉丝点击