結果
問題 | No.891 隣接3項間の漸化式 |
ユーザー |
![]() |
提出日時 | 2019-09-20 22:23:57 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 6,572 bytes |
コンパイル時間 | 1,901 ms |
コンパイル使用メモリ | 172,660 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-14 18:13:09 |
合計ジャッジ時間 | 3,214 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
ソースコード
// warm heart, wagging tail,and a smile just for you!//// ▒█████▒▒// ██████████▒// ▒████████████▒// ██████████████████// ████████████████████▒// ▒██████████████████████▒// ▒███████████████████████// ▒████▒▒▒▒▒▒█████████████████▒// ███▒▒▒▒▒▒██████████████████████▒▒▒// ▒██▒▒███████████████████████▒▒▒▒▒██████// ▒█████████████████████████▒▒▒▒▒▒█████████▒// ▒█████████████████████▒▒▒▒▒▒██████████████// ▒████ ████▒▒▒▒▒████ ████▒// ▒█████▒ ████ ▒▒▒▒███████ ████ ██████▒// ▒██▒▒▒▒▒ ██████ █████████ ██████ ██▒▒▒██▒// █████████ ████████ █████████ ████████ ▒▒▒▒█████// ▒█████████ ██████ ████████▒ ██████ █████████// ▒██████████ ████ █████▒▒▒▒▒▒ ████ ██████████// ████████████ ▒▒▒▒▒▒▒████████ ███████████▒// ▒██████████▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒███████████████████████████████████▒// ███▒▒▒▒▒▒▒▒▒▒▒▒█████████████████████████████████████████▒▒████████▒// ▒▒▒▒▒▒▒▒▒██████████████ ███████▒▒▒▒███████████// █████████████████████████ ███████▒▒▒██████████████▒// █████████████████████████████ ███████▒▒▒██████████████████▒// ██████████████████████████████████████████████████████████████████████// ██████████████████████████████████████████████████████████████████▒// ▒█████████████████▒▒▒▒▒▒▒██████████████████████████████████▒▒▒//#include "bits/stdc++.h"using namespace std;#define MOD 1000000007//#define MOD 998244353const double EPS = 1e-9;#define INF (1LL<<60)#define D double#define fs first#define sc second#define int long long#define FOR(i,a,b) for(int i=(a);i<(b);++i)#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)#define REP(i,n) FOR(i,0,(n))#define RREP(i,n) RFOR(i,0,(n))#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)#define range(i,a,b) ((a)<=(i) && (i)<(b))#define debug(x) cout << #x << " = " << (x) << endl;#define SP << " " <<typedef pair<int,int> P;#include <cstdint>template <std::uint_fast64_t Modulus> class modint {using u64 = std::uint_fast64_t;u64 a;public:constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}constexpr u64 val() const noexcept { return a; }constexpr modint operator+(const modint rhs) const noexcept {return modint(*this) += rhs;}constexpr modint operator-(const modint rhs) const noexcept {return modint(*this) -= rhs;}constexpr modint operator*(const modint rhs) const noexcept {return modint(*this) *= rhs;}constexpr modint operator/(const modint rhs) const noexcept {return modint(*this) /= rhs;}constexpr bool operator==(const modint rhs) const noexcept {return modint(*this).val() == rhs.val();}modint &operator+=(const modint rhs) noexcept {a += rhs.a;if (a >= Modulus) {a -= Modulus;}return *this;}modint &operator-=(const modint rhs) noexcept {if (a < rhs.a) {a += Modulus;}a -= rhs.a;return *this;}modint &operator*=(const modint rhs) noexcept {a = a * rhs.a % Modulus;return *this;}modint &operator/=(modint rhs) noexcept {u64 exp = Modulus - 2;while (exp) {if (exp % 2) {*this *= rhs;}rhs *= rhs;exp /= 2;}return *this;}};using mint = modint<MOD>;typedef vector<mint> vec;typedef vector<vector<mint>> mat;int m;vec matmul(vec &dp, mat &mt){vec ret(m,0);REP(i,m) REP(j,m) ret[i] += mt[i][j]*dp[j];return ret;}mat update(mat &mt){mat ret(m,vec(m,0));REP(i,m) REP(j,m) REP(k,m) ret[i][j] += mt[i][k]*mt[k][j];return ret;}void matpow(vec &dp, mat &mt, int k){m = dp.size();while(k){if(k%2) dp = matmul(dp,mt);mt = update(mt);k /= 2;}}signed main(){ios::sync_with_stdio(false);cin.tie(0);int a,b,n;cin >> a >> b >> n;vec dp = {0,1};mat mt(2,vec(2));mt[0][0] = 0; mt[0][1] = 1; mt[1][0] = b; mt[1][1] = a;matpow(dp,mt,n);cout << dp[0].val() << endl;return 0;}