FR | EN
Quentin L. Meunier
Associate Professor in Computer Science at Sorbonne Université

Problem 1013

That particular calculator has a "star" key, the * key, which performs a secret operation. This operation has the following properties for all natural numbers a and b:
Sometimes the result coincides with multiplication. Thus, 271 * 287 = 271 × 287 (= 77 777) and 2,018 * 39 = 2,018 × 39. Only write numbers that answer the question with certainty. If there are several, write them in ascending order on line 3, from the smallest to the largest. If there is none, write NO in box 3A.



For this problem, the written program implements the result values of the operation in a two-dimensional array (corresponding to both operands). It starts by initializing the known array values and then iteratively explores the values that can be derived from the rules. For effective exploration, it uses a list for new values to explore (which works well here because a new result is derived from a single previous result). An arbitrary choice has to be made here concerning the limit value of the operands: even for high values, the time remains reasonable (it takes about ten seconds to go up to 30,000), but the memory consumption becomes relatively important (3.5 GB for 30,000 for example).

The code is available here.



  • 1A. The smallest integer d answering the question is 315.
  • 2A. The only integer e greater than 2,017 such as 2,017 * e = 2,017 × 40 is 3,190.
  • 3A. The only integer f which one is certain that it verifies f * 2,017 = 40 × 2,017 is 3,996.