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 (Python):
from sys import stdin

gets = stdin.readline


def main():
    n = int(gets())
    flag = False
    for h in range(3500, 1, -1):
        nh = n*h
        for w in range(1, h+1):
            y = (4 * h * w - nh - n*w)
            if y > 0 and (nh % y == 0 or w % y == 0):
                print(h, w, (nh*w)//y)
                flag = True
                break
        if flag:
            break
    return


if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin

gets = stdin.readline


def main():
    n = int(gets())
    h, w = 0, 0
    flag = False
    for _ in range(3500):
        h += 1
        w = 0
        for _ in range(3500):
            w += 1
            y = (4 * h * w - n * (h + w))
            if y > 0:
                modulo = n % y * h % y * w % y
                if modulo % y == 0:
                    print(h, w, (n*h*w)//y)
                    flag = True
                    break
        if flag:
            break
    return


if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())

for x in range(n//4, 3501):
    for y in range(x, 3501):
        A = n*x*y
        B = 4*x*y - n*x - n*y
        if B > 0 and A % B == 0:
            print(x, y, A//B)
            exit()

Solution (Python):
n = int(input())
ans = None
for i in range(1, 3501, 1):
	for j in range(1, 3501, 1):
		dominator = 4 * i * j - n * (i + j)
		if dominator > 0:
			numerator = i * j * n
			if numerator % dominator == 0:
				ans = (i, j, int(numerator / dominator))
				break
	if ans is not None:
		break
print(" ".join(map(str, ans)))

Solution (Python):
from itertools import product

def inpl(): return tuple(map(int, input().split()))

N = int(input())

for b, c in product(range(max(1, N//4), 3500), range(max(1, N//4), 3500)):
    top = N*b*c
    bottom = 4*b*c - N*c -N*b

    if bottom > 0 and (top%bottom == 0):
        a = top // bottom
        print(a, b, c)
        break

Solution (Python):
N = int(input())

for h in range(1, 3501):
    a = 4 * h - N
    if a <= 0:
        continue
    b = N * h
    for n in range(max(h, b // a + 1), 3501):
        q = 4 * h * n - N * h - N * n
        if q <= 0:
            continue
        p = N * h * n
        if p % q == 0:
            w = int(p / q)
            print(str(h) + ' ' + str(n) + ' ' + str(w))
            exit()

Solution (Python):
N = int(input())

for h in range(1, 3501):
    for n in range(h, 3501):
        q = 4 * h * n - N * h - N * n
        if q <= 0:
            continue
        p = N * h * n
        if p % q == 0:
            w = int(p / q)
            print(str(h) + ' ' + str(n) + ' ' + str(w))
            exit()

Solution (Python):
N = int(input())

for h in range(1, 3501):
    for n in range(h, 3501):
        q = 4 * h * n - N * h - N * n
        if q <= 0:
            continue
        p = N * h * n
        if p >= q and p % q == 0:
            w = int(p / q)
            print(str(h) + ' ' + str(n) + ' ' + str(w))
            exit()

Solution (Python):
import sys
N=int(input())
if N%2==0:
  print(N//2,N,N)
  sys.exit()
for a in range(1,3501):
  for b in range(1,a):
    M=N*a*b
    L=4*a*b-N*(a+b)
    if L>0:
      if M%L==0:
        print(a,b,M//L)
        sys.exit()

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    for h in range(1, 3501):
        for n in range(1, 3501):
            if 4 * h * n - N * (n + h) > 0 and (N * h * n) % (4 * h * n - N * (n + h)) == 0:
                w = (N * h * n) // (4 * h * n - N * (n + h))
                print(str(h) + " " + str(n) + " " + str(w))
                exit()

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import re
import string

N = int(input())

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def solve(N):
    for a in range(1, 3501):
        N1 = 4*a - N
        N2 = N * a
        if N1 < 0: continue
        for b in range(1, 3501):
            N3 = b * N1 - N2
            N4 = b * N2
            if N4 > 0 and N3 > 0 and N4 % N3 == 0:
                print(a, b, N4//N3)
                return
    
solve(N)

Solution (Python):
import math

originN = int(raw_input())

isValid = False
for h in xrange(1, 3501):
    for n in xrange(1, 3501):
        if (4*n*h-n*originN-h*originN) > 0 and (originN*n*h) % (4*n*h-n*originN-h*originN) == 0:
            isValid = True
            print str(h)+" "+str(n)+" "+str((originN*n*h)/(4*n*h-n*originN-h*originN))
            break
    if isValid: break

Solution (Python):
import math

originN = int(raw_input())
N = originN
primes = []
while True:
    if N % 2 == 0:
        primes.append(2)
        N /= 2
    else:
        break
i = 3
while True:
    if N == 1 or N < i**2:
        break
    while True:
        if N % i == 0:
            primes.append(i)
            N /= i
        else:
            break
    i += 2
if N != 1:
    primes.append(N)
if primes[0] == 2:
    print str(originN/2)+" "+str(originN)+" "+str(originN)
elif primes[0] == 3:
    print str(originN/3)+" "+str(originN*2)+" "+str(originN*2)
else:
    p = int(math.ceil(float(primes[0])/4.0))
    if primes[0] % 4 == 1:
        if p % 2 == 0:
            print str(originN/primes[0]*p)+" "+str(originN*p/2)+" "+str(originN*p)
        else:
            isValid = False
            for h in xrange(1, 3501):
                for n in xrange(1, 3501):
                    if (4*n*h-n*originN-h*originN) > 0 and (originN*n*h) % (4*n*h-n*originN-h*originN) == 0:
                        isValid = True
                        print str(h)+" "+str(n)+" "+str((originN*n*h)/(4*n*h-n*originN-h*originN))
                        break
                if isValid: break
    else:
        print str(originN/primes[0]*p)+" "+str(originN*p*2)+" "+str(originN*p*2)

Solution (Python):

from itertools import combinations


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


def find_result(primes, cond, total):
    combi = {}
    for i in range(len(primes)):
        for c in combinations(primes, i+1):
            s = reduce(lambda x, y: x * y, c)
            if s <= cond - 2 and total / s < 3500:
                combi[tuple(c)] = s

    keys = sorted(combi.keys())
    for h in keys:
        for n in keys:
            for w in keys:
                s = combi[h] + combi[n] + combi[w]
                if s == cond:
                    return combi[h], combi[n], combi[w]
    return None


N = int(raw_input())
primes = [
    1,
] + prime_decomposition(N)

i = 2
while True:
    cond = i * 4
    all_primes = primes + prime_decomposition(i)
    total = reduce(lambda x, y: x * y, all_primes)
    candi_primes = [p for p in all_primes if p <= cond - 2]

    r = find_result(candi_primes, cond, total)
    if r is not None:
        h, n, w = r
        print '{} {} {}'.format(int(total/h), int(total/n), int(total/w))
        break
    i += 1

Solution (Python):
def solve(n):
    if n & 1 == 0:
        return n, n, n // 2
    for h in range(n // 4, 3501):
        nh = n * h
        for w in range(h, 3501):
            nm = 4 * h * w - nh - n * w
            if nm <= 0:
                continue

            dnm = nh * w
            if dnm % nm == 0:
                return h, w, dnm // nm


n = int(input())
print(*solve(n))

Solution (Python):
import sys
from math import *

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]

    for h in  range(1, 3501):
        for n in  range(1, 3501):
            if (4 * h * n - N * n - N * h) > 0:
                w = (N * n * h)/(4 * h * n - N * n - N * h)

                if N * (n *w  + h * w + n * h) == 4 * h * n * w:
                    print h, n, w
                    return


if __name__ == '__main__':
    main()

Solution (Python):
from fractions import Fraction
from math import ceil


N = int(input())
for h in range(ceil(N / 4), ceil(N / 4)*1000):
    r = Fraction(4, N) - Fraction(1, h)
    if r.numerator > 0:
        n = ceil(r.denominator / r.numerator)
    else:
        h, n = h+1, h * (h+1)
        r = Fraction(4, N) - Fraction(1, h)

    r -= Fraction(1, n)
    if r.numerator > 0:
        w = ceil(r.denominator / r.numerator)
        r -= Fraction(1, w)
    else:
        n, w = n+1, n*(n+1)
        r = Fraction(4, N) - Fraction(1, h) - Fraction(1, n) - Fraction(1, w)

    if r == 0:
        print(h, n, w)
        break

Solution (Python):

import fractions as fr
from itertools import count,product
from math import ceil

N = int(input())

if N%2 == 0:
  print(N,N,N//2)
  exit()

for h in range(1,3501):
  if 4*h > N:
    a = N*h//(4*h-N)+1
    b = 3501
  else:
    a = 1
    b = N*h//(4*h-N)+1
  for n in range(a,b):
    if (N*h*n)%(4*h*n-N*h-N*n) == 0:
      print(h,n,(N*h*n)//(4*h*n-N*h-N*n))
      exit()

Solution (Python):
def main():
    N = input()

    for h in range(1, 3501):
        for n in range(1, 3501):
            r1 = h * n * N
            r2 = 4 * h * n - h * N - n * N
            if r2 > 0 and r1 % r2 == 0:
                print "%d %d %d" % (h, n, r1 / r2)
                return

main()

Solution (Python):


import math
import fractions
import heapq
import collections
import re
import array
import bisect

from collections import Counter, defaultdict


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]


def main():
    N = int(input())
    for i in range(1, 3501):
        for j in range(1, i + 1):
            fb = 4 * i * j - N * (i + j)
            if fb <= 0:
                continue
            fa = N * i * j
            k = int(fa / fb)
            if (k * fb == fa):
                print("{} {} {}".format(i, j, k))
                return


if __name__ == "__main__":
    main()

Solution (Python):

def II(): return int(input())
def ILI(): return list(map(int, input().split()))


def read():
    N = II()
    return (N,)


def solve(N):
    ans = []
    for h in range(1, 3501):
        flag = False
        for n in range(1, 3501):
            if 4 * h * n - N * h - N * n == 0:
                continue
            div, mod = divmod(N * h * n, 4 * h * n - N * h - N * n)
            if mod == 0 and div > 0:
                ans = [h, n, div]
                flag = True
                break
        if flag:
            break
    ans = " ".join(map(str, ans))
    return ans


def main():
    params = read()
    print(solve(*params))


if __name__ == "__main__":
    main()

Solution (Python):


import itertools


MAX_ANS = 3500


def solve(n):
    for h, m in itertools.product(range(1, MAX_ANS + 1), repeat=2):
        d = 4 * h * m - n * m - n * h
        if d <= 0:
            continue
        w, mo = divmod(n * h * m, d)
        if mo == 0 and w > 0:
            return h, m, w
    assert False


def main():
    n = int(input())
    res = solve(n)
    print(*res)


if __name__ == '__main__':
    main()

Solution (Python):

N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        if 1/n + 1/h > 4/N:
            continue
        if (4*h*n-N*n-N*h) ==0:
            continue
        val =N*h*n/(4*h*n-N*n-N*h)
        if val == int(val) and val>0:
            print(h,n,int(val))
            exit(0)

Solution (Python):
n = int(input())
c = 0
for a in range(1, 3501):
    for b in range(a, 3501):
        if 4*a*b - n*(a+b) > 0 and n*a*b % (4*a*b - n*(a+b)) == 0:
            c = n*a*b // (4*a*b - n*(a+b))
            print('{} {} {}'.format(a, b, c))
            break
    if c:
        break

Solution (Python):
def main():
    N = int(input())
    for w in range(1, int(3*N/4)+1):
        a = 4 * w - N
        b = N * w
        if a == 0:
            continue
        for n in range(w, int(2*b/a)+1):
            if a*n - b != 0 and (b*n) % (a*n - b) == 0:
                h = b * n // (a*n - b)
                if h > 0:
                    print(h, n, w)
                    return
main()

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def pf(s):
    print(s, flush=True)

def main():
    n = I()
    if n%2 == 0:
        return "{} {} {}".format(n,n,n//2)
    t = 4/n
    for i in range(1,3501):
        c = t - 1/i
        for j in range(i,3501):
            d = c - 1/j
            if d <= 0:
                continue
            e = 1 / d
            if e > 3501:
                continue
            f = math.ceil(e)
            if f > 0 and abs(d - 1/f) < eps:
                return '{} {} {}'.format(i,j,f)
            f = math.floor(e)
            if f > 0 and abs(d - 1/f) < eps:
                return '{} {} {}'.format(i,j,f)

    return -1



print(main())

Solution (Python):
N = int(input())

def calc(h, n):
    a = N*h*n
    b = 4*h*n - N*n - N*h
    if b != 0:
        if a % b == 0 and a // b <= 3500 and a // b >= 1:
            return a // b
        else:
            return -1
    else:
        return -1

ans = 0
for h in range(1, 3501):
    for n in range(h, 3501):
        w = calc(h, n)
        if w > 0:
            ans = (h, n, w)
            break
print(ans[0],ans[1], ans[2])

Solution (Python):
N = int(input())
ans = []
for h in range(1, 3501):
    for n in range(h, 3501):
        x = 4 * h * n - N * n - N * h
        if x == 0:
            continue
        w = N * h * n // x
        if 4 * h * n * w == N * (n * w + h * w + h * n):
            ans = [h, n, w]
            break
print(' '.join(map(str, ans)))

Solution (Python):
def main():
    N = int(input())
    for i in range(1, 3501):
        for j in range(i, 3501):
            a = N * i * j
            b = 4*i*j - N*(i+j)
            if b == 0:
                continue
            if a%b == 0 and a//b > 0:
                print(a//b, i, j)
                exit()

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        a = n * h * N
        b = 4 * h * n - N * n - N * h
        if b > 0 and a % b == 0:
            print(h, n, a // b)
            quit()
assert(False)

Solution (Python):
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        b = 4*h*n - N*(n+h)
        a = N*h*n
        
        if b > 0 and a % b == 0:
            w = a // b
            print(h, n, w)
            exit(0)