// No.526 フィボナッチ数列の第N項をMで割った余りを求める // https://yukicoder.me/problems/no/526 // #include using namespace std; unsigned int solve(unsigned int N, unsigned int M); int main() { unsigned int N, M; cin >> N >> M; unsigned int ans = solve(N, M); cout << ans << endl; } unsigned int solve(unsigned int N, unsigned int M) { unsigned long a, b; a = 0; b = 1; for (auto i = 2; i < N; ++i) { unsigned long tmp = b; b = (a + b) % M; a = tmp; } return b; }