第三个测试点错了,怎么错了?怎么改?

P1150 Peter 的烟

_hacket @ 2024-05-22 19:07:58

#include<stdio.h>

int yan(int a,int b){
    int c=a/b;
    if(c!=0)
        return a+yan(c,b);
    return a+c;
}

int main(){
    int a,b;
    scanf("%d %d",&a,&b);

    printf("%d\n",yan(a,b));

    return 0;
} 

by CodeAnythingNow @ 2024-05-22 19:18:38

#include <stdio.h>

int yan(int a, int b) {
    int total = a; // 初始化总烟数为初始烟数

    while (a >= b) {
        int c = a / b; // 计算通过换烟蒂得到的新烟数
        total += c;
        a = c + (a % b); // 更新换烟蒂后剩余的烟数
    }

    return total;
}

int main() {
    int a, b;
    scanf("%d %d", &a, &b);

    printf("%d\n", yan(a, b));

    return 0;
}

@_hacket

我干脆重写了一个


by MSJ2013 @ 2024-07-18 17:51:53

我的AC代码:


#include <bits/stdc++.h>
     using namespace std;
     int main(){
         int n,k;
         cin>>n>>k;
         cout<<n+(n-1)/(k-1);
         return 0;
     }

|