TLE化简!

P1150 Peter 的烟

33961573wwh @ 2024-06-23 14:51:37

求化简

代码

a = [int(i) for i in input().split()]
s = a[0]
a = a[1]
d = 0
f = 0
while s > 0:
    d += s
    s = int((s + f) / a)
    f = s % a
print(d)

情况

第三个测试点TLE,大概是第二个数是2


by King_and_Grey @ 2024-06-23 14:52:53

@33961573wwh 你定义了一个数组是a,变量是a?


by 33961573wwh @ 2024-06-23 14:56:16

@greyandking

开始是数组,后面改成了变量,节省内存。

再说,剩下的都是 AC


by King_and_Grey @ 2024-06-23 14:57:10

6


by wangjingxi_ @ 2024-06-23 15:03:45

@33961573wwh AC代码:

a = [int(i) for i in input().split()]
s = a[0]
a = a[1]
d = 0
f = 0
while s > 0:
    d += s
    s, f = divmod(s + f, a)
print(d)

by 33961573wwh @ 2024-06-23 15:07:39

@wangjingxi_

sq


by limuchudsb @ 2024-07-23 23:15:57


#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long a,b;
    cin>>a>>b;
    cout<<a+(a-1)/(b-1);//化简
    return 0;
}

|