Yekong's Blog

A blog about my experiences and thoughts.

Notes of Odd Divisor - Codeforce

Check a number that contains any odd divisor except 1, return “YES” if founded otherwise “NO”

Solution

Filter all numbers that cannot mod by 2 Check number is 2^n, number that is no 2^n all contains at least 1 odd divisor

for _ in 0..counts {
    let mut line = String::new();
    handle.read_line(&mut line)?;
    let number = read_as_t::<i64>(&mut line.trim().split_whitespace())?;

    if number % 2 != 0 {
        println!("YES");
    } else {
        // HERE IS THE MOST IMPORTANTS PART
        // every numbers except 0, 1 in binary contains at least 2 of 1
        // if number is 2^n binary will only contain 1 of 1
        let mut chk = number;
        chk &= number - 1;
        if chk != 0 {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}