Submit Info #4987

Problem Lang User Status Time Memory
Montmort Number cpp risujiroh AC 66 ms 10.09 MiB

ケース詳細
Name Status Time Memory
example_00 AC 2 ms 0.68 MiB
example_01 AC 2 ms 0.71 MiB
max_00 AC 66 ms 9.68 MiB
max_01 AC 60 ms 9.80 MiB
max_02 AC 60 ms 10.09 MiB
random_00 AC 24 ms 4.17 MiB
random_01 AC 28 ms 4.67 MiB
random_02 AC 34 ms 6.11 MiB
random_03 AC 26 ms 4.67 MiB
random_04 AC 49 ms 8.10 MiB

#include <bits/stdc++.h> using namespace std; char readchar() { static char buf[1 << 15], *ptr = buf, *end = buf; if (ptr == end) ptr = buf, end = buf + fread(buf, 1, 1 << 15, stdin); return *ptr++; } void writechar(char c = 0) { static char buf[1 << 15], *ptr = buf; if (ptr == end(buf) or c == 0) fwrite(buf, 1, ptr - buf, stdout), ptr = buf; *ptr++ = c; } template <class Z> Z getint() { char c = readchar(); bool neg = c == '-'; Z res = neg ? 0 : c - '0'; while (isdigit(c = readchar())) res = res * 10 + (c - '0'); return neg ? -res : res; } template <class Z> void putint(Z a, char c = '\n') { if (a < 0) writechar('-'), a = -a; int d[40], i = 0; do d[i++] = a % 10; while (a /= 10); while (i--) writechar('0' + d[i]); writechar(c); } string getstring() { string res; for (char c; (c = readchar()) != '\n'; ) res += c; return res; } void putstring(string s) { for (char c : s) writechar(c); writechar('\n'); } unsigned mod = 2; struct mint { using m = mint; unsigned v; mint(long long x = 0) : v((x %= mod) < 0 ? x + mod : x) {} m operator-() const { return m() -= *this; } m& operator+=(m b) { if ((v += b.v) >= mod) v -= mod; return *this; } m& operator-=(m b) { if (v < b.v) v += mod; v -= b.v; return *this; } m& operator*=(m b) { v = (uint64_t)v * b.v % mod; return *this; } friend m operator+(m a, m b) { return a += b; } friend m operator-(m a, m b) { return a -= b; } friend m operator*(m a, m b) { return a *= b; } friend bool operator==(m a, m b) { return a.v == b.v; } friend string to_string(m a) { return to_string(a.v); } }; int main() { int n = getint<int>(); mod = getint<int>(); mint p1 = 1, p2; for (int k = 1; k <= n; ++k) { mint res = (k - 1) * (p2 + p1); putint(res.v, " \n"[k == n]); p2 = p1, p1 = res; } writechar(); }