結果
問題 |
No.526 フィボナッチ数列の第N項をMで割った余りを求める
|
ユーザー |
|
提出日時 | 2017-07-01 19:46:54 |
言語 | Java (openjdk 23) |
結果 |
WA
|
実行時間 | - |
コード長 | 531 bytes |
コンパイル時間 | 2,600 ms |
コンパイル使用メモリ | 74,600 KB |
実行使用メモリ | 54,456 KB |
最終ジャッジ日時 | 2024-10-05 00:06:58 |
合計ジャッジ時間 | 4,516 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 10 WA * 2 |
ソースコード
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%m; } System.out.println(fib1); s.close(); } }