fork download
  1. // ROOT : DRAGON3012009 : WA in Real Life
  2. #include <bits/stdc++.h>
  3. #define FOR(i,l,r) for(int i = l ; i <= r ; i ++)
  4. #define FORD(i,r,l) for(int i = r ; i >= l ; i --)
  5. #define REP(i, a ) for(int i = 0 ; i < a ; i ++ )
  6. #define compare(v) sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end());
  7. #define ll long long
  8. #define el "\n"
  9. #define fi first
  10. #define se second
  11. #define _ROOT_ int main()
  12. #define M 1000000007
  13. #define MAXN 1000001
  14. #define INF (1ll<<30)
  15. #define NAME "file"
  16. using namespace std;
  17.  
  18. ll n, m , q ;
  19. string s;
  20. ll dp[16][16 * 9 ][16 * 9 ][20] ;
  21.  
  22. bool snt(ll a ){
  23. if(a <= 1) return false ;
  24. if(a == 2 ) return true ;
  25. for(ll i = 2 ; i * i <= a ; i ++ ) if(a % i == 0 ) return false ;
  26. return true ;
  27. }
  28.  
  29. ll DP(ll pos , ll tcs_a ,ll tcs_b , ll nho , string & so ) {
  30. ll &cur = dp[pos][tcs_a][tcs_b][nho] ;
  31. if(pos == 0 ) {
  32. if(snt(tcs_a) && snt(tcs_b) && nho == 0 ) return cur = 1 ;
  33. else return cur = 0 ;
  34. }
  35. if(cur != -1 ) return cur ;
  36. cur = 0 ;
  37. FOR(x , 0 , 9 ) FOR(y , 0 , 9 ) {
  38. ll so_hien_tai = (x + 2*y + nho ) % 10 ;
  39. ll nxt_nho = (x + 2 * y + nho ) / 10 ;
  40. if(so_hien_tai == so[pos] -'0' ) {
  41. cur += DP(pos - 1 , tcs_a + x , tcs_b + y , nxt_nho , so ) ;
  42. }
  43. }
  44. return cur ;
  45. }
  46.  
  47. void init() {
  48. cin >> s ;
  49. n = s.size() ;
  50. s = " " + s ;
  51. }
  52.  
  53. void solve() {
  54. memset(dp , -1 , sizeof dp ) ;
  55. cout << DP(n , 0 , 0 , 0 , s ) << el ;
  56. }
  57.  
  58. _ROOT_ {
  59. // freopen(NAME".inp" , "r" , stdin);
  60. // freopen(NAME".out" , "w", stdout) ;
  61. ios_base::sync_with_stdio(0);
  62. cin.tie(0);
  63. cout.tie(0);
  64. int t = 1; // cin >> t ;
  65. while(t--) {
  66. init();
  67. solve();
  68. }
  69. return (0&0);
  70. }
  71.  
Success #stdin #stdout 0.02s 55404KB
stdin
Standard input is empty
stdout
0