Codeforces Round 895 (Div. 3) 1872C. Non-coprime Split Solution
Problem Link: https://codeforces.com/problemset/problem/1872/C
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- bool ok = false ;
- int l , r ; cin >> l >> r ;
- for (int i = r ; i >= l ; i--){
- if(i % 2 == 0 and ( i - 2) != 0){
- cout << i - 2 <<" "<< 2 <<'\n';
- ok = true ;
- break ;
- }
- }
- if(ok == false){
- for( int i = 3 ; i * i <= l ; i++ ){
- if( l % i == 0 and (l - i ) != 0){
- ok = true ;
- cout << l - i <<" "<<i<<'\n';
- break ;
- }
- }
- if(ok == false){
- cout <<"-1\n";
- }
- }
- }
- return 0 ;
- }
No comments