k-LCM (easy version) CodeForces - 1497C1(思维+构造/n分奇偶)

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

题意:简单版本k=3。给你一个正整数n,找出3个正整数满足:

1、a1+a2+a3=n;

2、LCM(a1,a2,…,ak)≤n/2,即a1、a2、a3的最小公倍数<=n/2;

题解:1、当n为奇数的时候可以分成:1、n/2、n/2;

2、n为偶数,可以把a1=2或2的倍数,a2=(n-a1)/2,a3=a2,接下来只需要判断LCM(a1,a2)<=n/2即可,符合就输出。

g=__gcd(i,h);//注意不能交c++!!!

AC代码:

#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	ll t,n,k;
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld%lld",&n,&k);
		if(n%2!=0)
			printf("1 %lld %lld\n",n/2,n/2);
		else
		{
			ll i,h,g,u;
			for(i=2;; i=i*2)
			{
				h=n-i;
				h=h/2;
				g=__gcd(i,h);//注意不能交c++
				u=(h*i)/g;
				if(u<=n/2)
				{
					printf("%lld %lld %lld\n",i,h,h);
					break;
				}
			}
		}
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值