Sphere Online Judge

Computer geeks! Show off your skills and claim the job of your dreams! RecruitCoders.com

SPOJ Problem Set (classical)

10738. Ra-One Numbers

Problem code: RAONE

In the War between good and evil . Ra-One is on the evil side and G-One on the good side.

Ra-One is fond of destroying cities and its G-one's duty to protect them..

 

Ra-One loves to destroy cities whose Zip Code has special properties. He says he loves to destroy cities which have Ra-One numbers as their ZIp Code.

Any number is Ra-one if the Difference between Sum of digits at even location and Sum of digits at odd location is One (1).. For eg... for 234563 is Ra-One number

digits at odd location are 3,5,3 (unit place is location 1 )

digits at even location are 2,4,6

Diff = (2+4+6)-(3+5+3)=12-11 = 1.

And 123456 is not Ra-One number

diff = (5+3+1) - (2+4+6) = -4

 

G-One knows this about Ra-one and wants to deploy his Army members in those cities. 1 army member will be deployed in each city.

G-one knows the range of ZIP-Codes where Ra-One might attack & needs your help to find out how many army members he needs.

Can you help Him ?

Input

first line will have only one integer 't' number of Zip-Code ranges. it is followed by t lines

each line from 2nd line cotains 2 integer 'from'  and 'to'. these indicate the range of Zip codes where Ra-one might attack .(from and to are included in the range)

Output

A single number for each test case telling how many army members G-One needs to deploy.

each number should be on separate lines

Example

Input:
2
1 10
10 100


 Output:
1
9
explanation:
for 1st test case the only number is 10
for 2nd test case numbers are 10,21,32,43,54,65,76,87,98

NOTE:
t will be less than 100
from and to will be between 0 and 10^8 inclusive

Added by:Devil D
Date:2012-02-21
Time limit:1s
Source limit:30000B
Languages:All
Resource:Own

hide comments
2012-03-17 20:04:48 Kim Fts
I not understand.
In '100', '1' and '0' are even and '0' are odd. The difference are one. In my home.:)

---in 100
0-loctation 1
0-loctation 2
1-loctation 3

Odd 1 & 0

Last edit: 2012-03-28 05:45:34
2012-03-16 05:55:20 Adhityaa
1) Is 100 a RAONE number ? ((1+0)-(0)=1)
2) Should the difference be 1 or can it also be -1 ?

@Adhityaa - for 100 the diff value -> 0-(1+0) = -1 ...
so 100 is not RAONE number
The diff should be 1 and not -1

Last edit: 2012-03-05 06:57:10
2012-03-16 05:55:20 surya kiran
ahh atlast...@deepak sir thanks for response got my mistake

Last edit: 2012-03-03 10:19:04
2012-03-16 05:55:20 Pramod Ch
p.s. can you check my code and give the cases for wrong output???


@pramod ...
for 1 10000
answer is 660 .... u r getting 197

Last edit: 2012-02-29 15:27:39
2012-03-16 05:55:20 Pramod Ch
p.s ..please check my code why am i getting wrong answer ??



Last edit: 2012-02-29 07:19:07
2012-03-16 05:55:20 Devil D
@surya - Your output is wrong for more then 50% test cases.. Check for overflow conditions ...
2012-03-16 05:55:20 surya kiran
p.s please check my code i am getting WA..but for sample I/O its correct and some other cases also i tested

Last edit: 2012-02-24 15:53:07
2012-03-16 05:55:20 Devil D
@gaurav - Ur answer are correct only for examples..
for 100 110 the answer is 0
you are getting 1
@marcos - there are a small fault in test case .. changed and rejudged .. Your solution got AC

Last edit: 2012-02-22 11:47:24
2012-03-16 05:55:20 Marcos Kawakami
are there any tricky cases? I've been testing my solution with a bruteforce algorithm using random inputs and the outputs seem to be matching.

Last edit: 2012-02-21 20:25:27
2012-03-16 05:55:20 Gaurav
got my mistake...

Last edit: 2012-02-22 10:10:29
SPOJ System © 2012 Sphere Research Labs | Projekty informatyczne i aplikacje na zamówienie. All Rights Reserved.