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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值