Under construction

Still being built. Things may change

Broken Communication Towers

Interview

Time limit1sMemory limit512 MB

Summary
Given two tower identifiers a and b, find the minimum-cost divisor-relation path between them, breaking ties by the smallest sum of identifiers on the path.
Level

Medium5 of 10

Topics
Shortest path, Graph, Number theory
Solved
No attempts yet

x

In 2050, countless communication towers stand on the Pusan National University campus. Originally, any two different towers could communicate one to one. On a day of heavy rain, students who disliked the towers secretly smashed the integer processing part of every tower with a hammer. Repairing the towers would take 1000 years, so for now the broken towers will be used. The broken towers have the following properties.

  • Each tower has a natural number identifier starting from 1, and the list is unbounded. The identifier of tower ii is ii.
  • For towers aa and bb, direct communication is possible if the pair (a,b)(a, b) is a divisor relation. A divisor relation means that when the larger number of the pair is divided by the smaller, the remainder is 0.
  • The direct communication cost between tower 1 and a tower with an even identifier is 2. The direct communication cost of every other communication is 1.
  • If tower aa can communicate with tower cc, and tower cc can communicate with tower bb, then towers aa and bb can communicate through tower cc. The communication cost is the sum of the costs of each direct communication.

Sanjini, the president of Pusan National University, wants to reduce communication costs. Sanjini decides to write a program that finds the communication path with the minimum cost between any towers aa and bb. To simplify the management of communication logs, Sanjini also wants the path with the smallest sum of tower identifiers on the path when several paths have the minimum cost. The member of the algorithm club PULSE was threatened with dissolution if the program was not finished within 3 hours, and the work was handed to the club. Under the input constraints, the communication path that satisfies the path selection conditions is unique for any valid input.

Examples1

  1. Example 1

    Input
    1
    6 8
    
    Expected output
    6 2 8