結果
問題 | No.1275 綺麗な式 |
ユーザー |
![]() |
提出日時 | 2024-11-06 00:39:24 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,218 bytes |
コンパイル時間 | 4,370 ms |
コンパイル使用メモリ | 255,244 KB |
最終ジャッジ日時 | 2025-02-25 02:24:14 |
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 60 |
ソースコード
#include <bits/stdc++.h>#include<atcoder/all>using namespace atcoder;using namespace std;using ll=long long;using ld=long double;ll mod=1000000007;ll inf=1000000000000000000;vector<vector<ll>>mul(vector<vector<ll>>&a,vector<vector<ll>>&b){vector<vector<ll>>c(a.size(),vector<ll>(b[0].size(),0));for (ll i = 0; i < a.size(); i++){for (ll j = 0; j < b[0].size(); j++){for (ll k = 0; k < a[0].size(); k++){c[i][j]+=(a[i][k]*b[k][j])%mod;c[i][j]%=mod;}}}return c;}vector<vector<ll>>matpow(vector<vector<ll>>a,ll n){vector<vector<ll>>b(a.size(),vector<ll>(a.size(),0));for (ll i = 0; i < a.size(); i++){b[i][i]=1;}while (n>0){if (n%2){b=mul(a,b);n-=1;}else{a=mul(a,a);n/=2;}}return b;}int main(){ll a,b,n;cin >> a >> b >> n;vector<vector<ll>>aa={{(2*a)%mod,(b+mod-(a*a)%mod)%mod},{1,0}};vector<vector<ll>>ans=matpow(aa,n);ll x=((2*a)%mod)*ans[1][0];x%=mod;x+=(2*ans[1][1])%mod;x%=mod;cout << x << endl;}