$ Cometoj \ # 4 \ D \ $ sum than $ dp $

\ (A \)

\(Sol\)

\ (upd: \) the following two paragraphs are wrong approach, but I do not want to delete \ (JPG \.)
----------------------- Here is the error section------------------------------

See Q \ (\ sum_ {nl} ^ rf (n) \) will think of digital \ (dp \) A pair, so try digit \ (dp \) , however, and will not do, but feel that we can first try to think of violence the method (of course violence excellent point)?

For a number (ABCD \) \ , changes as follows: \ ((A + B) (B + C) (C + D) \) , \ ((A + 2B + C) (B + 2C + D) \) , \ ((A + 3B +. 3C + D) \) , noted that in fact there is no intermediate process take \ (\% \) had no effect, and thus add to finally take \ (\% \) is the same the see here I thought of triangle. can be drawn here, for a number \ (the X-\) , we can \ (log_ {10} x \ ) come in time \ (f (x) \ ) . then you can play violent.

----------------------- ----------------------- The following is the correct part -------

Easy to find, if the last digit of a change \ (1 \) , then the \ (f \) value will change \ (1 \) . And because (f \) \ value can only take \ (0 \) to \ (1 \) . so for ten consecutive numbers, their \ (F \) values is \ (\ sum_ {i = 0 } ^ 9i = 45. \) thus calculated to \ (\ sum_ {i = 1} ^ {l} f ( i) \) should simpler, the first \ (+ AS * = 45 (L / 10) \) , then calculate the number of the remaining individual back like (as long as the calculated remaining violence the first number under the like, the other can be introduced). the final answer is \ (Sol (r) -sol (L-1) \) .

In summary, this problem does not seem to use digital \ (dp \) , and the data range was so large, in fact, may have some guess to a certain number of laws can be bundled together to calculate the value of these numbers bundled together and there will be some law.(Suddenly remembered the subject last semester done a trigonometric function, but also three consecutive considered together, then this value is circulating up)To find this law must go to analyze this \ (f (n) \) character / specificity.

\(over.\)

\(Code\)

Morning mind confused, \ (Wa \) a \ (Inf \) times, waking up after noon reconstructed again, although still not first pass through the sample, but then calmly checked the wrong, so too after sample again \ (a \) a.

Code

#include<bits/stdc++.h>
#define il inline
#define Ri register int
#define go(i,a,b) for(Ri i=a;i<=b;++i)
#define yes(i,a,b) for(Ri i=a;i>=b;--i)
#define e(i,u) for(Ri i=b[u];i;i=a[i].nt)
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define db double
#define inf 2147483647
using namespace std;
il ll read()
{
    ll x=0,y=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    return x*y;
}
int a[20];
il ll calc(ll x)
{
    Ri ct=0;
    mem(a,0);
    while(x){a[++ct]=x%10,x/=10;}
    while(ct>1)
    {
    go(i,1,ct-1)a[i]=(a[i]+a[i+1])%10;
    --ct;while(!a[ct] && ct>0)--ct;
    }
    return a[1];
}
il ll sol(ll x)
{
    ll ret=(x+1)/10*45,ct=(x+1)%10;
    ll qvq=calc(x-ct+1);
    while(ct--)
    {
    ret+=qvq;
    qvq=(qvq+1)%10;
    }
    return ret;
}
int main()
{
    int T=(int)read();
    while(T--)
    {
    ll l=read(),r=read();
    //printf("sol(%lld)=%lld sol(%lld)=%lld\n",l-1,sol(l-1),r,sol(r));
    printf("%lld\n",sol(r)-sol(l-1));
    }
    return 0;
}

Guess you like

Origin www.cnblogs.com/forward777/p/11592718.html