結果
問題 |
No.1275 綺麗な式
|
ユーザー |
|
提出日時 | 2025-08-16 12:02:30 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,506 bytes |
コンパイル時間 | 3,576 ms |
コンパイル使用メモリ | 297,832 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-08-16 12:02:41 |
合計ジャッジ時間 | 5,614 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 60 |
ソースコード
#include<bits/stdc++.h> #if __has_include(<atcoder/all>) #include<atcoder/modint> #endif using namespace std; #define done(...) return pp(__VA_ARGS__) #define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__) #define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step) #define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);} #define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{ #define use_ml1000000007 using ml=atcoder::modint1000000007; namespace my{ auto&operator<<(ostream&o,const atcoder::modint1000000007&x){return o<<(int)x.val();} void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);} using ll=long long; template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};} void lin(auto&...a){(cin>>...>>a);} constexpr auto pow(auto x,ll n,auto e){assert(n>=0);decltype(x)r=e;for(;n;x*=x,n>>=1)if(n&1)r*=x;return r;} template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>; } namespace my{ template<class V>struct vec; template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;}; template<class T>struct hvec_helper<0,T>{using type=T;}; template<int D,class T>using hvec=hvec_helper<D,T>::type; template<class V>struct vec:vector<V>{ using vector<V>::vector; ll size()const{return vector<V>::size();} }; template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>; } namespace my{ template<class T>struct matrix:vec<vec<T>>{ ll H,W; matrix()=default; matrix(ll n):H(n),W(n){this->resize(n,vec<T>(n));} matrix(ll n,ll m,T x={}):H(n),W(m){this->resize(n,vec<T>(m,x));} matrix(const vec<vec<T>>&v):H(v.size()),W(v[0].size()){vector<vec<T>>::operator=(v);} auto&operator*=(const matrix&a){ assert(W==a.H); matrix r(H,a.W); fo(i,H)fo(k,W)fo(j,a.W)r[i][j]+=(*this)[i][k]*a[k][j]; swap(*this,r); return*this; } friend vec<T>operator*(const vec<T>&v,const matrix&a){ assert(v.size()==a.H); vec<T>r(a.W); fo(i,a.H)fo(j,a.W)r[j]+=v[i]*a[i][j]; return r; } auto pow(ll n)const{matrix e(H);fo(i,H)e[i][i]=1;return my::pow(*this,n,e);} }; } namespace my{entry void main(){ LL(a,b,N); if(N==0)done(2); use_ml1000000007 matrix<ml>A({{2*a,1},{-a*a+b,0}}); A=A.pow(N-1); pp((vec<ml>{2*a,2}*A)[0]); }}