aishiteru_mitsu_ha @ 2023-12-20 18:28:23
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,ans;
cin>>n>>k;
ans=n;
while(1){
if(n<=1){
break;
}
ans+=n/k;
n=n%k;
}
cout<<ans;
return 0;
}
by 0907_WDS_0731 @ 2023-12-20 19:01:12
n还应加上再次吸剩下的烟蒂
//l所剩烟蒂个数
l=n%k;
n=n/k;
ans+=n;
n+=l;
by Linktux @ 2023-12-23 13:59:36
@not_much
#include <iostream>
using namespace std;
int main(){
int n,k,sum=0;
cin>>n>>k;
sum=n;
while(n>=k){sum+=n/k,n=n/k+n%k;}
cout<<sum<<endl;
return 0;
}
其中他至少抽了n
根烟,所以sum
初始化为n
,又因为n
根烟中每k
根烟蒂兑换一根烟,所以sum
要加上n/k
,然后剩下n/k
根烟蒂,还有原来没兑换的n%k
根烟蒂,共剩下n/k+n%k
根烟蒂,条件是n>=k
,即能兑换烟。希望有帮助QWQ
by aishiteru_mitsu_ha @ 2023-12-25 17:44:25
@Walnutjuice 现在90分
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,k,ans;
cin>>n>>k;
ans=n;
while(1){
if(n<=k){
break;
}
ans+=n/k;
n=n%k+n/k;
}
cout<<ans<<"\n";
return 0;
}
by linmoxi @ 2024-01-11 15:17:52
#include<iostream>
using namespace std;
int main(){
long long n,k,s=0,t=0;
cin>>n>>k;
while(n){
n--;
t++;
s++;
if(t==k){
t=0;
n++;
}
}
cout<<s;
return 0;
}