codeforce Gym - 101597C. Candy division

C. Candy division
time limit per test
2.0 s
memory limit per test
64 MB
input
standard input
output
standard output

Your older sister has three kids. Whenever you go to visit her, you bring along a bag of candies for the kids. There are n candies in the bag. You want to give all the candies to the kids, but you also want to teach them a little math along the way. Therefore, you gave them not just the bag of candies but also one simple rule: each of the kids must take an integer fraction of candies in the bag. In other words, the amount of candies each kid takes must be a divisor of n.

Formally, in order to divide all the candies the kids have to find three positive integers a1, a2, a3 such that n = a1 + a2 + a3 and each aidivides n.

Input

The first line of the input contains a single integer t – the number of test cases to follow. Each of the following t lines of the input contains the integer n. You may assume that 1 ≤ t ≤ 100 and 1 ≤ n ≤ 1018.

Output

Output t lines. The k-th line will solve the k-th test case and will contain three integers ai as specified above. If there are multiple solutions you may select an arbitrary one. If there are no solutions, output the word 'IMPOSSIBLE' instead (quotes only for clarity).

Example
input
Copy
3
1
3
12
output
Copy
IMPOSSIBLE
1 1 1
4 6 2 

                 已知一个数n,求是否存在abc,使a+b+c=n(1)的同时~a,b,c都能被n整除;

                 假设a*d=b*e=c*f=n; 把这个式子分别代入(1)式~~这样的话就是n/d+n/e+n/f=n~~简化得:1/d+1/e+1/f=1;

(其中d,e,f都是整数)~~这样的话~~把式子化为1/d+1/e=1-(1/f);  这样当f>=1的时候~~右边值就是0,1/2,2/3,3/4,4/5.......等等~~ 也就是1/d+1/e=(0, 1/2 , 2/3 , 3/4 , 4/5 ......)我们可以找出~~在d,e都为整数的时候~~又能够凑出1/2和2/3这两个值~~此时d,e,f的值分别为:3 3 3 (1/3, 1/3 ,1/3),4 4 2(1/4,1/4,1/2);

                   也就是::当这个数n能被3或4整除的时候~~才能化成如题目的形态~~;

                   最后别忘了用long long~~

#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	cin >> n;
	while (n--)
	{
		long long int m;
		scanf("%lld", &m);
		if (m % 3 == 0)
		{
			cout << m / 3 << " " << m / 3 << " " << m / 3 << endl;
		}
		else if (m % 4 == 0)
		{
			cout << m / 2 << " " << m / 4 << " " << m / 4 << endl;
		}
		else
		{
			cout << "IMPOSSIBLE" << endl;
		}
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值