Download spoj_cpp_clean/ADADUNG/ADADUNG-9.cpp from slayone/uva_spoj_raw: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/spoj_cpp_clean/ADADUNG/ADADUNG-9.cpp
- Command line
-
hf download hf://datasets/slayone/uva_spoj_raw/spoj_cpp_clean/ADADUNG/ADADUNG-9.cpp
-
curl -L -o ADADUNG-9.cpp https://huggingface.co/datasets/slayone/uva_spoj_raw/resolve/main/spoj_cpp_clean/ADADUNG/ADADUNG-9.cpp
1.06 kB
| /* | |
| **************************************************************** | |
| **************************************************************** | |
| -> Coded by Stavros Chryselis | |
| -> Visit my github for more solved problems over multiple sites | |
| -> https://github.com/StavrosChryselis | |
| -> Feel free to email me at stavrikios@gmail.com | |
| **************************************************************** | |
| **************************************************************** | |
| */ | |
| using namespace std; | |
| const ll MOD = 1000000007; | |
| ll memo[MAXN]; | |
| ll derangement(ll num) | |
| { | |
| if (num <= 1) | |
| return 0; | |
| if (num == 2) | |
| return 1LL; | |
| if (memo[num]) | |
| return memo[num]; | |
| ll temp = derangement(num - 1) + derangement(num - 2); | |
| temp %= MOD; | |
| memo[num] = (num - 1) * temp; | |
| memo[num] %= MOD; | |
| return memo[num]; | |
| } | |
| int main() | |
| { | |
| // freopen("input.txt", "r", stdin); | |
| ios::sync_with_stdio(0); | |
| int T, N; | |
| cin >> T; | |
| while (T--) | |
| { | |
| cin >> N; | |
| cout << derangement(N) << "\n"; | |
| } | |
| return 0; | |
| } | |