Codeforces Round 895 (Div. 3) 1872C. Non-coprime Split Solution

  


Problem Link: https://codeforces.com/problemset/problem/1872/C

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t;
  8. cin >> t;
  9. while (t--) {
  10. bool ok = false ;
  11. int l , r ; cin >> l >> r ;
  12. for (int i = r ; i >= l ; i--){
  13. if(i % 2 == 0 and ( i - 2) != 0){
  14. cout << i - 2 <<" "<< 2 <<'\n';
  15. ok = true ;
  16. break ;
  17. }
  18. }
  19. if(ok == false){
  20. for( int i = 3 ; i * i <= l ; i++ ){
  21. if( l % i == 0 and (l - i ) != 0){
  22. ok = true ;
  23. cout << l - i <<" "<<i<<'\n';
  24. break ;
  25. }
  26. }
  27. if(ok == false){
  28. cout <<"-1\n";
  29. }
  30. }
  31. }
  32. return 0 ;
  33. }

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.