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;
		}
	}
}


全部评论

相关推荐

11-28 17:58
门头沟学院 Java
美团 JAVA开发 n×15.5
牛客786276759号:百度现在晋升很难的 而且云这块的业务没美团好 你看百度股价都跌成啥样了
点赞 评论 收藏
分享
10-30 22:18
已编辑
毛坦厂中学 C++
点赞 评论 收藏
分享
11-14 16:13
已编辑
重庆科技大学 测试工程师
Amazarashi66:不进帖子我都知道🐮❤️网什么含金量
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务