Codeforces Round 895 (Div. 3) C. Non-coprime Split
找到数字
x
x
x的因子
k
k
k,构造出
k
,
x
−
k
k,x-k
k,x−k即可。 因为
x
=
C
1
∗
k
x = C_1 * k
x=C1∗k ,
x
−
k
=
(
C
1
−
1
)
∗
k
x - k = (C_1 - 1) * k
x−k=(C1−1)∗k,保证其最小公因数不为
1
1
1
如果没有因子,即这个数字是质数,其不满足条件,证明如下: 假设
A
,
B
A,B
A,B存在满足如下条件
1.
A
+
B
=
x
1. A + B = x
1.A+B=x
2.
G
C
D
(
A
,
B
)
=
k
(
k
>
1
)
2. GCD(A, B) = k (k >1)
2.GCD(A,B)=k(k>1) 那么一定有
A
=
C
1
∗
k
,
B
=
C
2
∗
k
A = C_1 * k,B=C_2*k
A=C1∗k,B=C2∗k
A
+
B
=
k
(
C
1
+
C
2
)
=
x
A+B = k(C_1 + C_2) = x
A+B=k(C1+C2)=x 由反证法得到,这种情况存在时,x不是质数。
#includeusingnamespace std;intgcd(int a,int b){return b ?gcd(b, a % b): a;}voidsolve(){int a, b;
cin >> a >> b;int i = b;while(i > a){if(i %2==0)break;
i--;}if(i ==2)
cout <<-1<<"\n";else{for(int j =2; j * j <= i; j++){if(i % j ==0){
cout << j <<" "<< i - j <<"\n";return;}}
cout <<-1<<"\n";}}intmain(){
ios::sync_with_stdio(false);
cin.tie(0);int t;
cin >> t;while(t--){solve();}}