Submit Info #8870

Problem Lang User Status Time Memory
Montmort Number cpp ignaciocanta AC 95 ms 17.67 MiB

ケース詳細
Name Status Time Memory
example_00 AC 0 ms 0.70 MiB
example_01 AC 0 ms 0.67 MiB
max_00 AC 95 ms 17.35 MiB
max_01 AC 90 ms 17.42 MiB
max_02 AC 88 ms 17.67 MiB
random_00 AC 38 ms 7.05 MiB
random_01 AC 40 ms 8.17 MiB
random_02 AC 51 ms 10.42 MiB
random_03 AC 38 ms 7.91 MiB
random_04 AC 76 ms 14.22 MiB

#include <bits/stdc++.h> using namespace std; #define forsn(i, s, n) for(int i=s;i<int(n);i++) #define forn(i, n) forsn(i, 0, n) #define all(v) v.begin(), v.end() #define rall(v) v.rbegin(), v.rend() typedef long long tint; typedef long double ld; const int INF = 190000000; const int MOD = 1e9+7; int main(){ int n, m; cin >> n >> m; tint dp[n+1]; dp[0] = 1; dp[1] = 0; dp[2] = 1; forsn(i, 3, n+1){ dp[i] = (i-1)*(dp[i-1]+dp[i-2]) % m; } forsn(i, 1, n+1){ cout << dp[i] << " "; } }