Codeforces Round #808 (Div. 2) 1708B. Difference of GCDs Solution



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

Solution in C++:

  1. /// La ilaha illellahu muhammadur rasulullah
  2. ///******Bismillahir-Rahmanir-Rahim******///
  3. /// Abul Hasnat Tonmoy
  4. /// Department of CSE,23rd batch
  5. /// Islamic University,Bangladesh
  6. ///**********ALLAH IS ALMIGHTY************///
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long int
  4. int main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int n, l, r, i, t, j, f;
  8. cin >> t;
  9. while (t--) {
  10. cin >> n >> l >> r;
  11. std::vector<int> v;
  12. int a,index;
  13. for( int i = 1 ; i <= n ; i++)
  14. {
  15. index=i;
  16. if(l%index==0)v.push_back(l);
  17. else
  18. {
  19. a=l/index +1;
  20. a=a*index;
  21. if(a<=r)v.push_back(a);
  22. }
  23. }
  24. if(v.size()==n)
  25. {
  26. cout<<"YES"<<endl;
  27. for(auto i:v)cout<<i<<" ";
  28. }
  29. else
  30. cout<<"NO";
  31.  
  32. cout<<endl;
  33. }
  34. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.