JENGA Editorial


Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4

Setter: Tejas Pandey
Testers: Felipe Mota, Abhinav sharma
Editorialist: Pratiyush Mishra






Chef hosts a party for his birthday. There are N people at the party. All these N people decide to play Jenga.

There are X Jenga tiles available. In one round, all the players pick 1 tile each and place it in the tower.

The game is valid if:

  • All the players have a tile in each round;

  • All the tiles are used at the end.

Given N and X, find whether the game is valid.


Let us assume it is a valid game that continues for M rounds then the number of tiles used will be N \times M as in each round a person will use 1 tile each. As we have to use all the tiles so we will get N \times M = X. We get the number of rounds by M = \frac{X}{N}.
Now we know for the game to be valid it should end after an integer number of rounds and its is only an integer if the number of tiles X is divisible by the number of players N. So, if it is divisible, then print YES otherwise print NO.


O(1) for each test case.


Editorialist’s Solution
Setter’s Solution
Tester 1’s Solution
Tester 2’s Solution