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



Sample input:
2


Sample output:
1 2 2

Submission status: Runtime Error

Solution code:
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cctype>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

int main(){
    int n, flag=0;
    ll x,y;
    cin >> n;
    for(int a=1; a<=3500; a++){
        if(flag)break;
        for(int b=a; b<=3500; b++){
            x = 4*a*b - n*a - n*b;
            y = n*a*b;
            if(x>0 && y>x && y%x==0){
                int c = y/x;
                cout << a <<" "<< b <<" "<< c << endl;
                flag = 1;
                break;
            }
        }
    }
}

Submission status: Runtime Error

Solution code:
n = int(input())

def solve(n):
	for x in range(1, 3501):
		nx = n * x
		for y in range(x, 3501):
			# 4/n = 1/x + 1/y + 1/z
			# 1/z = 4/n - 1/x - 1/y
			# z = 1/(4/n - 1/x - 1/y)
			# z = nxy/(4xy - ny - nx)
			nxy = nx * y
			den = 4*x*y - n*y -nx
			if (nxy % den == 0 and nxy//den > 0):
				print(x, y, nxy//den)
				return

solve(n)

Submission status: Runtime Error

Solution code:
from math import ceil
N = int(input())
max_w = 3*N/4
if max_w % 1 == 0:
    max_w += 1
ans = ""
for w in range(1,ceil(max_w)):
    max_n = 2/(4/N - 1/w)
    if max_n % 1 == 0:
        max_n += 1
    for n in range(1,ceil(max_n)):
        if 4/N - 1/n - 1/w == 0:
            continue
        h = 1/(4/N - 1/n - 1/w)
        if h % 1 == 0:
            ans = str(int(h)) + " " + str(n) + " " + str(w)
            break
    if ans:
        break
print(ans)

Submission status: Runtime Error

Solution code:
from math import ceil
N = int(input())
max_w = 3*N/4
for w in range(1,ceil(max_w),-1):
    max_n = 2/(4/N - 1/w)
    for n in range(1,ceil(max_n),-1):
        h = 1/(4/N - 1/n - 1/w)
        if h % 1 == 0:
            ans = str(h) + " " + str(n) + " " + str(w)
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Here your code !
N = int(input())

w = 0
for h in range(1 , 3501) : 
    if w != 0 : break
    x = 4 / N - 1 / h
    if x <= 0 : continue
    for n in range(1 , 3501) : 
        y = x - 1/n
        if y <= 0 : continue
        if n % (x*n - 1)  == 0 : 
            w = int(n / (n*x - 1))
            break
        
print(h - 1,n,w)