Codeforces Round #708 (Div. 2) C1
C1. k-LCM (easy version)
It is the easy version of the problem. The only difference is that in this version k=3.
You are given a positive integer n. Find k positive integers a1,a2,…,ak, such that:
a1+a2+…+ak=n
LCM(a1,a2,…,ak)≤n2
Here LCM is the least common multiple of numbers a1,a2,…,ak.
We can show that for given constraints the answer always exists.
Input
The first line contains a single integer t (1≤t≤104) — the number of test cases.
The only line of each test case contains two integers n, k (3≤n≤109, k=3).
Output
For each test case print k positive integers a1,a2,…,ak, for which all conditions are satisfied.
Example
input
3
3 3
8 3
14 3
output
1 1 1
4 2 2
2 6 6
linkC1
分析:
一个数可分为 i ,n-i ,其中 (n - i) 又可分为 (n - i)/2 ,(n - i)/2;
则后两个数的lcm 一定满足条件 ;
1
当一个数为奇数时,则 分别为 1 , (n - 1 ) / 2 , (n - 1 ) / 2;
最小公倍数为 (n - 1) / 2 ,满足 lcm <= n / 2;
2
①当一个数为偶数时,若 偶数为 2的x次方 ,则 结果为 n / 2 , n / 4 , n / 4
②若 偶数 为 2的x次方 * 奇数 的形式,这里的奇数 >= 3, 则2 的x次方 < n / 2; 则 令i = 2的x次方,
(n - i ) / 2 则为 2 的x次方 * (奇数倍 - 1)/ 2 的 状态 , 一定小于 2 的 n次方 * 奇数倍 / 2 ,此时 的lcm 为 (n - i) / 2;
#include <iostream>
using namespace std;
int main()
{
int t ;
cin >> t;
while(t --)
{
int n,k;
cin >> n >> k;
int i = 1,j = n;
while(j % 2 == 0)
{
i *= 2;
j /= 2;
}
if(j == 1)
{
i /= 2;
}
cout << i << ' ' << (n - i) / 2 << ' ' << (n - i)/2 ;
cout << endl;
}
return 0;
}