1708B - Difference of GCDs - CodeForces Solution


constructive algorithms math *1100

Please click on ads to support us..

Python Code:

import math
for i in range(int(input())):
    n,l,r = map(int,input().split())
    li = []
    if n==1:
        print('YES')
        print(r)
    else:
        for i in range(1,n+1):
            li.append(math.ceil(l/i)*i)
        if max(li)>r:
            print('NO')
        else:
            print('YES')
            print(*li)

C++ Code:

#include <bits/stdc++.h>
using namespace std;





/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compile and get accepted.
 *      ____________
 *     /            \
 *    /  /\      /\  \
 *   /  /  \    /  \  \
 *   \                /
 *    \     \___/    /
 *     \____________/
 */






#define f(i,j,k) for(long long i=j;i<k;i++)
#define cond(a) if(a)cout<<"YES"<<endl;else cout<<"NO"<<endl
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define test int t;cin>>t;while(t--)
#define endl "\n"
#define pb push_back
#define mp make_pair
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;

ll gcd(ll a, ll b) {
    return b ? gcd(b, a % b) : a;
}
ll lcm(ll a, ll b)
{
  return (a*b)/gcd(a,b);
}
ll PRO(ll a,ll b,ll MOD)
{
  return ((a%MOD)*(b%MOD)%MOD);
}
ll power(ll x, ll y, ll M)
{
  if (y == 0)
    return 1;
  ll p = power(x, y / 2, M) % M;
  p = (p * p) % M;
  return (y % 2 == 0) ? p : (x * p) % M;
}
ll modInverse(ll A, ll M)
{
  ll g = gcd(A, M);
  if (g != 1)
    return -1;
  else {
    return power(A, M - 2, M);
  }
}
bool isprime(ll n)
{

  for(ll i=2;i*i<=n;i++)
  {
    if(n%i==0)return false;
  }
  return true;
}


ll fact(ll n,ll m)
{
  if(n==0)
    return 1;
  ll res = 1;
  for (ll i=2;i<=n;i++){
    res=1ll * res*i;
    res%=m;
  }
  return res;
}
ll C(ll n, ll r)
{
  ll z=1;
  f(i,0,r)
  {
    z=z*(n-i)/(i+1);
  }
  return z;
}
const int N=500500;
bool prime[N + 1];
void SieveOfEratosthenes(int n)
{
  memset(prime, true, sizeof(prime));
    for (int p=2;p*p<=n;p++){
      if (prime[p] == true) {
        for (int i = p * p; i <= n; i += p)
          prime[i] = false;
      }
    }
}

int lowbit(int x)
{
  return x&(-x);
}









void solve()
{
  int n;
  cin>>n;
  ll l,r;
  cin>>l>>r;
  vector<ll>v;
  f(i,1,n+1)
  {
    ll k=i*((l-1)/i+1);
    if(k>r)
    {
      no;
      return;
    }
    v.pb(k);
  }
  yes;
  f(i,0,n)cout<<v[i]<<" ";
  cout<<endl;
}

int main()
{
  test
  {
    solve();
  }
  return 0;
}




























Comments

Submit
0 Comments
More Questions

162. Find Peak Element
1529A - Eshag Loves Big Arrays
19. Remove Nth Node From End of List
925. Long Pressed Name
1051. Height Checker
695. Max Area of Island
402. Remove K Digits
97. Interleaving String
543. Diameter of Binary Tree
124. Binary Tree Maximum Path Sum
1465. Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts
501A - Contest
160A- Twins
752. Open the Lock
1535A - Fair Playoff
1538F - Interesting Function
1920. Build Array from Permutation
494. Target Sum
797. All Paths From Source to Target
1547B - Alphabetical Strings
1550A - Find The Array
118B - Present from Lena
27A - Next Test
785. Is Graph Bipartite
90. Subsets II
1560A - Dislike of Threes
36. Valid Sudoku
557. Reverse Words in a String III
566. Reshape the Matrix
167. Two Sum II - Input array is sorted