Meaning of the questions:
You n, k. It is shown in [1, n] within this range, to find out all within the interval x satisfies x% k == 0, then let x all bits are added together (i.e., x% 10), output.
For example: Input 102
The number is then meet 246810
Then 2% 4% 10 + 10 + 10 + 8% 6% 10% 10 = 10 + 20
Then output 20
answer:
Satisfying x% k == x 0, it is certainly a factor of k and the product of y, i.e., 1 * k, 2 * k, 3 * k, 4 * k ....... (y <= n / k)
We find the same bits 11 * k bits and the number of 1 * k, i.e., (11 * k)% 10 == (1 * k)% 10
Well certainly there are (21 * k)% 10 == (1 * k)% 10 ...............
Therefore, we only need to find out all (i * k)% 10 (1 <= i <= 9) and then added together
Then look at the y is the number, get what you can, look at the specific code!
Code:
1 #include<stdio.h> 2 #include<string.h> 3 #include<iostream> 4 #include<algorithm> 5 using namespace std; 6 const int maxn=15; 7 typedef long long ll; 8 ll v[maxn],sum[maxn]; 9 int main() 10 { 11 ll t; 12 cin>>t; 13 while(t--) 14 { 15 ll n,m; 16 cin>>n>>m; 17 18 for(ll i=1;i<=9;++i) 19 v[i]=(i*m)%10,sum[i]=sum[i-1]+v[i]; 20 if(n<m) 21 { 22 printf("0\n"); 23 continue; 24 } 25 n/=m; 26 m%=10; 27 ll summ=0,ans; 28 ans=n/10; 29 ll q=n%10; 30 //printf("%d %lld %d\n",n,ans,q); 31 summ=ans*sum[9]; 32 summ+=sum[q]; 33 printf("%I64d\n",summ); 34 } 35 return 0; 36 }