Description Single!
Still single.
Brother Jill is still single.
DS-Class Code The brother is still single.
So, he hated Valentine's Day most of his life, whether it was 214 or 77, he hated it.
Jill observed 214 and 77 of these two numbers, found:
2+1+4=7
7+7=7*2
77=7*11
In the end, he found out that it was all about 7. So, he now even hates everything and 7 about the number.
What number is related to 7?
If an integer conforms to one of the 3 conditions below, then we say that this integer is related to 7--
1. One of the integers is 7;
2. Each of the integers adds up to an integer multiple of 7;
3. This integer is an integer multiple of 7;
Now the question is: Gill want to know the sum of squares of 7 unrelated numbers within a certain interval.
The first line of input data is the case number T (1 <= T <= 50), then the next T-line represents the T case, and each case contains two positive integer l, R (1 <= l <= R <= 10^18) on a row.
Output calculates the sum of squares of [l,r] and 7 unrelated numbers, and outputs the result to 10^9 + 7 after modulo.
Sample Input
3
1 9
17 17
Sample Output
236
221
0
Analysis: To find the sum of squares, to maintain three information, the number of each state, the number of each state and the sum of squares in each state, and then according to the square and the formula to mess up the line, feeling written very ugly.
#include <iostream> #include <string> #include <algorithm> #include <cstdlib> #include < cstdio> #include <set> #include <map> #include <vector> #include <ctime> #include <cstring > #include <stack> #include <cmath> #include <queue> #define INF 0x3f3f3f3f #define EPS 1e-9 #define MA
XN 100000 #define MOD 1000000007 using namespace std;
typedef long Long LL;
int T;
ll L,r,cs[20],a[22],dp[22][7][7][2],dpsum[22][7][7][2],dpsum2[22][7][7][2];
void Dfs (int pos,int sta1,int sta2,int limit) {if (pos = =-1) {Dpsum[pos+1][sta1][sta2][limit] = 0LL;
Dpsum2[pos+1][sta1][sta2][limit] = 0LL;
Dp[pos+1][sta1][sta2][limit] = sta1 && sta2;
Return
} if (Dp[pos+1][sta1][sta2][limit] >= 0) return; int up = limit?
A[pos]: 9;
ll ans = 0,ans1 = 0,ans2 = 0;
for (int i = 0;i <= up;i++) {if (i = = 7) continue;
DFS (Pos-1, (sta1 + i)% 7, (sta2*10 + i)% 7,limit && i = = up); ll num = dp[pos][(sta1 + i)% 7][(sta2*10 + i)% 7][limit && i = = up];
ll num2 = dpsum[pos][(sta1 + i)% 7][(sta2*10 + i)% 7][limit && i = = up];
ll num3 = dpsum2[pos][(sta1 + i)% 7][(sta2*10 + i)% 7][limit && i = = up];
Ans = (ans + num)% MOD;
Ans1 = (ans1 + ((cs[pos]*i)% MoD) *num + num2)% MoD;
Ans2 = (Ans2 + num* ((cs[pos]*i% MoD) * (cs[pos]*i% mod)% MoD)% mod + num3 + (cs[pos]*i% mod) *num2% mod)% MoD;
} Dp[pos+1][sta1][sta2][limit] = ans;
Dpsum[pos+1][sta1][sta2][limit] = ans1;
Dpsum2[pos+1][sta1][sta2][limit] = ans2;
Return
} ll solve (ll x) {if (x < 0) return 0;
int pos = 0;
while (x) {a[pos++] = x 10;
x/= 10;
} if (!pos) return 0LL;
Memset (Dp,-1,sizeof (DP));
DFS (pos-1,0,0,1);
return dpsum2[pos][0][0][1];
} int main () {cs[0] = 1LL;
for (int i = 1;i <= 19;i++) cs[i] = cs[i-1]*10% MOD;
scanf ("%d", &t);
while (t--) {scanf ("%lld%lld", &l,&r);
printf ("%lld\n", (Solve (R)-solve (L-1) + MoD)% mod); }
}