-
Notifications
You must be signed in to change notification settings - Fork 0
/
legal numbers
46 lines (46 loc) · 918 Bytes
/
legal numbers
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
#include<stdio.h>
int dig(long long int);
int main()
{
long long int l,u,t,j,i,sum=0,k=0;
scanf("%lld",&t);
long long int arr2[t];
for(i=0;i<t;i++)
{
scanf("%lld %lld",&l,&u);
sum=0;
for(j=l;j<=u;j++)
{
k=0;
long long int temp=j;
while(j/1000>0 && temp>0)
{
int a,b;
a=(temp/10)%10;
b=temp%10;
if(a!=0 && b!=0 && a%2==b%2)
k++;
else if(k>2)
break;
else
k=0;
temp=temp/10;
}
if(k<=2)
sum+=dig(j);
}
arr2[i]=sum;
}
for(i=0;i<t;i++)
printf("%lld\n",arr2[i]);
}
int dig(long long int n)
{
int k=0;
while(n)
{
k+=(n%10);
n=n/10;
}
return k;
}