結果
問題 |
No.2989 Fibonacci Prize
|
ユーザー |
![]() |
提出日時 | 2024-12-14 09:52:23 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 650 bytes |
コンパイル時間 | 1,939 ms |
コンパイル使用メモリ | 171,464 KB |
実行使用メモリ | 1,628,672 KB |
最終ジャッジ日時 | 2024-12-14 09:52:50 |
合計ジャッジ時間 | 20,410 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 MLE * 2 |
other | AC * 35 WA * 38 TLE * 3 MLE * 1 |
ソースコード
#include <bits/stdc++.h> using namespace std; int main(){ int N,M,T=-1,MAX=1e9; cin>>N>>M; if(M==1){ if(N==1)cout<<1; else cout<<0; return 0; } vector<int> F(2); vector<int64_t>R(N,0),RR(N,0); F[0]=F[1]=1; for(int i=2;i<MAX;i++){ F.push_back((F[i-1]+F[i-2])%N); if(F[i-1]==0&&F[i]==1){ T=i; F.push_back(1); break; } } int64_t K=(M-2)/T,r=(M-2)%T; for(int i=0;i<T;i++){ R[(F[i+2]-1+N)%N]++; if(i<r)RR[(F[i+2]-1+N)%N]++; } RR[0]++; int64_t ans=0; for(int i=0;i<N;i++){ R[i]*=K; R[i]+=RR[i]; ans+=R[i]*(R[i]-1)/2; } if(F[(M-1)%T]%N==0)ans++; if(F[M%T]%N==0)ans+=2; cout<<ans<<endl; //cout<<T; }