LCC '23 Contest 1 S3 - Oreos

View as PDF

Submit solution


Points: 7 (partial)
Time limit: 1.5s
Memory limit: 64M

Author:
Problem type

It's Halloween and Aaron wants to go trick-or-treating with Sharmin. Unfortuantely, Sharmin isn't going with him because he has decided not to eat candy for a year.

Aaron decides to go trick-or-treating alone, but not before gifting Sharmin a pack of N Oreos :). Instead of eating them though, Sharmin decides to split them evenly among his T friends (he decides not to eat any to keep the cut going). To spice things up, Sharmin decides that each oreo can either be counted as one component, or three components, by splitting the oreo into two cookies and the white creme. He wants to split all the Oreos amongst his friends. His friends will consider a split fair if each person receives the same number of Oreo components.

Given the above constraints, can you help Sharmin determine the number of fair splits he can create?

Clarification: A split is defined as the number of oreos that are split into two cookies and a creme

Subtasks

Subtask 1 [20%]

1 \le N, T \le 10^6

Subtask 2 [80%]

1 \le N, T \le 10^{12}

Input Specification

The first and only line will contain space-separated integers N and T.

Output Specification

Output the number of fair splits Sharmin can create.

Sample Input 1

4 3

Sample Output 1

2

Sample Explanation 1

It can be proven that he can make fair splits by splitting 1 Oreo, and splitting all the Oreos.

Sample Input 2

128348322 123438

Sample Output 2

2080

Comments

There are no comments at the moment.