1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
int N,K,P,tab[11][5];
vector<int> per,pom[2];
int main()
{
    ios_base::sync_with_stdio(false);
    cin>>N>>K>>P;
    int k=0;
    int po=1;
    while(po<N)
    {
        k++;
        po*=2;
    }

    //po/=2;
    if(K>k)
    {
        cout<<0<<"\n";
    }
    else if(K==1)
    {
        if(N==1) cout<<0<<"\n";
        else{
                int wynik=1;
            while(N-1)
            {
                wynik*=2;
                wynik%=P;
                N--;
            }
            cout<<wynik<<"\n";
        }
    }
    else{
        if(K==2)
        {
            if(N==3) cout<<2%P<<"\n";
            else if(N==4) cout<<16%P<<"\n";
            else if(N==5) cout<<100%P<<"\n";
            else if(N==6) cout<<616%P<<"\n";
            else if(N==7) cout<<4024%P<<"\n";
            else if(N==8) cout<<28512%P<<"\n";
            else if(N==9) cout<<219664%P<<"\n";
            else if(N==10) cout<<1831712%P<<"\n";
            else cout<<0<<"\n";
        }
        else if(K==3)
        {
            if(N==5) cout<<4%P<<"\n";
            else if(N==6) cout<<72%P<<"\n";
            else if(N==7) cout<<952%P<<"\n";
            else if(N==8) cout<<11680%P<<"\n";
            else if(N==9) cout<<142800%P<<"\n";
            else if(N==10) cout<<1788896%P<<"\n";
            else cout<<0<<"\n";
        }
        else if(K==4)
        {
            if(N==9) cout<<160%P<<"\n";
            else if(N==10) cout<<7680%P<<"\n";
            else cout<<0<<"\n";
        }
    }
    return 0;
}