当前位置:网站首页>B. Difference of GCDs
B. Difference of GCDs
2022-07-25 03:09:00 【Leng Chi】
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, What we know is that we need to find a number (k For a random variable )k*i(i>=1&&i<=n) stay [l,r] Between ,
Then there is k>=l/i If l%i==0, Then we will a[i]==k=l/i.
If l%i!=0, Then we have to think about it , or l>i or l<i, All in all l/i Is a decimal , But we use int type , All it will be forcibly rounded , in other words (int)l/i<(float)l/i, We put k=int(l/i)+1 That's it ,a[i]==k=l/i+1;
if(a[i]>r) It means in [l,r] There is no number that satisfies the meaning of the question , We output NO, Otherwise output YES.
The above sentence means that we are [l,r] Find the smallest i Multiple k)
( for instance l=4,i=4, that k=1,k*i=4;
l=4,i=2, that k=2,k*i=4;
l=5,i=2, that k=3,k*i=6;
l=5,i=4, that k=2,k*i=8;)
The code is as follows :
#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) /* If the minimum multiples exceed r Words , There is no solution */
{
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;
}边栏推荐
- JS construct binary tree
- 2022-07-19: all factors of F (I): I are added up after each factor is squared. For example, f (10) = 1 square + 2 square + 5 square + 10 square = 1 + 4 + 25 + 100 = 130.
- Use of stm32cubemonitor Part II - historical data storage and network access
- Bubble sort / heap sort
- JS foundation -- data
- How to take the mold for the picture of 1.54 inch TFT st7789 LCD screen
- Three ways to solve your performance management problems
- Dynamic planning of force buckle punch in summary
- Vscode copy synchronization plug-in expansion
- Unity refers to a variable in another class (its own instance)
猜你喜欢

Arduino + si5351 square wave generator

Riotboard development board series notes (VII) -- the use of framebuffer

JS written test question -- promise, setTimeout, task queue comprehensive question

Resolve the error: org.apache.ibatis.binding.bindingexception

Win10 -- open the hosts file as an administrator

Decoding webp static pictures using libwebp

From input URL to page presentation

Learning notes - talking about the data structure and algorithm of MySQL index and the introduction of index

Mark down learning

Use reflection to convert RDD to dataframe
随机推荐
Publish the project online and don't want to open a port
JS construction linked list
05 - MVVM model
JS foundation -- JSON
Dynamic planning of force buckle punch in summary
JS method encapsulation summary
A queue of two stacks
JS foundation -- task queue and event loop
mysql_ User table_ Field meaning
Banana pie bpi-m5 toss record (2) -- compile u-boot
ES6 - study notes
Riotboard development board series notes (VIII) -- building desktop system
Daily three questions 7.19
Handwriting promise
kettle_ Configure database connection_ report errors
Swiper4 is used to smooth longitudinal seamless scrolling. After clicking or dragging the mouse, the animation is not completely completed, the mouse moves out of the automatic rotation, and the dynam
The dolphin scheduler calls the shell script and passes multiple parameters
Keras load history H5 format model error: attributeerror 'STR' object has no attribute 'decode‘
hello csdn
Go multiplexing