Skip to content

Commit 6e39cc3

Browse files
committed
perf: more efficient square root limit for the primality test
1 parent e50ebb4 commit 6e39cc3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/year2017/day23.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn composite(n: u32) -> Option<u32> {
7272
if n % 2 == 0 {
7373
return Some(n);
7474
};
75-
for f in (3..=n.isqrt()).step_by(2) {
75+
for f in (3..).step_by(2).take_while(|m| m * m <= n) {
7676
if n % f == 0 {
7777
return Some(n);
7878
}

0 commit comments

Comments
 (0)