CF2233F.Shortest GCD Paths

省选/NOI-

通过率:0%

时间限制:2.00s

内存限制:512MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given three integers nn, aa, bb. Consider a weighted undirected graph with nn vertices, where for every pair of distinct vertices (u,v)(u, v) there is an edge with weight:

w(u,v)=fracmax(u,v)gcd(u,v)w(u, v) = \\frac{\\max(u, v)}{\\gcd(u, v)}

Here gcd⁡(x,y)\gcd(x, y) denotes the greatest common divisor (GCD) of integers xx and yy.

Find the shortest path from vertex aa to vertex bb in this graph.

给你三个整数 nn、aa、bb。考虑一个含 nn 个顶点的带权无向图,其中对任意一对不同的顶点 (u,v)(u, v),均存在一条边,其权重为:

w(u,v)=max⁡(u,v)gcd⁡(u,v)w(u, v) = \frac{\max(u, v)}{\gcd(u, v)}

这里 gcd⁡(x,y)\gcd(x, y) 表示整数 xx 和 yy 的最大公约数(GCD)。

求该图中从顶点 aa 到顶点 bb 的最短路径。

输入格式

The only line contains three integers nn, aa, bb (2≤n≤109,1≤a,b≤n,a≠b2 \le n \le 10^{9}, 1 \le a, b \le n, a \neq b).

唯一一行包含三个整数 nn、aa、bb(2≤n≤1092 \le n \le 10^{9},1≤a,b≤n1 \le a, b \le n,a≠ba \neq b)。

输出格式

Print one integer — the length of the shortest path from vertex aa to vertex bb.

输出一个整数——从顶点 aa 到顶点 bb 的最短路径的长度。

输入输出样例

  • 输入#1

    10 9 8

    输出#1

    7
  • 输入#2

    100 16 27

    输出#2

    10
  • 输入#3

    100 55 11

    输出#3

    5

说明/提示

Consider the first example.

The shortest path in it is 9→6→89 \to 6 \to 8 with total cost w(9,6)+w(6,8)=3+4=7w(9, 6) + w(6, 8) = 3 + 4 = 7.

考虑第一个例子。

其中最短路径为 9→6→89 \to 6 \to 8,总代价为 w(9,6)+w(6,8)=3+4=7w(9, 6) + w(6, 8) = 3 + 4 = 7。

输入解题思路,AI测评打分。不知道怎么写?

首页