Relatively Prime Pairs

本文探讨了一种解决特定数学问题的算法,即在给定的一系列连续整数中找到所有可能的互质对,确保每对数字的最大公约数为1。通过巧妙地将数字配对,可以保证解决方案的存在性,而这种方法的简洁性和有效性令人惊叹。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Description:
You are given a set of all integers from ll to rr inclusive, l<rl<r, (r−l+1)≤3⋅105 and (r−l) is always odd.

You want to split these numbers into exactly (r−l+1)/2 pairs in such a way that for each pair (i,j) the greatest common divisor of i and j is equal to 1. Each number should appear in exactly one of the pairs.

Print the resulting pairs or output that no solution exists. If there are multiple solutions, print any of them.

Input
The only line contains two integers ll and rr (1≤l<r≤1018 , r−l+1≤3⋅105 , (r−l) is odd).

Output
If any solution exists, print “YES” in the first line. Each of the next (r−l+1)/2 lines should contain some pair of integers. GCD of numbers in each pair should be equal to 11. All (r−l+1) numbers should be pairwise distinct and should have values from l to r inclusive.
If there are multiple solutions, print any of them.
If there exists no solution, print “NO”.

Example
Input
1 8
Output
YES
2 7
4 1
3 8
6 5

只要想到一种可以输出互质对的方法就行,答案一定是YES的,相邻数输出就行。太神奇了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值