結果
問題 |
No.526 フィボナッチ数列の第N項をMで割った余りを求める
|
ユーザー |
|
提出日時 | 2025-07-17 18:00:48 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 79 ms / 2,000 ms |
コード長 | 1,936 bytes |
コンパイル時間 | 1,701 ms |
コンパイル使用メモリ | 194,736 KB |
実行使用メモリ | 7,716 KB |
最終ジャッジ日時 | 2025-07-17 18:00:52 |
合計ジャッジ時間 | 3,043 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; const ll INF = LLONG_MAX / 4; const ll mod1 = 1000000007; const ll mod9 = 998244353; const ll Hash = 10000000000000061; #define all(a) (a).begin(),(a).end() #define rep(i, n) for (ll i = 0; (i) < (n); ++(i)) #define reps(i, l, r) for(ll i = (l); (i) < (r); ++(i)) ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1}; ll dy[8] = {0, -1, -1, -1, 0, 1, 1, 1}; template <typename T> bool chmax(T &a, const T& b) { if (a < b) { a = b; return true; } return false; } template <typename T> bool chmin(T &a, const T& b) { if (a > b) { a = b; return true; } return false; } #define EPS (1e-10) #define equals(a, b) (fabs((a) - (b)) < EPS) class Point { public: ld x; ld y; Point(ld _x = 0, ld _y = 0) : x(_x), y(_y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(ld a) { return Point(a * x, a * y); } Point operator/(ld a) { return Point(x / a, y / a); } ld abs() { return sqrt(norm()); } ld norm() { return x * x + y * y; } bool operator<(const Point& p) const { return !equals(x, p.x) ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.x) < (1e-10) && fabs(y - p.y) < (1e-10); } }; typedef Point Vector; struct Segment { Point A; Point B; }; typedef Segment Line; class Circle { public: Point C; ld r; Circle(Point C = Point(), ld r = 0.0) : C(C), r(r) {} }; typedef vector<Point> Polygon; void solve(){ ll N, M; cin >> N >> M; N -= 2; ll pre = 0, pos = 1; rep(i, N){ swap(pre, pos); pos += pre; pos %= M; } cout << pos << endl; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); cout << fixed << setprecision(20); solve(); }