Test instructions
If a number can be divisible by the number of its own bits, then it is called Beautiful numbers.
The number of Beautiful numbers in the interval [a, b].
Analysis: First analysis, 2~9 the largest least common multiple is 2520 ({5,7,8,9}), first preprocess all possible least common multiple m[c]
DP[I][D][C] Indicates the number of length I, remainder d, least common multiple is m[c].
#include <cstdio>#include<cstring>#defineMoD 2520ll dp[ *][2520][ -];intbit[ -],m[ $],mnum;intgcdintAintb) { inttmp; while(a%b) {tmp=b; b=a%b; A=tmp; } returnb;}intLcmintAintb) { returna*b/gcd (A, b);}
Check the label of least common multipleintTfind (intx) { intLl=1, rr=Mnum; while(ll<=RR) { intMid= (LL+RR) >>1; if(m[mid]<x) ll=mid+1; Elserr=mid-1; } returnll;}voidinit () {memset (DP,-1,sizeof(DP)); Mnum=0; for(intI=1; i<=mod;++i)if(mod%i==0) m[++mnum]=i;} ll Dfs (intIintDintCinte) { if(i==0)returnD%M[C]?0:1; if(!e&&dp[i][d][c]!=-1)returnDp[i][d][c]; intL=e?bit[i]:9; ll Num=0; for(intj=0; j<=l;++j) {intTd= (d*Ten+J)%MoD; intTc=C; if(j) tc=Tfind (LCM (m[c],j)); Num+=dfs (I-1,td,tc,e&& (j==l)); } returne?num:dp[i][d][c]=num;} ll solve (ll x) {intlen=0; while(x) {bit[++len]=x%Ten; X/=Ten; } returnDFS (Len,0,1,1);}intMain () {intT; scanf ("%d",&t); Init (); ll x, y; while(t--) {scanf ("%i64d%i64d",&x,&y); printf ("%i64d\n", Solve (y)-solve (X-1)); }return 0;}
CF 55d-beautiful numbers (digital DP)