Problem:
Score : 300 points

Problem Statement

You are given an integer N.
Find the number of the positive divisors of N!, modulo 10^9+7.

Constraints

1≤N≤10^3

Input

The input is given from Standard Input in the following format:

N

Output

Print the number of the positive divisors of N!, modulo 10^9+7.

Sample Input 1

3

Sample Output 1

4

There are four divisors of 3! =6: 1, 2, 3 and 6. Thus, the output should be 4.

Sample Input 2

6

Sample Output 2

30

Sample Input 3

1000

Sample Output 3

972926972

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

macro_rules !input {(source =$s :expr ,$($r :tt ) *) =>{let mut iter =$s .split_whitespace () ;let mut next =||{iter .next () .unwrap () } ;input_inner !{next ,$($r ) *} } ;($($r :tt ) *) =>{let stdin =std ::io ::stdin () ;let mut bytes =std ::io ::Read ::bytes (std ::io ::BufReader ::new (stdin .lock () ) ) ;let mut next =move ||->String {bytes .by_ref () .map (|r |r .unwrap () as char ) .skip_while (|c |c .is_whitespace () ) .take_while (|c |!c .is_whitespace () ) .collect () } ;input_inner !{next ,$($r ) *} } ;}
macro_rules !input_inner {($next :expr ) =>{} ;($next :expr ,) =>{} ;($next :expr ,$var :ident :$t :tt $($r :tt ) *) =>{let $var =read_value !($next ,$t ) ;input_inner !{$next $($r ) *} } ;}
macro_rules !read_value {($next :expr ,($($t :tt ) ,*) ) =>{($(read_value !($next ,$t ) ) ,*) } ;($next :expr ,[$t :tt ;$len :expr ] ) =>{(0 ..$len ) .map (|_ |read_value !($next ,$t ) ) .collect ::<Vec <_ >>() } ;($next :expr ,chars ) =>{read_value !($next ,String ) .chars () .collect ::<Vec <char >>() } ;($next :expr ,usize1 ) =>{read_value !($next ,usize ) -1 } ;($next :expr ,$t :ty ) =>{$next () .parse ::<$t >() .expect ("Parse error" ) } ;}

fn main() {
   input! {
      n: usize,
   }
   let pf = Sieve::new(n);
   let mut map = std::collections::BTreeMap::new();
   for i in 2..n + 1 {
      let mut f = Vec::new();
      pf.factor(i, &mut f);
      for (p, k) in f {
         let mut x = 0;
         if let Some(v) = map.get(&p) {
            x = *v;
         }
         map.insert(p, x + k);
      }
   }
   let mut ans = Mint::new(1);
   for (_, &k) in map.iter() {
      ans *= (k + 1) as i64;
   }
   println!("{}", ans.x);
}

const MOD: i64 = 1000000007;
#[derive(Copy, Clone)]
pub struct Mint {
   x: i64,
}
impl Mint {
   fn new(x: i64) -> Self {
      Mint {
         x: (x % MOD + MOD) % MOD,
      }
   }
   fn pow(self, n: usize) -> Self {
      match n {
         0 => Mint::new(1),
         _ => {
            let mut a = self.pow(n >> 1);
            a *= a;
            if n & 1 == 1 {
               a *= self;
            }
            a
         }
      }
   }
   fn inv(self) -> Self { self.pow((MOD - 2) as usize) }
}
impl std::ops::Neg for Mint {
   type Output = Mint;
   fn neg(self) -> Self::Output { Self::new(-self.x) }
}
impl std::ops::AddAssign<Mint> for Mint {
   fn add_assign(&mut self, rhs: Self) {
      self.x += rhs.x;
      if self.x >= MOD {
         self.x -= MOD;
      }
   }
}
impl std::ops::AddAssign<i64> for Mint {
   fn add_assign(&mut self, rhs: i64) { *self += Mint::new(rhs); }
}
impl<T> std::ops::Add<T> for Mint
where
   Mint: std::ops::AddAssign<T>,
{
   type Output = Self;
   fn add(self, other: T) -> Self {
      let mut res = self;
      res += other;
      res
   }
}
impl std::ops::SubAssign<Mint> for Mint {
   fn sub_assign(&mut self, rhs: Self) {
      self.x += MOD - rhs.x;
      if self.x >= MOD {
         self.x -= MOD;
      }
   }
}
impl std::ops::SubAssign<i64> for Mint {
   fn sub_assign(&mut self, rhs: i64) { *self -= Mint::new(rhs); }
}
impl<T> std::ops::Sub<T> for Mint
where
   Mint: std::ops::SubAssign<T>,
{
   type Output = Self;
   fn sub(self, other: T) -> Self {
      let mut res = self;
      res -= other;
      res
   }
}
impl std::ops::MulAssign<Mint> for Mint {
   fn mul_assign(&mut self, rhs: Self) {
      self.x *= rhs.x;
      self.x %= MOD;
   }
}
impl std::ops::MulAssign<i64> for Mint {
   fn mul_assign(&mut self, rhs: i64) { *self *= Mint::new(rhs); }
}
impl<T> std::ops::Mul<T> for Mint
where
   Mint: std::ops::MulAssign<T>,
{
   type Output = Self;
   fn mul(self, other: T) -> Self {
      let mut res = self;
      res *= other;
      res
   }
}
impl std::ops::DivAssign<Mint> for Mint {
   fn div_assign(&mut self, rhs: Self) { *self *= rhs.inv(); }
}
impl std::ops::DivAssign<i64> for Mint {
   fn div_assign(&mut self, rhs: i64) { *self *= Mint::new(rhs).inv(); }
}
impl<T> std::ops::Div<T> for Mint
where
   Mint: std::ops::DivAssign<T>,
{
   type Output = Self;
   fn div(self, other: T) -> Self {
      let mut res = self;
      res /= other;
      res
   }
}
impl<T> From<T> for Mint
where
   i64: From<T>,
{
   fn from(x: T) -> Mint { Mint::new(i64::from(x)) }
}

struct Sieve {
   f: Vec<usize>,
   primes: Vec<usize>,
}
impl Sieve {
   fn new(max_n: usize) -> Self {
      let mut f = vec![0; max_n + 1];
      let mut primes = Vec::new();
      for i in 2..max_n + 1 {
         if f[i] > 0 {
            continue;
         }
         primes.push(i);
         f[i] = i;
         for j in i..max_n / i + 1 {
            if f[i * j] == 0 {
               f[i * j] = i;
            }
         }
      }
      Sieve {
         f: f,
         primes: primes,
      }
   }
   fn is_prime(&self, x: usize) -> bool { self.f[x] == x }
   /// Example:
   ///   let mut fl = Vec::new();
   ///   seive.factor_list(90, &mut fl);
   ///   => fl = [2, 3, 3, 5]
   fn factor_list(&self, x: usize, fl: &mut Vec<usize>) {
      if !fl.is_empty() {
         panic!("fl must be empty");
      }
      let mut x = x;
      while x != 1 {
         fl.push(self.f[x]);
         x /= self.f[x];
      }
   }
   /// Example:
   ///   let mut f = Vec::new();
   ///   seive.factor(90, &mut f);
   ///   => f = [(2, 1), (3, 2), (5, 1)]
   fn factor(&self, x: usize, f: &mut Vec<(usize, usize)>) {
      if !f.is_empty() {
         panic!("f must be empty");
      }
      let mut fl = Vec::new();
      self.factor_list(x, &mut fl);
      let mut p_prev = fl[0];
      let mut count = 0;
      for p in fl {
         if p == p_prev {
            count += 1;
         } else {
            f.push((p_prev, count));
            p_prev = p;
            count = 1;
         }
      }
      f.push((p_prev, count));
   }
}