Submit Info #13622

Problem Lang User Status Time Memory
Montmort Number cpp (anonymous) AC 96 ms 13.92 MiB

ケース詳細
Name Status Time Memory
example_00 AC 2 ms 0.72 MiB
example_01 AC 1 ms 0.68 MiB
max_00 AC 96 ms 13.53 MiB
max_01 AC 88 ms 13.67 MiB
max_02 AC 86 ms 13.92 MiB
random_00 AC 37 ms 5.55 MiB
random_01 AC 42 ms 6.42 MiB
random_02 AC 53 ms 8.19 MiB
random_03 AC 40 ms 6.30 MiB
random_04 AC 70 ms 11.17 MiB

#include <vector> struct montmort { private : std::vector<int> table; public : montmort (std::size_t n, int mod) : table(n + 4, 0) { table[2] = 1; table[3] = 2; for (int i = 4; i <= n; i++) { table[i] = (1LL * (i - 1) * (table[i - 1] + table[i - 2])) % mod; } } const int& operator[] (int i) const { return (table[i]); } }; #include <iostream> int main() { int n, m; std::cin >> n >> m; montmort num(n, m); for (int i = 1; i <= n; i++) { std::cout << num[i] << ' '; } return 0; }