#P4028. New Product

    ID: 2958 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数学洛谷原创O2优化枚举,暴力哈希,HASH

New Product

Description

LiM owns a handmade pastry shop. Because the pastries are both affordable and delicious, the shop has accumulated PP regular customers (PP is prime).

Every time the shop launches a New Product, they make many items. All PP customers will support it in this way:

  • Each customer buys the same quantity.
  • They buy as much as possible.

The shop has BB workers. At the end of each minute, the total number of products becomes AA times the current total.

(Note: initially, there is one already-made New Product as a sample.)

After production is finished and the PP regular customers rush to buy (only these regular customers are considered):

  • To take care of the workers, exactly BB items must remain.

Given the known conditions, please help LiM compute the minimal working time.

Input Format

There are T+1T+1 lines.

The first line contains an integer TT, the number of New Products.

Lines 22 to T+1T+1 each contain three integers PP, AA, BB, as described above.

Output Format

For each New Product:

  • If it is achievable, output the minimal number of minutes worked.
  • If it is not achievable, output Couldn't Produce!.
1
5 2 3
3
1
2 2 2
Couldn't Produce!

Hint

Sample 1 explanation: There are 55 regular customers, the total multiplies by 22 each minute, and there are 33 workers. The minimum is 33 minutes (produce 23=82^3 = 8 items) to meet the requirement.

Sample 2 explanation: There are 22 regular customers, the total multiplies by 22 each minute, and there are 22 workers. Since no matter how long they work the leftover will always be 00, output Couldn't Produce!.

Notes:

  • LiM is not a worker.
  • For each New Product, the number of regular customers may differ.

Constraints:

  • For 20%20\% of the testdata, T=1T = 1 and all values 100\leqslant 100.
  • For 100%100\% of the testdata, T5000T \leqslant 5000, all values 5×104\leqslant 5 \times 10^4, and PP is prime.

Translated by ChatGPT 5