#P15435. [蓝桥杯 2025 国 Python B] 免费披萨

    ID: 17455 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度普及− 上传者: 标签>搜索2025枚举蓝桥杯国赛

[蓝桥杯 2025 国 Python B] 免费披萨

Background

Python contestants may try submitting this problem using PyPy3.

Problem Description

The owner of the pizza shop in Lanqiao Town has just baked the nn-th pizza of his life! To celebrate this important moment, he launched an event called “Lucky Order”, where customers have a chance to win a free pizza. The rules are as follows:

  1. Generate the order number: Each customer needs to generate a nine-digit order number. The method is: first, take the digits 11 to 88 and arrange them in any order (each digit appears exactly once) to form an eight-digit number. Then, insert one digit from 11 to 88 into any position of this eight-digit number (it can be at the beginning, the end, or in the middle), thus obtaining a nine-digit order number.
  2. Compute the greatest common divisor to win a free pizza: The owner will compute the greatest common divisor (GCD) of each customer’s order number and nn. If an order number has the largest GCD with nn, then that customer has a chance to win a free pizza. Note: the order number must strictly satisfy the generation rules above. If multiple order numbers have the same GCD with nn and this value is the maximum, then only the customer whose order number is the smallest in value wins.

Now, Xiaolan also wants to join this event and hopes to win a free pizza. Please help Xiaolan find the order number that allows him to win the free pizza.

Input Format

One line contains an eight-digit positive integer nn, representing the nn-th pizza baked by the owner.

Output Format

Output one line containing a nine-digit positive integer, the answer, i.e., the smallest order number with which Xiaolan can win the free pizza.

12345678
415637826

Hint

Constraints

For all testdata, 107n<10810^7 \le n < 10^8.

Translated by ChatGPT 5