VDATE - Flirtatious Verma
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 . 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, 0 ≤ Y ≤ 1000000000)
For each test case, print a single integer denoting the count of possible number of girls.
If X = 14 and Y = 2 then the possible number of girls are 3, 4, 6 and 12.
When will there be infinite possibilities?
Excellent problem! The core bit of the algorithm is something I was reluctant to implement properly for too long, and skipped many similar problems where I knew it was required to pass - this one tricked me to finally do it right =) A lot can go wrong though! Feels great to get AC with Python here.
Last edit: 2017-08-13 20:38:43
who can tell me the O(n) of the probem?
Any tricky test cases? Can't understand why I keep getting WA :(
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?
@visleck Consider x = 21, y = 5. Answer should be 2.Last edit: 2017-07-15 16:04:42
@divyanshjr i believe i am doing it correctly.... can u give a sample case where i am going wrong??
@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
@DJ please fix the following issues with this problem:-