挂#3

P1150 Peter 的烟

NEXUSNOA @ 2024-04-02 20:24:02

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

by Tsz1024_AK @ 2024-04-02 20:27:29

@NoaNexus 找规律:要吸 n+(n-1)/(k-1) 支烟

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

by _XiaY_ @ 2024-04-02 20:28:28

@NoaNexus while循环中n > k改为n >= k


by NEXUSNOA @ 2024-04-15 12:16:25

@ZYC_MUSTA_1024 @XiaY 谢谢,已关


|