結果
| 問題 |
No.673 カブトムシ
|
| コンテスト | |
| ユーザー |
hamray
|
| 提出日時 | 2019-09-01 23:29:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,656 bytes |
| コンパイル時間 | 2,187 ms |
| コンパイル使用メモリ | 167,268 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-02 16:02:56 |
| 合計ジャッジ時間 | 2,969 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//container util
//------------------------------------------
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
struct Edge {
int to, from;
ll cost;
Edge(int from, int to, ll cost): from(from), to(to), cost(cost) {}
};
typedef vector<vector<Edge>> AdjList;
AdjList graph;
typedef vector<ll> vec;
typedef vector<vec> mat;
mat mul(mat &A, mat &B) {
mat C(A.size(), vec((int)B[0].size()));
for(int i=0; i<A.size(); ++i){
for(int k=0; k<B.size(); ++k){
for(int j=0; j<B[0].size(); ++j){
C[i][j] = (C[i][j] + A[i][k] * B[k][j] %MOD) % MOD;
}
}
}
return C;
}
mat mat_pow(mat A, ll n) {
mat B(A.size(), vec((int)A.size()));
for(int i=0; i<A.size(); ++i){
B[i][i] = 1;
}
while(n > 0) {
if(n & 1) B = mul(B, A);
A = mul(A, A);
n >>= 1;
}
return B;
}
int main() {
//cin.tie(0);
//ios::sync_with_stdio(false);
//cout << fixed << setprecision(10);
ll B, C, D; cin >> B >> C >> D;
B %= MOD; C %=MOD;
mat A(2, vec(2));
A[0][0] = C; A[0][1] = 0;
A[1][1] = A[1][0] = 1;
A = mat_pow(A, D + 1);
cout << (A[1][0]+MOD-1)%MOD * B % MOD << endl;
return 0;
}
hamray