Submission #1609680
Source Code Expand
import std.algorithm, std.conv, std.range, std.stdio, std.string;
const mod = 10 ^^ 9 + 7;
alias mint = FactorRing!(mod, true);
void main()
{
auto n = readln.chomp.to!int;
int[int] ft;
auto p = primes(n.nsqrt);
foreach (i; 2..n+1) {
while (i > 1) {
auto f = factor(i, p);
++ft[f];
i /= f;
}
}
auto ans = mint(1);
foreach (fti; ft.byValue)
ans *= fti + 1;
writeln(ans);
}
pure T[] primes(T)(T n)
{
import std.algorithm, std.bitmanip, std.conv, std.range;
auto sieve = BitArray();
sieve.length((n + 1) / 2);
sieve = ~sieve;
foreach (p; 1..((nsqrt(n) - 1) / 2 + 1))
if (sieve[p])
for (auto q = p * 3 + 1; q < (n + 1) / 2; q += p * 2 + 1)
sieve[q] = false;
auto r = sieve.bitsSet.map!(to!T).map!("a * 2 + 1").array;
r[0] = 2;
return r;
}
pure T factor(T)(T n, const T[] pi)
{
auto ma = nsqrt(n) + 1;
foreach (p; pi)
if (p > ma) return n;
else if (n % p == 0) return p;
return n;
}
pure T nsqrt(T)(T n)
{
import std.algorithm, std.conv, std.range, core.bitop;
if (n <= 1) return n;
T m = 1 << (n.bsr / 2 + 1);
return iota(1, m).map!"a * a".assumeSorted!"a <= b".lowerBound(n).length.to!T;
}
struct FactorRing(int m, bool pos = false)
{
version(BigEndian) {
union { long vl; struct { int vi2; int vi; } }
} else {
union { long vl; int vi; }
}
@property int toInt() { return vi; }
alias toInt this;
this(int v) { vi = v; }
this(int v, bool runMod) { vi = runMod ? mod(v) : v; }
this(long v) { vi = mod(v); }
ref FactorRing!(m, pos) opAssign(int v) { vi = v; return this; }
pure auto mod(int v) const
{
static if (pos) return v % m;
else return (v % m + m) % m;
}
pure auto mod(long v) const
{
static if (pos) return cast(int)(v % m);
else return cast(int)((v % m + m) % m);
}
static if (m < int.max / 2) {
pure auto opBinary(string op: "+")(int rhs) const { return FactorRing!(m, pos)(mod(vi + rhs)); }
pure auto opBinary(string op: "-")(int rhs) const { return FactorRing!(m, pos)(mod(vi - rhs)); }
} else {
pure auto opBinary(string op: "+")(int rhs) const { return FactorRing!(m, pos)(mod(vl + rhs)); }
pure auto opBinary(string op: "-")(int rhs) const { return FactorRing!(m, pos)(mod(vl - rhs)); }
}
pure auto opBinary(string op: "*")(int rhs) const { return FactorRing!(m, pos)(mod(vl * rhs)); }
pure auto opBinary(string op)(FactorRing!(m, pos) rhs) const
if (op == "+" || op == "-" || op == "*") { return opBinary!op(rhs.vi); }
static if (m < int.max / 2) {
auto opOpAssign(string op: "+")(int rhs) { vi = mod(vi + rhs); }
auto opOpAssign(string op: "-")(int rhs) { vi = mod(vi - rhs); }
} else {
auto opOpAssign(string op: "+")(int rhs) { vi = mod(vl + rhs); }
auto opOpAssign(string op: "-")(int rhs) { vi = mod(vl - rhs); }
}
auto opOpAssign(string op: "*")(int rhs) { vi = mod(vl * rhs); }
auto opOpAssign(string op)(FactorRing!(m, pos) rhs)
if (op == "+" || op == "-" || op == "*") { return opOpAssign!op(rhs.vi); }
}
Submission Info
Submission Time |
|
Task |
C - Factors of Factorial |
User |
tesh |
Language |
D (DMD64 v2.070.1) |
Score |
300 |
Code Size |
3179 Byte |
Status |
AC |
Exec Time |
1 ms |
Memory |
256 KB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
300 / 300 |
Status |
|
|
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 |