【CF#808(Div.2)- B】构造数学题

该博客讨论了如何在给定的整数范围L到R中构造一个长度为N的序列,使得序列中每个元素与其下标之间的最大公约数互不相同。博主提出了解题思路,即利用下标是元素倍数的特性,确保每个gcd(i, ai)都是唯一的。代码实现中,通过检查每个i能否找到满足条件的ai,最终输出符合条件的序列或表明无解。

https://codeforces.com/contest/1708/problem/B

B. Difference of GCDs

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given three integers n, l, and r. You need to construct an array a1,a2,…,an(l≤ai≤r) such that gcd(i,ai) are all distinct or report there's no solution.

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

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤10^4) — the number of test cases. The description of the test cases follows.

The first line contains three integers n, l, r (1≤n≤10^5, 1≤l≤r≤10^9).

It is guaranteed that the sum of nn over all test cases does not exceed 105.

Output

For each test case, if there is no solution, print "NO" (without quotes). You can print letters in any case (upper or lower).

Otherwise, print "YES" (without quotes). In the next line, print n integers a1,a2,…,an — the array you construct.

If there are multiple solutions, you may output any.

Example

input

4
5 1 5
9 1000 2000
10 30 35
1 1000000000 1000000000

output

YES
1 2 3 4 5
YES
1145 1926 1440 1220 1230 1350 1001 1000 1233
NO
YES
1000000000

Note

In the first test case, gcd(1,a1),gcd(2,a2),…,gcd(5,a5)are equal to 1, 2, 3, 4, 5, respectively.


题目大意:在给定的L - R区间内找出一个长度为N并满足其中元素与下标的最大公约数各不相同(gcd(i,ai)!= gcd(k,ak))的序列(ai || ak)

解题思路:没有说一个值只能用一次,并且已知下标是1-N所以ai的值一定是下标的倍数,只要能整除就是符合条件的。

code:

#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize(3)
#define ll long long
#define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define endl '\n'
#define inf  0x3f3f3f3f
#define llinf  0x3f3f3f3f3f3f3f3f
#define upfor(i, st, ed)  for(int i = st; i <= ed; ++i)
#define dnfor(i, st, ed)  for(int i = st; i >= ed; --i)
#define upfor_(i, st, ed)  for(int i = st; i < ed; ++i)
#define dnfor_(i, st, ed)  for(int i = st; i < ed; --i)
#define map unordered_map
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ppb pop_back 
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vc = vector<char>;
using vstr = vector<string>;

//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////

int main(){
	ios;
	int T , n , r , l , flat = 1 ;
	cin >> T;
	while(T--){
		flat = 1;
		cin >> n >> l >> r;
		upfor(i , 1 , n){
			if(l % i != 0 && (l - l % i + i) > r){
                //l - l % i保证其能被整除 ,并且 l % i 是小于 i 的,所以再加上一个 i
                //一定大于l 
                //如果存在一个i不能被整除就一定不满足条件标记并跳出循环
				flat = 0;
				break;
			}
		}
		if(!flat)cout << "NO" << endl;
		else {
            如果所有的i都符合条件就按要求输出
			cout << "YES" << endl;
			upfor(i , 1 , n){
				if(l % i == 0)cout << l << ' ';
				else cout << l - l % i + i << ' '; 
			}
			cout << endl;
		}
	}
	return 0;
}

蒟蒻新人,有问题请指出ww

### 各命令作用及使用场景 #### `pactl set-default-sink alsa_output.usb-CF-IC_DOV_2025-0711-1800-00.analog-stereo` - **作用**:此命令将指定的音频输出设备 `alsa_output.usb-CF-IC_DOV_2025-0711-1800-00.analog-stereo` 设置为系统的默认音频输出设备。当应用程序播放音频时,若无特殊指定,音频将通过该设备输出。 - **使用场景**:当连接了多个音频输出设备,如同时连接了 USB 音箱和蓝牙耳机,而希望将 USB 音箱作为默认输出设备时,可使用该命令。 #### `pactl set-default-source alsa_input.usb-CF-IC_DOV_2025-0711-1800-00.analog-stereo` - **作用**:该命令把指定的音频输入设备 `alsa_input.usb-CF-IC_DOV_2025-0711-1800-00.analog-stereo` 设置为系统的默认音频输入设备。当应用程序进行音频录制时,若无特殊指定,将从该设备获取音频输入。 - **使用场景**:在连接了多个音频输入设备,如同时有内置麦克风和 USB 麦克风,而希望使用 USB 麦克风作为默认输入设备时,可使用此命令。 #### `pactl set-sink-volume @DEFAULT_SINK@ 100%` - **作用**:将当前系统默认的音频输出设备的音量设置为 100%。 - **使用场景**:当发现音频输出音量过小,需要将默认输出设备音量调至最大时使用。 #### `pactl set-source-volume @DEFAULT_SOURCE@ 100%` - **作用**:把当前系统默认的音频输入设备的音量设置为 100%。 - **使用场景**:当音频录制声音过小,需要将默认输入设备音量调至最大时使用。 ### 可能出现的问及解决办法 #### 设备名称错误 - **问表现**:执行命令时,提示找不到指定的设备。 - **解决办法**:使用 `pactl list sinks` 和 `pactl list sources` 命令查看系统中可用的音频输出和输入设备的名称,确保命令中使用的设备名称正确。 #### 权限问 - **问表现**:执行命令时,提示没有足够的权限。 - **解决办法**:确保以具有足够权限的用户身份执行命令,通常可以使用 `sudo` 来提升权限,但这可能需要输入管理员密码。 #### 音量设置无效 - **问表现**:执行音量设置命令后,音量没有变化。 - **解决办法**:检查设备本身是否有独立的音量控制开关或旋钮,确保其处于合适的位置。也可以尝试重新启动 PulseAudio 服务,使用命令 `pulseaudio -k` 停止服务,然后 `pulseaudio --start` 重新启动服务。 ```bash # 查看可用的音频输出设备 pactl list sinks # 查看可用的音频输入设备 pactl list sources # 停止 PulseAudio 服务 pulseaudio -k # 重新启动 PulseAudio 服务 pulseaudio --start ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值