-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path282-tetrahedron.cpp
More file actions
36 lines (34 loc) · 901 Bytes
/
Copy path282-tetrahedron.cpp
File metadata and controls
36 lines (34 loc) · 901 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* Tetrahedron [166E]
* Problem: https://codeforces.com/problemset/problem/166/E
* Verdict: ACCEPTED Solved: 2021-02-21
* Language: C++17 (GCC 7-32)
* Runtime: 684 ms Memory: 156600 KB
* Tags: dp, math, matrices
* Author: BidoTeima
* Source: https://codeforces.com/contest/166/submission/108132146
*/
#include "bits/stdc++.h"
using namespace std;
using ll = long long; // respunsible prugramar
/// free eye torture
constexpr int mod = 1000000007; // respunsible prugramar
int main() {
vector<ll> pw3(10000005);
pw3[0] = 1;
for (ll i = 1; i <= 10000000; i++) {
pw3[i] = (pw3[i - 1] * 3)%mod;
}
vector<ll> dp(10000005);
dp[1] = 0;
dp[2] = 3; /// 3 ^ 1 - dp[1]
//dp[3]=6 /// 3 ^ 2 - dp[2]
//dp[4]=21 /// 3 ^ 3 - dp[3]
for (ll i = 3; i <= 10000000; i++) {
dp[i] = (pw3[i - 1] - dp[i - 1] + mod) % mod;
}
int n=0;
cin >> n;
cout << dp[n];
return 0;
}