ODDEVENDIV - Editorial

PROBLEM LINK:

Practice
Contest: Division 1
Contest: Division 2
Contest: Division 3
Contest: Division 4

Author: raysh07
Tester: sushil2006
Editorialist: iceknight1093

DIFFICULTY:

Simple

PREREQUISITES:

None

PROBLEM:

Given A and B, does there exist some integer with A odd divisors and B even divisors?

EXPLANATION:

Every number has at least one odd divisor (that being 1), so if A = 0 we can immediately say that no solution exists.

What about even divisors?
It’s definitely possible for a number to not have any even divisors: specifically, note that odd numbers don’t have any even divisors.

So, suppose we have B = 0, i.e. we want no even divisors.
Our aim is to then find an odd number that has exactly A divisors.

This is always possible: for example, consider N = 3^{A-1}.
The divisors of 3^{A-1} are exactly 1, 3, 9, \ldots, 3^{A-1}, or 3^0, 3^1, 3^2, \ldots, 3^{A-1}.
There are of course A such divisors, and they’re all odd so we have what we want.
(Note that 3 isn’t special here - any p^{A-1} where p is an odd prime will work).


Next, we need to solve for B \gt 0, i.e. find a number which does have some even divisors.
Such an N must be even, obviously.

From the solution to the B = 0 case, we can see that powers of elements are important - so let’s look at the powers of 2 present in N.
That is, suppose we have N = 2^k \cdot M, where k \gt 0 and M is odd.

Now, observe that if d is any odd divisor of N, it will give rise to the even divisors 2d, 4d, 8d, \ldots, 2^k\cdot d.
That is, for each odd divisor of N, we obtain exactly k even divisors of N.

This means the number of even divisors of N must be exactly k times the number of odd divisors!
In other words, if B is not a multiple of A, then no solution can exist.

When B is a multiple of A, a valid N always exists: by combining the two ideas above, we can choose N = 2^k\cdot 3^{A-1}, where k = \frac{B}{A}.
This has A odd factors (that being 3^0, 3^1, \ldots, 3^{A-1}), and each odd factor gives us \frac{B}{A} even factors so there are B even factors in total, as we wanted!

So, quite simply, the answer is "Yes" if A\gt 0 and B is a multiple of A, and "No" otherwise.

TIME COMPLEXITY:

\mathcal{O}(1) per testcase.

CODE:

Editorialist's code (PyPy3)
for _ in range(int(input())):
    a, b = map(int, input().split())
    print('Yes' if a > 0 and b%a == 0 else 'No')

Can someone pls clarify the logic of how to deduce from multiple examples that b must be divisible by a. I read the editorial twice and tried with examples which proof it but how come like reach this conclusion, I am confused at this point?

1 Like

How can this question be of 1100 rating i have been giving contest since 3 years i believe its not rated correctly

4 Likes

I agree, defo didn’t deserve the 1100 rating .

I am assuming you want to know how can one reach to relation stated above.

How I did it was, to verify if any two values of odd and even no. of divisors are possible, I’ll need a relation between these two, on satisfying which I can say that there exists a number with these no. of odd and even divisors.

In general when I need to count the no. of divisors of a number I can break it down as N = a^x * b^y … * c^z, where a,b,c are prime numbers.
no. of divisors of N = (x+1)*(y+1)…*(z+1) [for a prime number it can have exponent from 0 to x, so total x+1 contributions and then taking the combination of each of those.]

Using this I tried to calculate no. of even and odd divisors of a number.
Suppose x = 2^t * a, where a is what is left when you remove all factors of 2 from x, so a is odd. The intuition to consider 2 separately was that an even divisor needs to have 2 as factor of it.

no. of odd divisors of x = no. divisors of a, as they won’t have 2 as a factor.
no. of even divisors of x = t * (no. of divisors of a) , we are not taking t+1 as to exclude the case where t==0 and the divisor becomes odd.

From which came:

  1. “no. of even divisors” must be a divisor of “no. of odd divisors”.
  2. no. of even divisors can be 0 (when t=0)
  3. no. of odd divisors cannot be 0, as any no. will have 1 as a divisor and so will “a”.

Hope this helped!

1 Like

Thanks @sharique_1, it was a amazing and clear explanation😺

The logic that some number can be represented as 2^t \times a actually helped me figure it out! Did not quite analyze the fact deeply about separate even and odd.

So basically all odds come together as a product to form a.

And all powers of 2 with combinations of odd with them form an even factor.

45 has factors = 1,3,5,9,15,45  (odd = 6, even = 0) <-- odd number has always only odd factors

36 has factors = 1,2,3,4,6,12,18, 36 (odd = 2, even = 6 i.e. odd < even) <-- even number can have mix of odd and even factors 
(at least one odd factor 1 always)

30 has factors = 1,2,3,5,6,10,15,30 (odd = 4, even = 4 i.e. odd == even)

No example can be found such that odd > even except when even  = 0.