1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| #include<algorithm> #include<bitset> #include<complex> #include<deque> #include<exception> #include<fstream> #include<functional> #include<iomanip> #include<ios> #include<iosfwd> #include<iostream> #include<istream> #include<iterator> #include<limits> #include<list> #include<locale> #include<map> #include<memory> #include<new> #include<numeric> #include<ostream> #include<queue> #include<set> #include<sstream> #include<stack> #include<stdexcept> #include<streambuf> #include<string> #include<typeinfo> #include<utility> #include<valarray> #include<vector> #include<cctype> #include<cerrno> #include<cfloat> #include<ciso646> #include<climits> #include<clocale> #include<cmath> #include<csetjmp> #include<csignal> #include<cstdarg> #include<cstddef> #include<cstdio> #include<cstdlib> #include<cstring> #include<ctime> using namespace std;
#define re register #define int long long #define eps 1e-5 #define mod 1000000007
class Quick_Input_Output{ private: static const int S=1<<21; #define tc() (A==B&&(B=(A=Rd)+fread(Rd,1,S,stdin),A==B)?EOF:*A++) char Rd[S],*A,*B; #define pc putchar public: #undef gc #define gc getchar inline int read(){ int res=0,f=1;char ch=gc(); while(ch<'0'ch>'9'){if(ch=='-') f=-1;ch=gc();} while(ch>='0'&&ch<='9') res=res*10+ch-'0',ch=gc(); return res*f; } inline void write(int x){ if(x<0) pc('-'),x=-x; if(x<10) pc(x+'0'); else write(x/10),pc(x%10+'0'); } #undef gc #undef pc }I; #define File freopen("tmp.in","r",stdin);freopen("tmp.out","w",stdout);
int a[30],m,pw[30]; struct node{int ans,sum,sqrsum;}dp[30][10][10]; inline node DFS(int now,int presum,int prenum,int lim){ if(!now) return (node){presum!=0&&prenum!=0,0,0}; if(!lim&&~dp[now][presum][prenum].ans) return dp[now][presum][prenum]; re int Max=lim?a[now]:9;node ans=(node){0,0,0},bk; for(int i=0;i<=Max;i++){ if(i==7) continue ; bk=DFS(now-1,(presum+i)%7,(prenum*10+i)%7,lim&&i==Max); ans.ans+=bk.ans;ans.ans%=mod; ans.sum+=bk.sum;ans.sum%mod; ans.sum+=pw[now-1]*i%mod*bk.ans%mod;ans.sum%=mod; ans.sqrsum+=bk.sqrsum;ans.sqrsum%=mod; ans.sqrsum+=2*pw[now-1]%mod*i%mod*bk.sum%mod;ans.sqrsum%=mod; ans.sqrsum+=bk.ans*pw[now-1]%mod*pw[now-1]%mod*i%mod*i%mod;ans.sqrsum%=mod; } if(!lim) dp[now][presum][prenum]=ans; return ans; } inline int solve(int N){ re int x=N;m=0; while(x){ a[++m]=x%10; x/=10; } for(int i=1;i<=28;i++) for(int j=0;j<10;j++) for(int k=0;k<10;k++) dp[i][j][k]=(node){-1,0,0}; return DFS(m,0,0,1).sqrsum; } int T,L,R; signed main(){ pw[0]=1;for(int i=1;i<=28;i++) pw[i]=pw[i-1]*10,pw[i]%=mod; T=I.read(); while(T--){ L=I.read();R=I.read(); I.write((solve(R)-solve(L-1)+mod)%mod);putchar('\n'); } return 0; }
|