CF2233F.Shortest GCD Paths
省选/NOI-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
You are given three integers n, a, b. Consider a weighted undirected graph with n vertices, where for every pair of distinct vertices (u,v) there is an edge with weight:
w(u,v)=fracmax(u,v)gcd(u,v)
Here gcd(x,y) denotes the greatest common divisor (GCD) of integers x and y.
Find the shortest path from vertex a to vertex b in this graph.
给你三个整数 n、a、b。考虑一个含 n 个顶点的带权无向图,其中对任意一对不同的顶点 (u,v),均存在一条边,其权重为:
w(u,v)=gcd(u,v)max(u,v)
这里 gcd(x,y) 表示整数 x 和 y 的最大公约数(GCD)。
求该图中从顶点 a 到顶点 b 的最短路径。
输入格式
The only line contains three integers n, a, b (2≤n≤109,1≤a,b≤n,a=b).
唯一一行包含三个整数 n、a、b(2≤n≤109,1≤a,b≤n,a=b)。
输出格式
Print one integer — the length of the shortest path from vertex a to vertex b.
输出一个整数——从顶点 a 到顶点 b 的最短路径的长度。
输入输出样例
输入#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→8 with total cost w(9,6)+w(6,8)=3+4=7.
考虑第一个例子。
其中最短路径为 9→6→8,总代价为 w(9,6)+w(6,8)=3+4=7。
输入解题思路,AI测评打分。不知道怎么写?