#include #include using namespace std; #include using namespace atcoder; #define rep(i,n) for(int i=0;i<(int)n;i++) #define rep1(i,n) for(int i=1;i<=(int)n;i++) using ll = long long; using ull = unsigned long long; using uint = unsigned int; using vi = vector; using vvi = vector; using vvvi = vector; using vd = vector; using vvd = vector; using vs = vector; using vb = vector; using vvb = vector; using vl = vector; using vvl = vector; #define INF ((ll)2e18) #define IINF ((int)1e9) const double PI = 3.1415926535897932384626433832795028841971; templateinline bool chmax(T& a, T b) { return ((a < b) ? (a = b, true) : (false)); } templateinline bool chmin(T& a, T b) { return ((a > b) ? (a = b, true) : (false)); } #define yesno(ans) cout<<(ans?"Yes\n":"No\n") #define all(v) (v).begin(),(v).end() const int di[] = { 0, 1, 0,-1 }; const int dj[] = { 1, 0,-1, 0 }; //const int di[] = { 0, 1, 1, 1, 0, -1,-1,-1}; //const int dj[] = { 1, 1, 0,-1,-1, -1, 0, 1}; //const int di[]={-1,-1, 0, 0, 1, 1}; //const int dj[]={-1, 0,-1, 1, 0, 1}; const double EPS = 1e-11; //using mint = modint998244353; using mint = modint1000000007; template void Fill(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); } #define MAX 300 int solve1(); int solve2(); int solve3(); int solve(); /* #include std::random_device seed_gen; std::mt19937 engine(seed_gen()); void generate() { int n = engine() %100000 ; //int n = 1000; cout << n << endl; rep(i, n) { cout<<(engine()%212122 * 10282)%1000000000<sync_with_stdio(0); //generate(); int T = 1; while (T--)solve2(); return 0; } int solve() { return 0; } //小課題1(n<=10000,b<=30) int solve1() { int n, b, K; cin >> n >> b >> K; vi c(K); rep(i, K)cin >> c[i]; vector> dp(n + 1, vector(b, 0)); dp[0][0] = 1; for (int i = 0; i < n; i++) { for (int j = 0; j < b; j++) { for (int k = 0; k < K; k++) { int next = (10 * j + c[k]) % b; dp[i + 1][next] += dp[i][j]; } } } cout << dp[n][0].val() << endl; return 0; } //小課題2(n<=10000) ll M = 0; vvl mul(vvl& a, vvl& b) { vvl c(a.size(), vl(b[0].size())); for (int i = 0; i < a.size(); i++) { for (int k = 0; k < b.size(); k++) { for (int j = 0; j < b[0].size(); j++) { c[i][j] += (a[i][k] * b[k][j]); c[i][j] %= M; } } } return c; } vvl powmat(vvl a, ll n) { vvl b(a.size(), vl(a.size())); rep(i, a.size())b[i][i] = 1; while (n>0) { if (n%2==1)b = mul(b, a); a = mul(a, a); n /= 2; } return b; } int solve2() { ll n; cin >> n; cin >> M; vvl a(2, vl(2)); a[0][0] = 1; a[0][1] = 1; a[1][0] = 1; a[1][1] = 0; for (int i = n; i <= n; i++) { auto res = powmat(a, i-1); cout << res[1][0] << endl; } return 0; } //小課題3(追加の制約なし) int solve3() { return 0; } /* compile g++ a.cpp -std=c++17 -I . ./a */