Language: C++

import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

/// n 番目のフィボナッチ数を求める
/// F(0) = 0, F(1] = 1, F(2) = 1, F(3) = 2, F(4) = 3
int fib(int n) {
    if (n == 0) return 0;

    auto mat = new Mat2x2([[1, 1], [1, 0]]);
    auto m = mat.pow(n, int.max);
    return m.get(0, 1);
}

void main() {
    int n = readint;
    // 問題文の定義だとF(0) = 1, F(1) = 1 なので値を 1 だけずらす
    writeln(fib(n + 1));
}

class Mat2x2 {
    private const N = 2;
    private const int[][] _mat;

    this(const int[][] init) {
        assert(init.length == N);
        assert(init[0].length == init[1].length && init[0].length == N);

        _mat = init.dup;
    }

    int get(int r, int c) const {
        return _mat[r][c];
    }

    Mat2x2 mul(const Mat2x2 m, int mod) const {
        auto t = new int[][](N, N);

        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                int x = 0;
                for (int k = 0; k < N; k++) {
                    x = (x + (_mat[i][k] * m.get(k, j)) % mod) % mod;
                }
                t[i][j] = x;
            }
        }
        return new Mat2x2(t);
    }

    Mat2x2 copy() const {
        return new Mat2x2(_mat);
    }

    Mat2x2 pow(int k, int mod) const {
        assert(k > 0);
        if (k == 1) return this.copy();

        auto m = this.pow(k / 2, mod);
        return k % 2 == 0
            ? m.mul(m, mod)
            : this.mul(m.mul(m, mod), mod);
    }

    void dump() const {
        writeln(_mat[0][0], " ", _mat[0][1]);
        writeln(_mat[1][0], " ", _mat[1][1]);
    }
}



Compiler output:
a.cc:1:1: error: 'import' does not name a type
    1 | import std.algorithm;
      | ^~~~~~
a.cc:1:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:2:1: error: 'import' does not name a type
    2 | import std.array;
      | ^~~~~~
a.cc:2:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:3:1: error: 'import' does not name a type
    3 | import std.conv;
      | ^~~~~~
a.cc:3:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:4:1: error: 'import' does not name a type
    4 | import std.math;
      | ^~~~~~
a.cc:4:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:5:1: error: 'import' does not name a type
    5 | import std.range;
      | ^~~~~~
a.cc:5:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:6:1: error: 'import' does not name a type
    6 | import std.stdio;
      | ^~~~~~
a.cc:6:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:7:1: error: 'import' does not name a type
    7 | import std.string;
      | ^~~~~~
a.cc:7:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:8:1: error: 'import' does not name a type
    8 | import std.typecons;
      | ^~~~~~
a.cc:8:1: note: C++20 'import' only available with '-fmodules-ts'
a.cc:10:1: error: 'T' does not name a type
   10 | T read(T)() { return readln.chomp.to!T; }
      | ^
a.cc:11:1: error: 'T' does not name a type
   11 | T[] reads(T)() { return readln.split.to!(T[]); }
      | ^
a.cc:12:1: error: 'alias' does not name a type
   12 | alias readint = read!int;
      | ^~~~~
a.cc:13:1: error: 'alias' does not name a type
   13 | alias readints = reads!int;
      | ^~~~~
a.cc: In function 'int fib(int)':
a.cc:20:20: error: expected type-specifier before 'Mat2x2'
   20 |     auto mat = new Mat2x2([[1, 1], [1, 0]]);
      |                    ^~~~~~
a.cc:21:25: error: expected primary-expression before 'int'
   21 |     auto m = mat.pow(n, int.max);
      |                         ^~~
a.cc: At global scope:
a.cc:25:1: error: '::main' must return 'int'
   25 | void main() {
      | ^~~~
a.cc: In function 'int main()':
a.cc:26:13: error: 'readint' was not declared in this scope
   26 |     int n = readint;
      |             ^~~~~~~
a.cc:28:5: error: 'writeln' was not declared in this scope
   28 |     writeln(fib(n + 1));
      |     ^~~~~~~
a.cc: At global scope:
a.cc:32:12: error: expected ':' before 'const'
   32 |     private const N = 2;
      |            ^~~~~~
      |            :
a.cc:32:19: error: 'N' does not name a type
   32 |     private const N = 2;
      |                   ^
a.cc:33:12: error: expected ':' before 'const'
   33 |     private const int[][] _mat;
      |            ^~~~~~
      |            :
a.cc:33:22: error: expected unqualified-id before '[' token
   33 |     private const int[][] _mat;
      |                      ^
a.cc:35:5: error: expected unqualified-id before 'this'
   35 |     this(const int[][] init) {
      |     ^~~~
a.cc:79:2: error: expected ';' after class definition
   79 | }
      |  ^
      |  ;
a.cc: In member function 'int Mat2x2::get(int, int) const':
a.cc:43:16: error: '_mat' was not declared in this scope
   43 |         return _mat[r][c];
      |                ^~~~
a.cc: In member function 'Mat2x2 Mat2x2::mul(Mat2x2, int) const':
a.cc:47:28: error: expected primary-expression before ']' token
   47 |         auto t = new int[][](N, N);
      |                            ^
a.cc:47:30: error: 'N' was not declared in this scope
   47 |         auto t = new int[][](N, N);
      |                              ^
a.cc:53:31: error: '_mat' was not declared in this scope
   53 |                     x = (x + (_mat[i][k] * m.get(k, j)) % mod) % mod;
      |                               ^~~~
a.cc: In member function 'Mat2x2 Mat2x2::copy() const':
a.cc:62:27: error: '_mat' was not declared in this scope
   62 |         return new Mat2x2(_mat);
      |                           ^~~~
a.cc: In member function 'Mat2x2 Mat2x2::pow(int, int) const':
a.cc:66:9: error: 'assert' was not declared in this scope
   66 |         assert(k > 0);
      |         ^~~~~~
a.cc:1:1: note: 'assert' is defined in header '<cassert>'; this is probably fixable by adding '#include <cassert>'
  +++ |+#include <cassert>
    1 | import std.algorithm;
a.cc:67:33: error: request for member 'copy' in '(const Mat2x2*)this', which is of pointer type 'const Mat2x2*' (maybe you meant to use '->' ?)
   67 |         if (k == 1) return this.copy();
      |                                 ^~~~
a.cc:69:23: error: request for member 'pow' in '(const Mat2x2*)this', which is of pointer type 'const Mat2x2*' (maybe you meant to use '->' ?)
   69 |         auto m = this.pow(k / 2, mod);
      |                       ^~~
a.cc:72:20: error: request for member 'mul' in '(const Mat2x2*)this', which is of pointer type 'const Mat2x2*' (maybe you meant to use '->' ?)
   72 |             : this.mul(m.mul(m, mod), mod);
      |                    ^~~
a.cc: In member function 'void Mat2x2::dump() const':
a.cc:76:17: error: '_mat' was not declared in this scope
   76 |         writeln(_mat[0][0], " ", _mat[0][1]);
      |                 ^~~~
a.cc:76:9: error: 'writeln' was not declared in this scope
   76 |         writeln(_mat[0][0], " ", _mat[0][1]);
      |         ^~~~~~~