[Baekjoon 23848] Sum of a Geometric Sequence
Try common ratios and check whether a normalized geometric sum divides the target.
July 18, 2022
Find a geometric sequence of positive integers with total N. Rather than search for the first term immediately, I computed a normalized sum for a common ratio r and number of terms k.
1 + r + r² + ... + r^(k - 1)
If this sum divides N, the first term is N / sum. Repeatedly multiplying by the ratio then produces the actual sequence. Only sequences with at least three terms are valid.
Instead of blindly trying every first term and ratio, I first checked whether the normalized geometric sum was a divisor of N.
Problem: Baekjoon · Code: View on GitHub