結果
問題 | No.1275 綺麗な式 |
ユーザー |
![]() |
提出日時 | 2020-10-30 22:55:24 |
言語 | C++17 (gcc 11.2.0 + boost 1.78.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 3,659 bytes |
コンパイル時間 | 1,807 ms |
使用メモリ | 8,368 KB |
最終ジャッジ日時 | 2023-02-21 15:32:15 |
合計ジャッジ時間 | 3,898 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
8,228 KB |
testcase_01 | AC | 1 ms
8,300 KB |
testcase_02 | AC | 1 ms
8,240 KB |
testcase_03 | AC | 1 ms
8,240 KB |
testcase_04 | AC | 2 ms
7,660 KB |
testcase_05 | AC | 2 ms
7,604 KB |
testcase_06 | AC | 1 ms
7,660 KB |
testcase_07 | AC | 1 ms
7,596 KB |
testcase_08 | AC | 1 ms
8,244 KB |
testcase_09 | AC | 2 ms
8,252 KB |
testcase_10 | AC | 2 ms
7,664 KB |
testcase_11 | AC | 1 ms
8,292 KB |
testcase_12 | AC | 1 ms
7,576 KB |
testcase_13 | AC | 1 ms
8,368 KB |
testcase_14 | AC | 1 ms
7,592 KB |
testcase_15 | AC | 2 ms
8,228 KB |
testcase_16 | AC | 2 ms
8,244 KB |
testcase_17 | AC | 1 ms
8,256 KB |
testcase_18 | AC | 1 ms
8,228 KB |
testcase_19 | AC | 1 ms
7,564 KB |
testcase_20 | AC | 1 ms
8,252 KB |
testcase_21 | AC | 1 ms
7,600 KB |
testcase_22 | AC | 1 ms
8,320 KB |
testcase_23 | AC | 2 ms
7,656 KB |
testcase_24 | AC | 1 ms
7,680 KB |
testcase_25 | AC | 1 ms
8,232 KB |
testcase_26 | AC | 1 ms
7,660 KB |
testcase_27 | AC | 1 ms
7,596 KB |
testcase_28 | AC | 2 ms
8,324 KB |
testcase_29 | AC | 1 ms
7,596 KB |
testcase_30 | AC | 1 ms
7,724 KB |
testcase_31 | AC | 1 ms
8,208 KB |
testcase_32 | AC | 1 ms
7,676 KB |
testcase_33 | AC | 1 ms
8,312 KB |
testcase_34 | AC | 2 ms
8,316 KB |
testcase_35 | AC | 2 ms
8,228 KB |
testcase_36 | AC | 1 ms
7,604 KB |
testcase_37 | AC | 1 ms
8,292 KB |
testcase_38 | AC | 1 ms
7,596 KB |
testcase_39 | AC | 1 ms
8,224 KB |
testcase_40 | AC | 1 ms
8,316 KB |
testcase_41 | AC | 1 ms
7,668 KB |
testcase_42 | AC | 2 ms
8,320 KB |
testcase_43 | AC | 2 ms
7,596 KB |
testcase_44 | AC | 1 ms
8,296 KB |
testcase_45 | AC | 1 ms
7,656 KB |
testcase_46 | AC | 1 ms
8,216 KB |
testcase_47 | AC | 1 ms
8,248 KB |
testcase_48 | AC | 1 ms
8,292 KB |
testcase_49 | AC | 1 ms
8,300 KB |
testcase_50 | AC | 1 ms
7,596 KB |
testcase_51 | AC | 1 ms
8,320 KB |
testcase_52 | AC | 1 ms
7,604 KB |
testcase_53 | AC | 1 ms
8,324 KB |
testcase_54 | AC | 2 ms
7,656 KB |
testcase_55 | AC | 1 ms
8,224 KB |
testcase_56 | AC | 1 ms
8,244 KB |
testcase_57 | AC | 1 ms
7,672 KB |
testcase_58 | AC | 1 ms
8,316 KB |
testcase_59 | AC | 1 ms
7,612 KB |
testcase_60 | AC | 1 ms
8,228 KB |
testcase_61 | AC | 1 ms
8,316 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #define int long long #define ii pair <int, int> #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC #define debug(x) std::cout << #x << ": " << x << '\n'; const int MOD = 1e9+7, N = 2; //need define int long long int mod(int n) { n %= MOD; if (n < 0) return n + MOD; else return n; } int fp(int a, int p) { int ans = 1, c = a; for (int i = 0; (1ll << i) <= p; ++i) { if ((p >> i) & 1) ans = mod(ans * c); c = mod(c * c); } return ans; } int dv(int a, int b) { return mod(a * fp(b, MOD - 2)); } struct M { ll x; M (int x_) { x = mod(x_); } M () { x = 0; } M operator + (M y) { int ans = x + y.x; if (ans >= MOD) ans -= MOD; return M(ans); } M operator - (M y) { int ans = x - y.x; if (ans < 0) ans += MOD; return M(ans); } M operator * (M y) { return M(x * y.x % MOD); } M operator / (M y) { return M(x * fp(y.x, MOD - 2) % MOD); } M operator + (int y) { return (*this) + M(y); } M operator - (int y) { return (*this) - M(y); } M operator * (int y) { return (*this) * M(y); } M operator / (int y) { return (*this) / M(y); } M operator ^ (int p) { return M(fp(x, p)); } void operator += (M y) { *this = *this + y; } void operator -= (M y) { *this = *this - y; } void operator *= (M y) { *this = *this * y; } void operator /= (M y) { *this = *this / y; } void operator += (int y) { *this = *this + y; } void operator -= (int y) { *this = *this - y; } void operator *= (int y) { *this = *this * y; } void operator /= (int y) { *this = *this / y; } void operator ^= (int p) { *this = *this ^ p; } }; M f[N], inv[N]; void prec() { f[0] = M(1); for (int i = 1; i < N; ++i) f[i] = f[i - 1] * M(i); inv[N - 1] = f[N - 1] ^ (MOD - 2); for (int i = N - 2; i >= 0; --i) inv[i] = inv[i + 1] * M(i + 1); } M C(int n, int k) { if (n < k) return M(0); else return f[n] * inv[k] * inv[n - k]; } struct Matrix { M a[N][N]; Matrix () { memset(a, 0, sizeof a); } Matrix (bool t) { memset(a, 0, sizeof a); for (int i = 0; i < N; ++i) a[i][i] = t; } M * operator [] (int i) { return a[i]; } Matrix operator * (Matrix b) { Matrix ans; for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) for (int k = 0; k < N; ++k) ans[i][j] += a[i][k] * b[k][j]; return ans; } void operator *= (Matrix b) { *this = *this * b; } void print() { for (int i = 0; i < N; ++i) { for (int j = 0; j < N; ++j) cout << a[i][j].x << ' '; cout << '\n'; } cout << '\n'; } Matrix operator ^ (int p) { Matrix cur = *this; Matrix ans(1); for (int i = 0; (1ll << i) <= p; ++i) { if ((p >> i) & 1) ans *= cur; cur *= cur; } return ans; } void operator ^= (int p) { *this = *this ^ p; } }; signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20); #endif int A, B, n; cin >> A >> B >> n; Matrix a; a[0][0] = A; a[1][1] = A; a[0][1] = B; a[1][0] = 1; a ^= n; M ans = a[0][0] + a[1][1]; cout << ans.x << endl; }