输出圆圈报数退出的最后号码.c 322 B

1234567891011121314151617181920
  1. #include <stdio.h>
  2. int lastRemaining(int n, int m) {
  3. int last = 0;
  4. int i;
  5. for (i = 2; i <= n; i++) {
  6. last = (last + m) % i;
  7. }
  8. return last + 1;
  9. }
  10. int main() {
  11. int n, m;
  12. scanf("%d %d", &n, &m);
  13. int result = lastRemaining(n, m);
  14. printf("%d\n", result);
  15. return 0;
  16. }