15170254896zhou @ 2023-11-10 12:23:15
#include<stdio.h>
int main()
{
int n, k, m1 = 0, m2 = 0, t = 0;
scanf("%d %d", &n, &k);
m1 = n / k;
m2 = n % k;
for (; ;)
{
t += m1;
if (m1 + m2 >= k)
{
m1 = (m1 + m2) / k;
m2 = (m1 + m2) % k;
}
else
{
printf("%d", n + t);
break;
}
}
return 0;
}
by 2Bxzj @ 2023-11-10 12:52:15
@15170254896zhou 题目里有n根烟
你应该先算n根,一直有一个变量记录你现在有的烟蒂,一直循环,每当烟蒂的数量到了k就多吸一根,等到再也不能了,就退出循环,输出
你先试试
by M0XU @ 2024-01-05 15:36:19
m2算得有问题,你的式子中m2 = (m1 + m2) % k没有考虑到换完烟对m2的影响。改成m2=(m1+m2-m1*k)%k;