Main topic:
Number of beauties: This number divides the non-zero of his own individual bits.
Give you an interval to ask how many beautiful numbers there are.
Analysis: dp[number of digits [least common multiple on each single digit] [value after 2520] = number of conditions to satisfy
1. The number I get is least common multiple to the number of digits on all digits if the ==0 description is legal
2.1-9 of the least common multiple is 2520 so I get to the number first to 2520, and then the number of its various digits to take the remainder, the same can get the same result.
3. Because we want to open dp[20][2520][2520] array is to hyper-memory so we want to give him the last dimension of discretization, the final result is only 50 numbers.
#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<cmath>using namespaceStd;typedefLong LongLL;#defineMOD 2520LL dp[ -][mod][ the];intbit[ -], index[mod+Ten];voidinit () {intI, num =0; Memset (DP,-1,sizeof(DP)); for(i=1; i<=mod; i++) { if(mod%i = =0) Index[i]= num + +; }}intgcdintAintb) { returnb = =0? A:GCD (b, a%b);}intLcmintAintb) { returnA/GCD (A, b) *b;} LL DFS (intPosintPresum,intPRELCM,intflag) { if(pos = =-1) { returnPRESUM%PRELCM = =0; } if(!flag && DP[POS][PRESUM][INDEX[PRELCM]]! =-1) returnDP[POS][PRESUM][INDEX[PRELCM]]; LL ans=0; intEnd = Flag?bit[pos]:9; for(intI=0; i<=end; i++) { intNowsum = (presum*Ten+ i)%MOD; intNOWLCM =PRELCM; if(i) NOWLCM =LCM (NOWLCM, i); Ans+ = DFS (pos-1, Nowsum, NOWLCM, flag && i = =end); } if(!flag) DP[POS][PRESUM][INDEX[PRELCM]]=ans; returnans;} ll solve (ll N) {intLen =0; while(n) {Bit[len+ +] = n%Ten; N/=Ten; } returnDFS (len-1,0,1,1);}intMain () {intT; LL A, B; Init (); scanf ("%d",&t); while(t--) {scanf ("%lld%lld", &a, &b); printf ("%lld\n", solve (b)-Solve (A-1) ); } return 0;}
Digital DP (codeforces 55DBeautiful numbers)