Submission #3423683


Source Code Expand

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>

using namespace std;

struct Mod {
    static constexpr auto kMod = 1000000007L;
    static constexpr auto kIMod = 1000000005L;

    // can be implicitly converted
    Mod(int64_t n) : n(n) {}

    Mod operator*(Mod m) const {
        return (n * (m.n % kMod)) % kMod;
    }

    Mod& operator*=(Mod m) {
        *this = *this * m;
        return *this;
    }

    Mod pow(int64_t p) {
        if (p == 0) {
            return 1;
        }
        if (p == 1) {
            return n;
        }

        int64_t r = this->pow(p/2).n;
        if (p % 2 == 0) {
            return r * r % kMod;
        } else {
            return (r * r % kMod) * n % kMod;
        }
    }

    Mod operator/(Mod m) const {
        if (n == 0) {
            return 0;
        }

        return *this * m.pow(kIMod);
    }

    Mod& operator/=(Mod m) {
        *this = *this / m;
        return m;
    }

    Mod operator+(Mod m) const {
        return (n + m.n) % kMod;
    }

    Mod& operator+=(Mod m) {
        *this = *this + m;
        return *this;
    }

  int64_t n;
};

long solve(int32_t n) {
  vector<int> f(n + 1, 0);
  vector<bool> p(n, true);
  p[0] = false;
  p[1] = false;
  
  for (int32_t i = 2; i <= n/2; ++i) {
    if (!p[i]) {
      // not prime
      continue;
    }
    
    f[i] += 1;
    for (int32_t j = i + 1; j <= n; ++j) {
      int d = 0;
      int jj = j;
      while (jj % i == 0) {
        jj /= i;
        ++d;
      }
      f[i] += d;
      if (d > 0) {
        p[j] = false;
      }
    }
  }
  for (int32_t i = n/2 + 1; i <= n; ++i) {
    if (p[i]) {
      f[i] += 1;
    }
  }
  
  auto ans = Mod(1);
  for (auto ff : f) {
    ans *= ff + 1;
  }
  
  return ans.n;
}

int main() {
  int n;

  cin >> n;
  cout << solve(n) << endl;

  return 0;
}

Submission Info

Submission Time
Task C - Factors of Factorial
User hiratai
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1973 Byte
Status AC
Exec Time 1 ms
Memory 256 KB

Compile Error

./Main.cpp: In member function ‘Mod& Mod::operator/=(Mod)’:
./Main.cpp:49:25: warning: reference to local variable ‘m’ returned [-Wreturn-local-addr]
     Mod& operator/=(Mod m) {
                         ^

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 10
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_certain_01.txt, subtask_1_certain_02.txt, subtask_1_certain_03.txt, subtask_1_certain_04.txt, subtask_1_rand_01.txt, subtask_1_rand_02.txt, subtask_1_rand_03.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 256 KB
sample_02.txt AC 1 ms 256 KB
sample_03.txt AC 1 ms 256 KB
subtask_1_certain_01.txt AC 1 ms 256 KB
subtask_1_certain_02.txt AC 1 ms 256 KB
subtask_1_certain_03.txt AC 1 ms 256 KB
subtask_1_certain_04.txt AC 1 ms 256 KB
subtask_1_rand_01.txt AC 1 ms 256 KB
subtask_1_rand_02.txt AC 1 ms 256 KB
subtask_1_rand_03.txt AC 1 ms 256 KB