fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define ll long long
  5. int a[] = {30,19,13,11};
  6. int b[15];
  7.  
  8. int dp[11][2][2][31][20][14][12];
  9. int mod = 1e9+7;
  10. int INF= 1e9+1;
  11.  
  12. ll get(int x1, int x2, int x3, int x4) {
  13. ll res = 1;
  14. while(x1-->0) {
  15. res *=2;
  16. if(res>INF) return res;
  17. }
  18. while(x2-->0) {
  19. res *=3;
  20. if(res>INF) return res;
  21. }
  22. while(x3-->0) {
  23. res *=5;
  24. if(res>INF) return res;
  25. }
  26. while(x4-->0) {
  27. res*=7;
  28. if(res>INF) return res;
  29. }
  30. return res;
  31. }
  32.  
  33. int go(int p, bool z, bool g, int a2, int a3, int a5,int a7) {
  34. if(p==-1) return z && (a2==0) && (a3==0) && (a5==0)&& (a7==0);
  35. int &res = dp[p][z][g][a2][a3][a5][a7];
  36. if(res>=0) return res;
  37. res = 0;
  38. if(!z) res = go(p-1,z,g || (0<b[p]),a2,a3,a5,a7);
  39. for(int i=1;i<=9; i++) {
  40. if(g ||(i<=b[p]))
  41. {
  42. int b2 = a2,b3=a3, b5=a5, b7=a7;
  43. if(i%8==0) b2-=3;
  44. else if(i%4==0) b2-=2;
  45. else if(i%2==0) b2--;
  46. if(i%9==0) b3-=2;
  47. else if(i%3==0) b3--;
  48. if(i%5==0) b5--;
  49. if(i%7==0) b7--;
  50. if(b2>=0 && b3>=0 && b5>=0 && b7>=0) {
  51. res+=go(p-1,1,g||(i<b[p]),b2,b3,b5,b7);
  52. }
  53.  
  54. }
  55. }
  56. return res;
  57. }
  58.  
  59. int main() {
  60. /* Enter your code here. Read input from STDIN. Print output to STDOUT */
  61. int t;
  62. cin>>t;
  63. while(t-->0) {
  64. memset(dp,-1,sizeof(dp));
  65. int ret =0;
  66. int n;
  67. cin>>n;
  68. for(int i=0; i<=11;i++) {
  69. b[i]= n%10;
  70. n/=10;
  71. }
  72. for(int i=0;i<=a[0]; i++) {
  73. for(int j=0;j<=a[1]; j++) {
  74. for(int k=0; k<=a[2];k++) {
  75. for(int l=0;l<=a[3]; l++){
  76. ll res = get(i,j,k,l);
  77. if(res>=INF)continue;
  78. int cur = res;
  79. int ans = go(10,0,0,i,j,k,l);
  80. int phi = cur, div = 1;
  81. for(int m=2;m*m<=cur; m++) {
  82. if(cur%m==0) {
  83. int tot = 0;
  84. while(cur%m==0) {
  85. cur/=m;
  86. tot++;
  87. }
  88. phi /=m;
  89. phi*=(m-1);
  90. div *= (tot+1);
  91. }
  92. }
  93. if(cur>1) {
  94. phi /=cur;
  95. phi *= (cur-1);
  96. div *= 2;
  97. }
  98. ret=(ret+((ans*1LL*phi)%mod)*1LL*div)%mod;
  99. }
  100. }
  101. }
  102. }
  103. cout<<ret<<endl;
  104. }
  105. return 0;
  106. }
Time limit exceeded #stdin #stdout 5s 33144KB
stdin
Standard input is empty
stdout
31617427
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0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