Links: http://acm.hdu.edu.cn/showproblem.php?pid=4507
Story-Hate 7 no wife Time limit:1000/500 MS (java/others) Memory limit:65535/32768 K (java/others)
Total submission (s): 2306 Accepted Submission (s): 675
Problem 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 10 11 17 17
Sample Output
236 221 0
Practice:
DP[I][J][K]
Represents the square sum of the number of digits before the POS bit and the decimal number before%7 ==j before the pos bit,%7 = = k.
Open a struct, which indicates that the answer to this DP state exists in Fang, and then how many exist in GE, the sum of these sums.
Then the formula is pushed down and shifted down.
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <limits.h> #include < malloc.h> #include <ctype.h> #include <math.h> #include <string> #include <iostream> #
Include <algorithm> using namespace std; #include <stack> #include <queue> #include <vector> #include <deque> #include <set> #
Include <map> typedef __int64 LL;
struct Point {ll ge;
ll sum;
ll Fang;
};
const int maxn=22;
int DIG[MAXN];
ll SHI[MAXN];
Point F[maxn][7][7];
ll mod=1000000007;
Point DFS (int pos,int wei,int all,int limit) {//0 compliant, but sum=0 insignificant, a-ans;
ans.ge=0;
ans.sum=0;
ans.fang=0;
if (pos<0) {if (wei!=0&&all!=0) ans.ge=1;
return ans;
} if (!limit&&f[pos][wei][all].ge!=-1) return F[pos][wei][all];
int last=limit?dig[pos]:9;
for (int i=0;i<=last;i++) {if (i==7) continue; Point Tem=dfs (Pos-1, (Wei+i)%7, ((all*10) +i)%7,limit&& (i==last));
if (tem.ge) {ans.ge= (ans.ge+tem.ge)%mod;
ll zhe= (shi[pos]*i)%mod;
Ans.sum= (ans.sum+zhe*tem.ge+tem.sum)%mod;
Ans.fang= (ans.fang+tem.fang+ ((Zhe*zhe)%mod*tem.ge)%mod+ (tem.sum*zhe*2)%mod)%mod;
}} if (!limit) f[pos][wei][all]/* [TODO] */=ans;
return ans;
} ll solve (ll n) {int len=0;
while (n) {dig[len++]=n%10;
n/=10;
} return Dfs (len-1,0,0/* TODO */,1). Fang;
} int main () {point tem;
Tem.ge=-1;
for (int i=0;i<=20;i++) for (int. j=0;j<7;j++) for (int k=0;k<7;k++) F[i][j][k]=tem;
Shi[0]=1;
for (int i=1;i<=19;i++) {shi[i]= (shi[i-1]*10)%mod;
} int n;
int t;
ll A, B;
scanf ("%d", &t);
while (t--) {scanf ("%i64d%i64d", &a,&b);
printf ("%i64d\n", (Solve (b)-solve (A-1) +mod)%mod);
} return 0;
}