Problem:
Score: 200 points

Problem Statement

The number 105 is quite special - it is odd but still it has eight divisors.
Now, your task is this: how many odd numbers with exactly eight positive divisors are there between 1 and N (inclusive)?

Constraints

N is an integer between 1 and 200 (inclusive).

Input

Input is given from Standard Input in the following format:

N

Output

Print the count.

Sample Input 1

105

Sample Output 1

1

Among the numbers between 1 and 105, the only number that is odd and has exactly eight divisors is 105.

Sample Input 2

7

Sample Output 2

0

1 has one divisor. 3, 5 and 7 are all prime and have two divisors. Thus, there is no number that satisfies the condition.

Solution in Rust (1.15.1) (judge verdict: Accepted)

#![allow(unused_imports)]
#![cfg_attr(feature = "cargo-clippy", allow(redundant_field_names))]

use std::cell::{Cell, RefCell};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::io::{self, BufWriter, Read, Write};
use std::ops::{
    Add, AddAssign, BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Div, DivAssign,
    Mul, MulAssign, Neg, Not, Rem, RemAssign, Sub, SubAssign,
};
use std::str::{self, FromStr};
use std::{char, cmp, f32, f64, fmt, i16, i32, i64, i8, thread, u16, u32, u64, u8};

fn main() {
    scan_all(io::stdin(), 1024);
    let n = r::<u32>();
    let r = (1..n + 1).filter(|&n| f(n)).count();
    println!("{}", r);
}

fn f(mut n: u32) -> bool {
    static PS: [u32; 45] = [
        3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
        97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181,
        191, 193, 197, 199,
    ];
    if n % 2 == 0 {
        return false;
    }
    let mut r = 1;
    for &p in PS.iter() {
        if n % p == 0 {
            let mut q = 1;
            while n % p == 0 {
                n /= p;
                q += 1;
            }
            r *= q;
        }
    }
    r == 8
}

thread_local! {
    static SCANNED: RefCell<Scanned> = RefCell::default();
}

fn scan_all<R: Read>(mut input: R, estimated: usize) {
    let mut buf = Vec::with_capacity(estimated);
    let _ = io::copy(&mut input, &mut buf).unwrap();
    if buf.last() != Some(&b'\n') {
        buf.push(b'\n');
    }
    SCANNED.with(|scanned| scanned.borrow_mut().buf = buf);
}

fn r<T: FromStr>() -> T
where
    T::Err: fmt::Debug,
{
    SCANNED.with(|scanned| scanned.borrow_mut().next())
}

#[allow(dead_code)]
fn rv<T: FromStr>(n: usize) -> Vec<T>
where
    T::Err: fmt::Debug,
{
    SCANNED.with(|scanned| {
        let mut scanned = scanned.borrow_mut();
        (0..n).map(|_| scanned.next()).collect()
    })
}

#[allow(dead_code)]
fn rp<T1: FromStr, T2: FromStr>(n: usize) -> Vec<(T1, T2)>
where
    T1::Err: fmt::Debug,
    T2::Err: fmt::Debug,
{
    SCANNED.with(|scanned| {
        let mut scanned = scanned.borrow_mut();
        (0..n).map(|_| (scanned.next(), scanned.next())).collect()
    })
}

#[allow(dead_code)]
fn rt<T1: FromStr, T2: FromStr, T3: FromStr>(n: usize) -> Vec<(T1, T2, T3)>
where
    T1::Err: fmt::Debug,
    T2::Err: fmt::Debug,
    T3::Err: fmt::Debug,
{
    SCANNED.with(|scanned| {
        let mut scanned = scanned.borrow_mut();
        (0..n)
            .map(|_| (scanned.next(), scanned.next(), scanned.next()))
            .collect()
    })
}

#[allow(dead_code)]
fn rq<T1: FromStr, T2: FromStr, T3: FromStr, T4: FromStr>(n: usize) -> Vec<(T1, T2, T3, T4)>
where
    T1::Err: fmt::Debug,
    T2::Err: fmt::Debug,
    T3::Err: fmt::Debug,
    T4::Err: fmt::Debug,
{
    SCANNED.with(|scanned| {
        let mut scanned = scanned.borrow_mut();
        (0..n)
            .map(|_| {
                (
                    scanned.next(),
                    scanned.next(),
                    scanned.next(),
                    scanned.next(),
                )
            }).collect()
    })
}

#[allow(dead_code)]
fn rm<T: FromStr>(m: usize, n: usize) -> Vec<Vec<T>>
where
    T::Err: fmt::Debug,
{
    SCANNED.with(|scanned| {
        let mut scanned = scanned.borrow_mut();
        (0..m)
            .map(|_| (0..n).map(|_| scanned.next()).collect())
            .collect()
    })
}

#[allow(dead_code)]
fn r_char_mat<T, F: FnMut(u8) -> T>(h: usize, mut f: F) -> Vec<Vec<T>> {
    SCANNED.with(|scanned| {
        let mut scanned = scanned.borrow_mut();
        (0..h)
            .map(|_| {
                let l = scanned.next::<String>();
                l.as_bytes().iter().cloned().map(&mut f).collect()
            }).collect()
    })
}

#[derive(Default)]
struct Scanned {
    buf: Vec<u8>,
    pos: usize,
}

impl Scanned {
    #[inline]
    fn next<T: FromStr>(&mut self) -> T
    where
        T::Err: fmt::Debug,
    {
        let mut start = None;
        loop {
            match (self.buf[self.pos], start.is_some()) {
                (b' ', true) | (b'\n', true) => break,
                (_, true) | (b' ', false) | (b'\n', false) => self.pos += 1,
                (_, false) => start = Some(self.pos),
            }
        }
        let target = &self.buf[start.unwrap()..self.pos];
        unsafe { str::from_utf8_unchecked(target) }.parse().unwrap()
    }
}