time limit per test 1 second
memory limit per tes t256 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)gcd(i,ai) are all distinct or report there's no solution.
Here gcd(x,y)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 t (1≤t≤10^4) — the number of test cases. The description of the test cases follows.
The first line contains three integers nn, ll, rr (1≤n≤10^5, 1≤l≤r≤10^9).
It is guaranteed that the sum of nn over all test cases does not exceed 105105.
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.
OK,我们知道的是我们需要找到一个数(k为一个随机变量)k*i(i>=1&&i<=n)在[l,r]之间,
那么便有k>=l/i如果l%i==0,那么我们就把a[i]==k=l/i。
如果l%i!=0,那么我们就要想一想了,要么l>i要么l<i,总之l/i为小数,但是我们用的是int类型,所有它会被强行取整,也就是说(int)l/i<(float)l/i,我们把k=int(l/i)+1就行了,a[i]==k=l/i+1;
if(a[i]>r)就表示在[l,r]不存在一个数满足题意,我们输出NO,否则输出YES。
上面这句话的意思是我们在[l,r]之间找到一个最小的i的倍数k)
(比如说l=4,i=4,那么k=1,k*i=4;
l=4,i=2,那么k=2,k*i=4;
l=5,i=2,那么k=3,k*i=6;
l=5,i=4,那么k=2,k*i=8;)
代码如下:
#include <iostream>
using namespace std;
int n,l,r;
int main()
{
int t;
cin>>t;
while (t>0)
{
cin>>n>>l>>r;
bool falg=true;
int data1[100001];
for(int i=1;i<=n;i++)
{
if(l%i==0)
{
data1[i]=l;
}
else
{
if(((l/i)+1)*i>r) /*如果最小的倍数都超过r的话,就不存在解了*/
{
falg=false;
break;
}
else
{
data1[i]=((l/i)+1)*i;
}
}
}
if(falg==true)
{
cout<<"YES"<<endl;
for(int i=1;i<=n;i++)
{
cout<<data1[i]<<" ";
}
cout<<endl;
}
else
{
cout<<"NO"<<endl;
}
t--;
}
return 0;
}