#include <map> #include <utility> #include <iostream> using namespace std; map< pair< int, int >, long long > cache; void fill_cache() { cache[ make_pair( 1, 0 ) ] = 1; cache[ make_pair( 10, 1 ) ] = 512; cache[ make_pair( 10, 2 ) ] = 1831712; cache[ make_pair( 10, 3 ) ] = 1788896; cache[ make_pair( 10, 4 ) ] = 7680; cache[ make_pair( 11, 1 ) ] = 1024; cache[ make_pair( 11, 2 ) ] = 16429152; cache[ make_pair( 11, 3 ) ] = 23252832; cache[ make_pair( 11, 4 ) ] = 233792; cache[ make_pair( 2, 1 ) ] = 2; cache[ make_pair( 3, 1 ) ] = 4; cache[ make_pair( 3, 2 ) ] = 2; cache[ make_pair( 4, 1 ) ] = 8; cache[ make_pair( 4, 2 ) ] = 16; cache[ make_pair( 5, 1 ) ] = 16; cache[ make_pair( 5, 2 ) ] = 100; cache[ make_pair( 5, 3 ) ] = 4; cache[ make_pair( 6, 1 ) ] = 32; cache[ make_pair( 6, 2 ) ] = 616; cache[ make_pair( 6, 3 ) ] = 72; cache[ make_pair( 7, 1 ) ] = 64; cache[ make_pair( 7, 2 ) ] = 4024; cache[ make_pair( 7, 3 ) ] = 952; cache[ make_pair( 8, 1 ) ] = 128; cache[ make_pair( 8, 2 ) ] = 28512; cache[ make_pair( 8, 3 ) ] = 11680; cache[ make_pair( 9, 1 ) ] = 256; cache[ make_pair( 9, 2 ) ] = 219664; cache[ make_pair( 9, 3 ) ] = 142800; cache[ make_pair( 9, 4 ) ] = 160; }; int main() { fill_cache(); int N; int K; int long long prime; cin >> N; cin >> K; cin >> prime; long long res = cache[ make_pair( N, K ) ]; res %= prime; cout << res << "\n"; }
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 | #include <map> #include <utility> #include <iostream> using namespace std; map< pair< int, int >, long long > cache; void fill_cache() { cache[ make_pair( 1, 0 ) ] = 1; cache[ make_pair( 10, 1 ) ] = 512; cache[ make_pair( 10, 2 ) ] = 1831712; cache[ make_pair( 10, 3 ) ] = 1788896; cache[ make_pair( 10, 4 ) ] = 7680; cache[ make_pair( 11, 1 ) ] = 1024; cache[ make_pair( 11, 2 ) ] = 16429152; cache[ make_pair( 11, 3 ) ] = 23252832; cache[ make_pair( 11, 4 ) ] = 233792; cache[ make_pair( 2, 1 ) ] = 2; cache[ make_pair( 3, 1 ) ] = 4; cache[ make_pair( 3, 2 ) ] = 2; cache[ make_pair( 4, 1 ) ] = 8; cache[ make_pair( 4, 2 ) ] = 16; cache[ make_pair( 5, 1 ) ] = 16; cache[ make_pair( 5, 2 ) ] = 100; cache[ make_pair( 5, 3 ) ] = 4; cache[ make_pair( 6, 1 ) ] = 32; cache[ make_pair( 6, 2 ) ] = 616; cache[ make_pair( 6, 3 ) ] = 72; cache[ make_pair( 7, 1 ) ] = 64; cache[ make_pair( 7, 2 ) ] = 4024; cache[ make_pair( 7, 3 ) ] = 952; cache[ make_pair( 8, 1 ) ] = 128; cache[ make_pair( 8, 2 ) ] = 28512; cache[ make_pair( 8, 3 ) ] = 11680; cache[ make_pair( 9, 1 ) ] = 256; cache[ make_pair( 9, 2 ) ] = 219664; cache[ make_pair( 9, 3 ) ] = 142800; cache[ make_pair( 9, 4 ) ] = 160; }; int main() { fill_cache(); int N; int K; int long long prime; cin >> N; cin >> K; cin >> prime; long long res = cache[ make_pair( N, K ) ]; res %= prime; cout << res << "\n"; } |