Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.04 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ios ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL)
  3. #define pb push_back
  4. #define mp make_pair
  5. #define fi first
  6. #define se second
  7. #define enter cout << '\n'
  8.  
  9. using namespace std;
  10.  
  11. typedef long long ll;
  12. typedef pair <int, int> pii;
  13. typedef pair <ll, ll> pll;
  14. typedef vector <int> vi;
  15. typedef vector <pii> vii;
  16. typedef vector <ll> vl;
  17. typedef vector <pll> vll;
  18. typedef queue <int> qi;
  19. typedef queue <pii> qii;
  20. typedef queue <ll> ql;
  21. typedef queue <pll> qll;
  22.  
  23. const int INF = 0x3f3f3f3f;
  24. const int MOD = 1e9 + 9;
  25. const double EPSILON = 1e-10;
  26. const int NMAX = 1e4 + 5;
  27.  
  28. int prime[143] = {101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233,
  29. 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389,
  30. 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563,
  31. 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727,
  32. 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907,
  33. 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997};
  34. map <int, bool> isprime;
  35. int n, cnt, cntb;
  36. ll dp[NMAX][10];
  37.  
  38. ll mem(int root, int poz)
  39. {
  40. if (poz == n)
  41. {
  42. return 1;
  43. }
  44.  
  45. if (dp[root][poz])
  46. {
  47. return dp[root][poz];
  48. }
  49.  
  50. for (int i = 0; i < 10; ++i)
  51. if (root / 10 % 10 && isprime[(root % 100) * 10 + i])
  52. dp[root][poz] = (1LL * dp[root][poz] + 1LL * mem((root % 100) * 10 + i, poz + 1)) % MOD;
  53. while (dp[root][poz] < 0) dp[root][poz] += MOD;
  54.  
  55. return dp[root][poz];
  56. }
  57. /*
  58. void brute(int root, int poz)
  59. {
  60. if (poz == n)
  61. {
  62. cntb = (cntb + 1) % MOD;
  63. return;
  64. }
  65.  
  66. for (int i = 0; i < 10; ++i)
  67. if (root / 10 % 10 && isprime[(root % 100) * 10 + i])
  68. brute((root % 100) * 10 + i, poz + 1);
  69. }
  70. */
  71. int main()
  72. {
  73. for (int i = 0; i < 143; ++i)
  74. isprime[prime[i]] = true;
  75.  
  76. for (int i = 3; i < 10000; ++i)
  77. {
  78. n = i;
  79. cnt = cntb = 0;
  80. // memset(dp, 0, sizeof(dp));
  81. for (int i = 0; i < 143; ++i)
  82. {
  83. memset(dp, 0, sizeof(dp));
  84. cnt += mem(prime[i], 3);
  85. // while (cnt < 0) cnt += MOD;
  86. }
  87. // for (int i = 0; i < 143; ++i)
  88. // brute(prime[i], 3);
  89.  
  90. // if (cnt != cntb)
  91. // {
  92. cout << i << " " << cnt << "\n";
  93. // break;
  94. //}
  95. //else cout << "DA! " << i << endl;
  96. }
  97. /*
  98. cin >> n;
  99. for (int i = 0; i < 143; ++i)
  100. {
  101. memset(dp, 0, sizeof(dp));
  102. cnt += mem(prime[i], 3);
  103. }
  104. while (cnt < 0) cnt += MOD;
  105. cout << cnt;
  106. */
  107. return 0;
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement