結果
問題 |
No.526 フィボナッチ数列の第N項をMで割った余りを求める
|
ユーザー |
|
提出日時 | 2018-07-08 18:39:51 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 194 ms / 2,000 ms |
コード長 | 436 bytes |
コンパイル時間 | 2,286 ms |
コンパイル使用メモリ | 74,256 KB |
実行使用メモリ | 41,540 KB |
最終ジャッジ日時 | 2024-07-07 23:48:01 |
合計ジャッジ時間 | 4,428 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 12 |
ソースコード
import java.util.Scanner; class no526{ public static void main(String[] args) { Scanner stdIn=new Scanner(System.in); long n=stdIn.nextLong(),m=stdIn.nextLong(),a[]=new long[3]; int i,j; for(i=0;i<2;i++) a[i]=i; if(2>n) System.out.print(0); else if(3>n) System.out.print(1); else { for(i=2;i<n;i++) { a[2]=(a[0]+a[1])%m; for(j=0;j<2;j++) a[j]=a[j+1]; } System.out.print(a[2]); } } }