题解 | #质数因子#
质数因子
https://www.nowcoder.com/practice/196534628ca6490ebce2e336b47b3607
use std::io::{self, *};
fn main() {
let stdin = io::stdin();
unsafe {
for line in stdin.lock().lines() {
let ll = line.unwrap();
let mut x: u32 = ll.trim().parse().expect("parse error");
for i in 2..((f64::sqrt(x as f64) + 1.0) as u32) {
let mut m = x % i;
if m != 0 {continue}
// 不用判定是否是质数,不是质数的话已经被之前更小的质数分解过了
loop {
x = x / i;
print!("{} ", i);
m = x % i;
if m != 0 {break}
}
if i < 2 {break}
}
if x > 1 {
print!("{}", x)
}
}
}
}
查看22道真题和解析