PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000369. Đường đi ngắn nhất trên đồ thị GCD ẩn (Shortest GCD Paths)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đường đi ngắn nhất trên đồ thị GCD ẩn (Shortest GCD Paths)
Shortest GCD Paths
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given integers , consider a complete undirected graph on vertices : every pair of distinct vertices is joined by an edge with weight
This is a positive integer. Find the minimum total edge weight of a path from vertex to vertex . Output the minimum cost only, not the path itself.
Important: can be as large as , so explicitly building this graph is impossible.
Input
A single line containing .
Output
Print one integer: the shortest-path distance from to .
Subtasks
- Subtask 1 (20 points): ; ; .
- Subtask 2 (30 points): ; ; .
- Subtask 3 (50 points): ; ; .
Examples
Example 1
Input
10 9 8
Output
7
Explanation
The direct edge costs . The path costs , which is optimal.
Example 2
Input
100 16 27
Output
10
Explanation
Path has edge costs , , and . The total is , the minimum possible.
Example 3
Input
100 55 11
Output
5
Explanation
The direct edge costs , which is optimal.