# Digital DP (codeforces 55DBeautiful numbers)

Source: Internet
Author: User

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)

Related Keywords:

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.