Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. using namespace std;
  2.  
  3. #include <algorithm>
  4. #include <cctype>
  5. #include <cmath>
  6. #include <cstdio>
  7. #include <cstdlib>
  8. #include <cstring>
  9. #include <iostream>
  10. #include <map>
  11. #include <queue>
  12. #include <set>
  13. #include <sstream>
  14. #include <stack>
  15. #include <string>
  16. #include <vector>
  17.  
  18. #define EPS 1e-11
  19. #define inf ( 1LL << 31 ) - 1
  20. #define LL long long
  21.  
  22. #define _rep( i, a, b, x ) for( __typeof(b) i = ( a ); i <= ( b ); i += x )
  23. #define rep( i, n ) _rep( i, 0, n - 1, 1 )
  24. #define rrep( i, a, b ) for( __typeof(b) i = ( a ); i >= ( b ); --i )
  25. #define xrep( i, a, b ) _rep( i, a, b, 1 )
  26.  
  27. #define abs(x) (((x)< 0) ? (-(x)) : (x))
  28. #define all(x) (x).begin(), (x).end()
  29. #define ms(x, a) memset((x), (a), sizeof(x))
  30. #define mp make_pair
  31. #define pb push_back
  32. #define sz(k) (int)(k).size()
  33.  
  34. typedef vector <int> vi;
  35. const LL MOD = 1000007;
  36.  
  37. int n;
  38.  
  39. LL memo[50][70][70][70];
  40. int tcase[50][70][70][70];
  41. int ncase;
  42.  
  43. int LCM[70][70];
  44.  
  45. LL solve(int pos, int nmod, int lcm, int clcm)
  46. {
  47.     if (pos == n) return (nmod == 0 && lcm == clcm);
  48.     LL &ret = memo[pos][nmod][lcm][clcm];
  49.     if (tcase[pos][nmod][lcm][clcm] == ncase) return ret;
  50.     tcase[pos][nmod][lcm][clcm] = ncase;
  51.     ret = 0;
  52.     xrep(i,1,6) if (lcm % i == 0)
  53.     {
  54.         ret += solve(pos + 1, (nmod * 10 + i) % lcm, lcm, LCM[clcm][i]);
  55.         ret %= MOD;
  56.     }
  57.     return ret;
  58. }
  59.  
  60. int main()
  61. {
  62.     #ifdef Local
  63.         freopen("/home/wasi/Desktop/input.txt", "r", stdin);
  64.     #endif
  65.     xrep(i,1,65) xrep(j,1,65) LCM[i][j] = (i*j) / (__gcd(i, j));
  66.     vi dig, lcms;
  67.     set<int> L;
  68.     xrep(i,1,6) dig.pb(i);
  69.     rep(i,(1<<6))
  70.     {
  71.         int l = 1;
  72.         rep(j,6) if (i & (1<<j))
  73.             l = LCM[l][dig[j]];
  74.         L.insert(l);
  75.     }
  76.     lcms = vi(all(L));
  77.  
  78.  
  79.  
  80.     int tc;
  81.     scanf("%d", &tc);
  82.  
  83.     while (tc--)
  84.     {
  85.         ncase++;
  86.         scanf("%d", &n);
  87.         LL ans = 0;
  88.         rep(i,sz(lcms))
  89.         {
  90.             ans += solve(0, 0, lcms[i], 1);
  91.             ans %= MOD;
  92.         }
  93.         printf("%lld\n", ans);
  94.     }
  95.  
  96.  
  97.     return 0;
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement