HDU 4507 series of stories-Hate 7 no wife

Source: Internet
Author: User

You need to push down the sum of squares. Maintenance number, and, squared sum.

#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#defineMoD 1000000007LLusing namespacestd;Long Longbit[ -],tab[ -],ret=0, T,l,r;structpnt{Long LongVal1,val2,val3; PNT (Long LongVal1,Long LongVal2,Long Longval3): Val1 (Val1), Val2 (Val2), Val3 (VAL3) {} PNT () {}}dp[ -][ -][ -];voidGet_bit (Long Longx) {ret=0;  while(x) {bit[++ret]=x%Ten; x/=Ten;}}voidget_table () {tab[0]=1;  for(Long LongI=1; i<= +; i++) tab[i]=tab[i-1]*Ten%MoD;  for(Long LongI=0; i<= +; i++)         for(Long Longj=0; j<=9; j + +)             for(Long Longk=0; k<=9; k++) {Dp[i][j][k].val1=dp[i][j][k].val2=dp[i][j][k].val3=-1; }    return;} PNT Comb (pnt x,pnt y,Long LongPosLong Longnum) {    Long Longr1=0, r2=0, r3=0; R1= ((y.val3*tab[2* (pos-1)]%mod*num%mod*num%mod+ (2* (y.val2*tab[pos-1]%mod)%mod*num) (%mod)%mod+y.val1)%MoD; R2= (y.val3*num%mod*tab[pos-1]%MOD+Y.VAL2)%MoD; R3=Y.val3; X.val1= (X.VAL1+R1)%MoD; X.val2= (X.VAL2+R2)%MoD; X.val3= (X.VAL3+R3)%MoD; returnx;} PNT DFS (Long LongPosLong LongVal1,Long LongVal2,BOOLflag) {    if(!POS) {        if(Val1 && Val2)returnPnt0,0,1); Else returnPnt0,0,0); }    if((!flag) && (~DP[POS][VAL1][VAL2].VAL1))returnDp[pos][val1][val2]; PNT ans=PNT (0,0,0);Long LongUp=flag?bit[pos]:9;  for(Long LongI=0; i<=up;i++)    {        if(i==7)Continue; Ans=comb (Ans,dfs (pos-1, (val1*Ten+i)%7, (val2+i)%7, flag&&i==up), pos,i); }    if(!flag) dp[pos][val1][val2]=ans; returnans;}Long LongWorkLong Longx)    {get_bit (x); returnDFS (ret,0,0,1). Val1;}intMain () {scanf ("%i64d",&t); get_table ();  for(Long LongI=1; i<=t;i++) {scanf ("%i64d%i64d",&l,&R); printf ("%i64d\n", (Work (R)-work (l1) +mod)%MoD); }        return 0;}

HDU 4507 series of stories-Hate 7 no wife

Contact Us

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.