90求助

P1150 Peter 的烟

J_K_ROWLING @ 2024-12-19 19:42:16

#include <iostream>
using namespace std;
int main(){
    //模拟
    long long n,k,j=0,cnt=0;//cnt用来记录烟数
    cin>>n>>k;
    for(int i=1;n>0;i++){
        if(j==k){
            n++;
            j=0;
        }
        j++;
        n--;
        cnt++;
    }
    cout<<cnt;
    return 0;
}

by J_K_ROWLING @ 2024-12-19 19:53:28

柯南,懂了!!!!!!!!!!!!!!!!!!!!!!!!


by J_K_ROWLING @ 2024-12-19 19:55:35

#include <iostream>
using namespace std;
int main(){
    //模拟
    int n,k,j=0,cnt=0;//cnt用来记录烟数
    cin>>n>>k;
    for(int i=1;n>0;i++){
        cnt+=n;
        j+=n%k;
        if(j>=k){
            n+=j%k;
        }
        n/=k;
    }
    cout<<cnt;
    return 0;
}

又废了,嘤嘤嘤


|