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 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

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

Powered by Blogger.