题解 | #质数因子#

质数因子

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)
            }
            

        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
迷茫的大四🐶:摊牌了,我是25届的,你们也不招我
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务