VDATE - Flirtatious Verma

no tags 

Harsh Verma is a college guy who likes to date a lot of girls. He has got great flirting skills and he managed to convince a lot of girls to go out with him. He knows X dating locations in his city. He wanted to date all the girls so he started assigning each of them some dating locations. He treated all girls equal so he gave each of them equal number of dating locations. He wanted to spend maximum possible time with each girl so he tried to maximise the number of dating locations given to each girl. Also, no two girls got the same dating location.

After the distribution, he was left with Y dating locations. But unfortunately, he was too excited and he forgot to count the number of girls he had already assigned the dating locations Tongue out . This was a difficult situation for him but Aditya (Sciencepal) came to his rescue. He gave him a list of possible number of girls to him which would help him to figure out the actual number of girls. Your task is to write a program to find the total count of possible number of girls i.e. the number of entries in the list prepared by Sciencepal. 

If there are infinite possiblities, print -1. If there is no solution, print 0.


First line will contain an integer T i.e. the number of test cases. (1  T  50)

Next T lines will contain two integers X and Y(0  X  1000000000,  Y  1000000000)


For each test case, print a single integer denoting the count of possible number of girls.



14 2



If X = 14 and Y = 2 then the possible number of girls are 3, 4, 6 and 12. 

hide comments
anurag garg: 2017-07-23 14:07:31

Last edit: 2017-08-13 20:38:43
arthur1991: 2017-07-21 03:10:03

who can tell me the O(n) of the probem?

Vladimir: 2017-07-18 05:25:44

Any tricky test cases? Can't understand why I keep getting WA :(

dhana_25796: 2017-07-16 07:29:35

For the given sample test case why can't the no of girls be 1 or 2? ie the possible count can be 1,2,3,4,6,12?

divyanshjr: 2017-07-15 16:02:55

@visleck Consider x = 21, y = 5. Answer should be 2.

Last edit: 2017-07-15 16:04:42
visleck: 2017-07-14 21:17:12

@divyanshjr i believe i am doing it correctly.... can u give a sample case where i am going wrong??
(edit) Thank you very much divyansh

Last edit: 2017-07-22 21:55:56
divyanshjr: 2017-07-13 17:01:58

@aman224 For x < y, it will be an invalid case with no solution, so expected answer is 0 as mentioned in the problem statement. NZEC problem for JAVA has been fixed.

Last edit: 2017-07-13 19:37:39
aman224: 2017-07-13 16:17:29

@DJ please fix the following issues with this problem:-
1. Exactly same code passes in C, gets an RTE in JAVA :/ , maybe there is something wrong with the input files.
2. According to the problem statement ("After the distribution, he was left with Y dating locations") , Y should always be <=X as pointed by shubham2305 :p.

visleck: 2017-07-12 22:10:29

Last edit: 2017-07-12 22:12:10
Vipul Srivastava: 2017-07-12 22:03:40

Please remove the comments, they are giving away the logic

Added by:DJ
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Resource:College contest