#P9416. [POI 2021/2022 R1] Domino

[POI 2021/2022 R1] Domino

Background

Translated from XXIX Olimpiada Informatyczna – Stage I Domino

Problem Description

There is a 22-row, nn-column rectangle, where some cells are blocked. You need to use 1×21\times 2 or 2×12\times 1 dominoes to cover all unblocked cells, and no cell may be covered twice. Let the number of ways be mm.

Given mm, find the smallest nn such that there exists a way to choose the blocked cells so that the number of tilings is exactly mm. If there is no solution, output NIE.

Input Format

One line with a positive integer mm

Output Format

If there is a solution, output your answer nn

If there is no solution, output NIE

4

5

101

NIE

9

7

11

NIE

500

20

112233445566778899

NIE

Hint

For all testdata, 1m10181\leq m\leq 10^{18}

Constraints

Subtask ID Additional Constraints Score
1 Answer 12\leq 12 20
2 m2000000m\leq 2000000 30
3 50

Translated by ChatGPT 5