def sample_geometric_exp_fast(x) -> int:
if x == 0:
return 0
s, t = Rational.into_numer_denom(x)
while True:
u = Integer.sample_uniform_int_below(t) d = bool.sample_bernoulli_exp(Rational(u, t)) if d:
break
v = sample_geometric_exp_slow(1) z = u + t * v
return z // s