#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int res=n;
while(n>=3)
{
res+=n/3;
n=n/3+n%3;
}
cout<<res;
return 0;
}
2 回复
0 转发
0 喜欢
13 阅读
#include<iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int res=n;
while(n>=3)
{
res+=n/3;
n=n/3+n%3;
}
cout<<res;
return 0;
}n/3 + n%3 简洁地解决了这个问题,真的很棒。对于正在学习循环和模拟思路的小伙伴来说,这是一个很好的参考范例。n%3 的那一步,考虑得很周全。