結果
問題 | No.1559 Next Rational |
ユーザー | noya2 |
提出日時 | 2021-03-04 12:53:36 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 3,567 bytes |
コンパイル時間 | 4,650 ms |
コンパイル使用メモリ | 269,652 KB |
実行使用メモリ | 6,944 KB |
最終ジャッジ日時 | 2024-06-25 07:56:53 |
合計ジャッジ時間 | 5,315 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,812 KB |
testcase_01 | AC | 2 ms
6,944 KB |
testcase_02 | AC | 2 ms
6,940 KB |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 2 ms
6,940 KB |
testcase_05 | AC | 2 ms
6,944 KB |
testcase_06 | AC | 2 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,944 KB |
testcase_08 | AC | 2 ms
6,940 KB |
testcase_09 | AC | 2 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,940 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 2 ms
6,940 KB |
testcase_14 | AC | 2 ms
6,940 KB |
testcase_15 | AC | 2 ms
6,944 KB |
testcase_16 | AC | 2 ms
6,944 KB |
testcase_17 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> /* #include <boost/multiprecision/cpp_dec_float.hpp> #include <boost/multiprecision/cpp_int.hpp> namespace mp = boost::multiprecision; using bint = mp::cpp_int; */ #include <atcoder/all> #include <iostream> #include <queue> #include <stack> #include <vector> #include <string> #include <set> #include <map> #include <random> #define rep(i,n) for (int i = 0; i < (n); ++i) #define repp(i,n,m) for (int i = m; i < (n); ++i) using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using P = pair<int, int>; using PI = pair<pair<int,int>,int>; using PL = pair<long long, long long>; using PLL = pair<pair<long long, long long>, long long>; using Pxy = pair<long double, long double>; const int INF = 2001001007; const int modd = 1000000007; const long long modl = 1000000007LL; const long long mod = 998244353LL; const ll inf = 8e18; template <typename SA> void priv(vector<SA> &ar){ rep(i,ar.size()-1) cout << ar[i] << " "; cout << ar[ar.size()-1] << endl; } template <typename SB> void privv(vector<vector<SB>> &ar){ rep(i,ar.size()){ rep(j,ar[i].size()-1) cout << ar[i][j] << " "; cout << ar[i][ar[i].size()-1] << endl; } } template <typename SC> bool range(SC a, SC b, SC x){return (a <= x && x < b);} bool rrange(P a, P b, P xy){ bool s = range(a.first,b.first,xy.first); bool t = range(a.second,b.second,xy.second); return (s && t); } template <typename SD> void sor(vector<SD> &ar){sort(ar.begin(),ar.end());} template <typename SE> void rev(vector<SE> &ar){reverse(ar.begin(),ar.end());} template <typename SF> bool chmin(SF &a, const SF &b){if(a>b){a = b; return true;} return false;} template <typename SG> bool chmax(SG &a, const SG &b){if(a<b){a = b; return true;} return false;} template <typename SH> void eru(vector<SH> &ar){sor(ar);ar.erase(unique(ar.begin(),ar.end()),ar.end());} template <typename SI> SI last(vector<SI> &ar){return ar[ar.size()-1];} void yes(){cout << "Yes" << endl;} void no (){cout << "No" << endl;} void yn (bool t){if(t)yes();else no();} void Yes(){cout << "YES" << endl;} void No (){cout << "NO" << endl;} void YN (bool t){if(t)Yes();else No();} vector<int> dx = {0,1,0,-1}; vector<int> dy = {1,0,-1,0}; ll cel (ll a, ll b){ if (a % b == 0) return a / b; else return a / b + 1; } ll gcds(ll a, ll b){ ll c = a % b; while (c != 0){ a = b; b = c; c = a % b; } return b; } vector<vector<modint1000000007>> mult(vector<vector<modint1000000007>> &a, vector<vector<modint1000000007>> &b){ vector<vector<modint1000000007>> ans(2,vector<modint1000000007>(2,0)); rep(i,2){ rep(j,2){ rep(k,2){ ans[i][j] += a[i][k] * b[k][j]; } } } return ans; } vector<vector<modint1000000007>> saiki(vector<vector<modint1000000007>> &ar, ll n){ if (n == 1){ return ar; } vector<vector<modint1000000007>> ans = saiki(ar,n/2LL); ans = mult(ans,ans); if (n % 2 == 1) ans = mult(ans,ar); return ans; } int main(){ ll n; cin >> n; ll aa, bb, kk; cin >> aa >> bb >> kk; modint1000000007 a = aa; modint1000000007 b = bb; modint1000000007 k = kk; modint1000000007 w = 1; modint1000000007 x = -w; modint1000000007 y = (a*a + b*b + k) / (a*b); if (n == 1) {cout << a.val() << endl; return 0;} vector<vector<modint1000000007>> t = {{y,x},{1,0}}; auto s = saiki(t,n-1); modint1000000007 ans = s[1][0] * b + s[1][1] * a; cout << ans.val() << endl; }