Trial division by hand
while d * d <= x: if x % d == 0: divisors(x) / factor(x) from std.math
let x: 1..=1000000000 = read()
var cnt = 0
var d = 1
while d * d <= x:
if x % d == 0:
cnt += if d * d == x: 1 else: 2
d += 1
print(cnt)let x: 1..=1000000000 = read()
print(divisors(x).len)Why
Trial division up to (while d * d <= x: if x % d == 0: ...) is the textbook way to list divisors or prime factors, and the loop bound, the square-root pairing and the leftover prime are each easy to get wrong. divisors(x) lists the divisors and factor(x) returns the (prime, exponent) pairs, both from std.math. A loop with an inner while x % d == 0 is reported as factoring, otherwise as listing divisors. There is no automatic fix, since what the loop computes from them varies.
The practice it serves
A hand-written pattern the language or the standard library already says in one step.
Not flagged
A near miss: close to the pattern, but not it.
let x: 1..=1000000000 = read()
var d = 1
while d * d <= x:
d += 1
print(d - 1)Turn it off
For one block, wrap it in with lint(trial_division: allow):. For a project, add trial_division = "allow" under [lints] in cp.toml.
Generated from spec/lints/trial_division, the same record the linter is built from.