結果
問題 | No.344 ある無理数の累乗 |
ユーザー |
|
提出日時 | 2018-04-29 12:46:19 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,549 bytes |
コンパイル時間 | 1,066 ms |
コンパイル使用メモリ | 88,184 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-27 23:30:47 |
合計ジャッジ時間 | 2,025 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 30 |
ソースコード
#include <iostream>#include <algorithm>#include <vector>#include <map>using namespace std;#define YES(condition) if(condition) cout << "YES" << endl; else cout << "NO" << endl#define Yes(condition) if(condition) cout << "Yes" << endl; else cout << "No" << endl#define POSS(condition) if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl#define Poss(condition) if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl#define First(condition) if(condition)cout << "First" << endl; else cout << "Second" << endl#define negative(condition, num) if(condition)cout << -1 << endl; else cout << num << endllong power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}#define mod long(1e9 + 7)#define bitcount(n) __builtin_popcount(n)struct matrix{vector<vector<int>> space;matrix(vector<vector<int>> element){space = element;}matrix(int size){space.resize(size, vector<int>(size));}matrix operator *(matrix another){matrix ans(int(space.size()));for(int i = 0; i < space.size(); i++){for(int j = 0; j < space.size(); j++){ans.space[i][j] = 0;for(int k = 0; k < space.size(); k++){ans.space[i][j] += space[i][k] * another.space[k][j];}ans.space[i][j] %= 1000;}}return ans;}inline vector<int> operator [](int index){return space[index];}};matrix A({{2, 2}, {1, 0}}), E({{1, 0}, {0, 1}});matrix matrix_power(int exponent){if(exponent % 2){return A * matrix_power(exponent - 1);}else if(exponent){matrix root_ans = matrix_power(exponent / 2);return root_ans * root_ans;}else{return E;}}int main(){int n;cin >> n;cout << ((matrix_power(n) * matrix({{2, 2}, {2, 999}}))[1][0] + 1000 - (n + 1) % 2) % 1000 << endl;}