結果
問題 |
No.526 フィボナッチ数列の第N項をMで割った余りを求める
|
ユーザー |
|
提出日時 | 2017-07-01 19:16:05 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 529 bytes |
コンパイル時間 | 2,048 ms |
コンパイル使用メモリ | 74,276 KB |
実行使用メモリ | 54,360 KB |
最終ジャッジ日時 | 2024-10-05 00:02:46 |
合計ジャッジ時間 | 4,889 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 WA * 1 |
other | AC * 6 WA * 6 |
ソースコード
import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner s = new Scanner(System.in); String[] str = s.nextLine().split(" "); int n = Integer.parseInt(str[0]); int m =Integer.parseInt(str[1]); long fib1; if(n == 0){ fib1=0%m; } else if(n == 1){ fib1= 1%m; } else{ int n_1 = 1; int n_2 = 1; int ans = 0; for(int i = 3;i<n;i++){ ans = n_1 + n_2; n_2 = n_1%m; n_1 = ans%m; } fib1= ans; } System.out.println(fib1); s.close(); } }