-
Notifications
You must be signed in to change notification settings - Fork 0
/
kfunc.c
47 lines (40 loc) · 870 Bytes
/
kfunc.c
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
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[15],i,test,count;
long long int l,r,a1,d,sum,p,x,sum1;
scanf("%d",&test);
while(test--)
{
scanf("%lld%lld%lld%lld",&a1,&d,&l,&r);
sum=a1;
sum1=0;
for(i=0;i<9;i++)
{
arr[i]=(sum-1)%9;
arr[i]++;
sum=sum+d;
sum1=sum1+arr[i];
}
x=r-l+1;
sum=0;
p=(l-1)%9;
if(p)
{
for(i=p,count=0;count<x;i++,count++)
{
if(i==9)
break;
sum=sum+arr[i];
}
x=x-count;
}
sum=sum+sum1*(x/9);
x=x%9;
for(i=0,count=0;count<x;count++,i++)
sum=sum+arr[i];
printf("%lld\n",sum);
}
return 0;
}