結果
問題 | No.2989 Fibonacci Prize |
ユーザー |
👑 ![]() |
提出日時 | 2024-12-09 03:37:14 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 52 ms / 2,000 ms |
コード長 | 695 bytes |
コンパイル時間 | 2,064 ms |
コンパイル使用メモリ | 196,876 KB |
最終ジャッジ日時 | 2025-02-26 11:40:02 |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 77 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main(){ll N, M;cin >> N >> M;if (M <= 2){cout << (N == 1 ? 2 : 0) << "\n";return 0;}if (N == 1){cout << 3 + (M - 2) * (M - 1) / 2 << "\n";return 0;}ll a = 1, b = 1;vector<ll> q;do{a = (a + b) % N;swap(a, b);q.push_back(a);}while (a != 1 || b != 1);// f2, f3, ... , fmvector<ll> p(N);int len = q.size();int syo = (M - 1) / len;int rem = (M - 1) % len;for (int i = 0; i < len; i++){p[q[i]] += syo + (i < rem);}ll ans = 0;if (q[(M - 2) % len] == 0) ans += 2;if (q[(M - 3) % len] == 0) ans += 1;for (auto x : p) ans += x * (x - 1) / 2;cout << ans << "\n";}