Skip to content

Instantly share code, notes, and snippets.

@icub3d
Created December 21, 2025 20:48
Show Gist options
  • Select an option

  • Save icub3d/d43a9d89d431bbf50511c55bd5e5a3d9 to your computer and use it in GitHub Desktop.

Select an option

Save icub3d/d43a9d89d431bbf50511c55bd5e5a3d9 to your computer and use it in GitHub Desktop.
Kattis stararrangements
use std::io::{Read, stdin};
fn main() {
let mut s = String::new();
stdin().read_to_string(&mut s).unwrap();
let s = s.trim().parse::<usize>().unwrap();
println!("{s}:");
(2..=(s / 2 + 1))
.flat_map(|n| [(n, n - 1), (n, n)])
.filter(|(x, y)| s % (x + y) == 0 || s % (x + y) == *x)
.for_each(|(x, y)| println!("{x},{y}"));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment