Problem:
Prime Factorization

Factorize a given integer n.

Input

n

An integer n is given in a line.

Output

Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor.

Constraints

2 ≤ n ≤ 109

Sample Input 1

12

Sample Output 1

12: 2 2 3

Sample Input 2

126

Sample Output 2

126: 2 3 3 7

Solution in Rust (judge verdict: Accepted)

use std::io;
use std::str::FromStr;

fn input<T:FromStr>() -> T {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.trim().parse().ok().unwrap()
}

fn calc_prime_numbers(max: u64) -> Vec<u64> {
    let limit: u64 = (max as f64).sqrt() as u64;
    let mut prime_numbers: Vec<u64> = Vec::new();
    for i in 2..(limit+1) {
        let mut flag = true;
        for p in &prime_numbers {
            if i % p == 0 {
                flag = false;
            }
        }
        if flag {
            prime_numbers.push(i)
        }
    }
    prime_numbers
}

fn main() {
    let mut n: u64 = input();    
    let prime_numbers= calc_prime_numbers(n);

    // println!("{:?}", prime_numbers);
    print!("{}:", n);
    for p in prime_numbers {
        if n == 1 {
            break;
        }
        while n % p == 0 {
            n /= p;
            print!(" {}", p);
        }
    }
    if n != 1 {
        println!(" {}", n);
    } else {
        println!();
    }
}