Problem:
Score : 300 points

Problem Statement

You are given an integer N.

Find a triple of positive integers h, n and w such that 4/N = 1/h + 1/n + 1/w.

If there are multiple solutions, any of them will be accepted.

Constraints

It is guaranteed that, for the given integer N, there exists a solution such that h,n,w \leq 3500.

Inputs

Input is given from Standard Input in the following format:

N

Outputs

Print a triple of positive integers h, n and w that satisfies the condition, in the following format:

h n w

Sample Input 1

2

Sample Output 1

1 2 2

4/2 = 1/1 + 1/2 + 1/2.

Sample Input 2

3485

Sample Output 2

872 1012974 1539173474040

It is allowed to use an integer exceeding 3500 in a solution.

Sample Input 3

4664

Sample Output 3

3498 3498 3498

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<stdlib.h>
#include<string>
#include <functional>
#include"time.h"
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl
const int INF = (1 << 30);

//毎回変える場所
#define N_MAX 200


//問題文のとおり
int N;
const double EPS = 1e-9;

double abs1(double a) {
	if (a > 0)return a;
	else - a;
}


int main() {
	cin >> N;
	double aN = 1.0 / N;
	FOR(h, 1 , 3501)FOR(n, h, 3501){
		int l = n; 
		int r = 3500;
		int mid;
		double ans = 1.0 / h + 1.0 / n;
		while (l + 1 < r){
			mid = ( l + r )/ 2;
			if (abs1(aN - ans - 1.0 / mid) < EPS) {
				cout << h << " " << n << " " << mid << endl;
				cin >> N;
				return 0;
			}
			if (ans < aN) {
				r = mid;
			}
			else {
				l = mid;
			}
		}
		//失敗時
		if (abs1(aN - ans - 1.0 / (r + 1)) < EPS) {
			cout << h << " " << n << " " << r+1 << endl;
			cin >> N;
			return 0;
		}
		if (abs1(aN - ans - 1.0 / r) < EPS) {
			cout << h << " " << n << " " << r << endl;
			cin >> N;
			return 0;
		}
		if (abs1(aN - ans - 1.0 / (r - 1)) < EPS) {
			cout << h << " " << n << " " << r-1 << endl;
			cin >> N;
			return 0;
		}
	}
}