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: Wrong Answer

Solution code:
from fractions import Fraction
from math import ceil


N = int(input())
r = Fraction(4, N)
h = ceil(r.denominator / r.numerator)

r -= 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)
else:
    n, w = n+1, n*(n+1)

print(h, n, w)

Submission status: Wrong Answer

Solution code:
N=int(input())

import sys

for h in range(1,3501):
    for n in range(h,3501):
        a=(h*n*N)
        b=(4*h*n-(n+h)*N)
        if b==0:
            continue
        w=int(a/b)
        if w<n:
            break
        if a%b==0:

            #print(w)
            if w>0:
                print(h,n,w)
                sys.exit()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

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 get_a(N):
    a = 1
    while True:
        if N < 4 * a:
            return a, 4*a-N, N*a
        a += 1

def get_b(N1, N2):
    b = 1
    while True:
        if N2 < b * N1:
            return b, b*N1-N2, b*N2
        b += 1

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

def solve(N):
    a, N1, N2 = get_a(N)
    print("a,N1,N2 = ", a, N1, N2)
    b, N1, N2 = get_b(N1, N2)
    print("b,N1,N2 = ", b, N1, N2)
    g = gcd(N1,N2)
    N1 //= g
    N2 //= g
    # assert(N1 == 1)
    print(a, b, N2)

for N in range(1, 100):
    solve(N)

solve(N)

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while(b != 0):
        tmp = b
        b = a % b
        a = tmp
    return a
n = int(raw_input())
if(n % 2 == 0):
    print n, n, n / 2
    exit(0)
for e in xrange(1, 3501):
    for f in xrange(1, 3501):
        num0 = e + f
        den0 = e * f
        den1 = n * den0
        num1 = n * e + n * f + 4 * e * f
        gc = gcd(num1, den1)
        if(num1 / gc == 1):
            print e, f, den1 / gc
            exit(0)

Submission status: Wrong Answer

Solution code:
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**10
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//2,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())

Submission status: Wrong Answer

Solution code:
# coding: utf-8
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):
            w = (4 * h * n - N * h - N * n) / (N * h * n)
            if w > 0 and int(w) == w:
                ans = [h, n, w]
                flag = True
                break
        if flag:
            break
    ans = " ".join(map(str, map(int, ans)))
    return ans
 
 
def main():
    params = read()
    print(solve(*params))
 
 
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
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**10
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()
    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())

Submission status: Wrong Answer

Solution code:
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)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

for i in range(1,3501):
    for j in range(1,3501):
        if (4*i*j-n*i-n*j) != 0:
            w = i*j*n/(4*i*j-n*i-n*j)
            if w%1 == 0 and w > 0:
                print(i,j,int(w))
                exit()

Submission status: Time Limit Exceeded

Solution code:
import sys

def cal():
    N = int(input())

    for i in range(1, 3501):
        for j in range(1, 3501):
            num0 = 4*i*j-N*(i+j) 
            if num0 != 0:
                num = N*i*j/num0
                if num.is_integer() and 0 < num <= 3500:
                    print(i, int(num), j)
                    sys.exit()

cal()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
for h in range(1, 3501):
    for n in range(1, 3501):
        numera = 4 * h * n - n * N - h * N
        denomi = h * n * N
        if numera <= 0:
            continue
        elif denomi % numera != 0:
            continue
        w = denomi // numera
        print(h, n, w)
        exit()

Submission status: Time Limit Exceeded

Solution code:
def main():
    N = int(input())
    for n in range(1, 3501):
        for h in range(1, 3501):
            denom = 4*n*h - N*n - N*h
            if denom == 0:
                continue
            w = (N*h*n) / denom
            if w == int(w) and w > 0:
                print(int(n), int(h), int(w))
                return
    
if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:

def resolve():
    nnn = int(input())
    for h in range(1, 3501):
        for w in range(1, 3501):
            div = 4 * h * w - nnn * h - nnn * w
            if div == 0:
                continue
            n = nnn * h * w / div
            if int(n) == n and 0 < n:
                print(h, w, int(n))
                return

if __name__ == "__main__":
    resolve()

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
for h in range(1,3500):
    for n in range(1,3500):
        flg = False
        try:
            w = (N*h*n)/(4*h*n-N*n-N*h)
            if w >= 0 and w.is_integer():
                flg = True
        except:
            pass
        if flg:
            print(h,n,int(w))
            exit(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
mx = 3503
found = False
for i in range(1, mx):
    for j in range(1, mx):
        num = N*i*j
        den = (i*j*4 - N*i - N*j)
        if den == 0:
            continue
        if num%den == 0 and num//den > 0 and num//den < mx:
            print(i,j,num//den)
            found = True
            break
    if found:
        break

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
ans_a = 0
ans_b = 0
ans_c = 0
for b in range(1, 3501):
    for c in range(1, 3501):
        sita = 4 * b * c - (n * (b + c))
        if sita <= 0:
            continue
        ue = n * b * c
        if ue % sita == 0:
            ans_a, ans_b, ans_c = ue // sita, b, c
            break
print(ans_a, ans_b, ans_c)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

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

Submission status: Time Limit Exceeded

Solution code:
import sys
N=int(input())

for h in range(1,3501):
  for n in range(1,3501):
    bb=(4*h*n-N*n-N*h)
    bs=(N*h*n)
    if bb==0:
      continue

    if bs%bb==0 and 1<=bs//bb:
      print(h,n,bs//bb)
      sys.exit()

Submission status: Time Limit Exceeded

Solution code:
import sys
N = int(input())
for i in range(1,3501):
  for j in range(max(i-1,1),3501):
    if (4*i*j - N*i -N*j) != 0:
      w = (N*i*j)/(4*i*j - N*i -N*j)
      if w > 0 and w.is_integer():
        print(i,j,int(w))
        sys.exit()

Submission status: Time Limit Exceeded

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    from fractions import Fraction
    n = int(readline())
    k = Fraction(4, n)
    kd = k - Fraction(1, 3500)

    for a in range(1, 3501):
        p = Fraction(1, a)
        for b in range(a, 3501):
            q = Fraction(1, b)
            x = p + q
            if x > kd:
                break
            ok = 3500
            ng = 0
            while abs(ng - ok) > 1:
                mid = (ok + ng) // 2
                y = x + Fraction(1, mid)
                if y > k:
                    ng = mid
                else:
                    ok = mid
            if x + Fraction(1, ok) == k:
                return print(a, b, ok)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(input())
for i in range(3500):
    for j in range(3500):
        temp = 4 * (i + 1) * (j + 1) - n * (i + j + 2)
        if temp != 0:
            if (n * (i + 1) * (j + 1)) % temp == 0:
                if (n * (i + 1) * (j + 1)) // temp > 0:
                    print(i + 1, j + 1, (n * (i + 1) * (j + 1)) // temp)
                    sys.exit()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
for i in range(1, 3501):
    for j in range(1, 3501):
        tmp = 4 * i * j - N * j - N * i
        if tmp != 0 and (N * i * j) % tmp == 0:
            k = (N * i * j) // (4 * i * j - N * j - N * i)
            if k>0:
                print(i, j, k)
                exit()

Submission status: Time Limit Exceeded

Solution code:
from itertools import product

N = int(input())

for h, w in product(range(1, 3501), range(1, 3501)):
    tmp = 4 * h * w - N * w - N * h
    if tmp:
        n = (N * h * w) / tmp
        if 3501 > n > 0 and n == int(n):
            print(h, int(n), w)
            exit()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
for ai in range(1,3500):
    for bi in range(1,3500):
        try:
            ci = N*ai*bi/(4*ai*bi-N*ai-N*bi)
        except:
            continue
        if ci == int(ci) and ci > 0:
            print(ai,bi,int(ci))
            exit()

Submission status: Time Limit Exceeded

Solution code:
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()

    ans = (0, 0, 0)
    for h in range(1, 3501):
        for n in range(1, 3501):
            # 式をwについて解いた
            num = N * n * h
            denom = 4 * h * n - N * (h + n)
            if denom > 0 and num % denom == 0:
                w = num // denom
                ans = (h, n, w)
                break

    print(*ans)

if __name__ == '__main__':
    resolve()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())


for h in range(1, 3500):
    for n in range(1, 3500):
        x = 4 * h * n - N * h - N * n
        if x != 0:
            w = N * h * n / (4 * h * n - N * h - N * n)
            if int(w) == w and w > 0:
                print(h, n, int(w))
                exit()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        try:
            w = (N * h * n) / (4 * (h * n) - (N * n) - (N * h))
        except:
            continue
        if w.is_integer() and 0 < w and w < 3501:
            if 4 * (h * n * w) == N * ((n * w) + (h * w) + (h * n)):
                ans = [h, n, int(w)]
                exit(print(' '.join(map(str, ans))))

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction
import math
N = int(input())
ans = Fraction(4,N)
point = [1,math.floor(N/4)]
for h in range(1,3501):
    h_pro = Fraction(1,h)
    for n in range(1,3501):
        check = ans - h_pro
        n_pro = Fraction(1,n)
        check -= n_pro
        if type(check) == "int":
            if check ==1:
                print(h, end=" ")
                print(n, end=" ")
                print(1)
                exit()
        elif check.numerator == 1:
            print(h, end=" ")
            print(n, end=" ")
            print(check.denominator)
            exit()

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction
import math
N = int(input())
ans = Fraction(4,N)
point = [1,math.floor(N/4)]
for h in range(max(point),3501):
    h_pro = Fraction(1,h)
    check = ans - h_pro
    target = [math.floor(4*h-N/N*h),h]
    for n in range(h,3501):
        check = ans - h_pro
        n_pro = Fraction(1,n)
        check -= n_pro
        if type(check) == "int":
            if check ==1:
                print(h, end=" ")
                print(n, end=" ")
                print(1)
                exit()
        elif check.numerator == 1:
            print(h, end=" ")
            print(n, end=" ")
            print(check.denominator)
            exit()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

for h in range(1,3501):
    for w in range(1,3501):
        if 4 * h * w - n * w - n * h != 0:
            N = (n * h * w) / (4 * h * w - n * w - n * h)
            if N.is_integer() and N > 0:
                print(h,w,int(N))
                exit()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

for h in range(1, 3501):
  for n in range(1, 3501):
    a = (4 * h * n) - N * h - N * n
    if a == 0:
      continue
    w = (N * h * n) / a
    if w.is_integer() and 0 < w:
      print(h, n, int(w))
      exit(0)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        t1 = 4 * h * n
        t2 = N * (h+n)
        if t1 != t2:
            temp = (N*h*n) / (t1-t2)
            if temp.is_integer():
                if temp > 0:
                    print(h,n,int(temp))
                    break
    else:
        continue
    break

Submission status: Time Limit Exceeded

Solution code:
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

if N % 2 == 0:
    h, n, w = N//2, N, N
else:
    h = N
    w_i = N//3 + 1
    while True:
        if (N*w_i)%(3*w_i-N) == 0:
            n = (N*w_i)//(3*w_i-N)
            w = w_i
            break
        else:
            w_i += 1

print(h, n, w)

Submission status: Time Limit Exceeded

Solution code:
import math

N = int(input())

if N % 2 == 0:
    h, n, w = N//2, N, N
else:
    h = N
    w_i = N//3 + 1
    while True:
        if (N*w_i)%(3*w_i-N) == 0:
            n = (N*w_i)//(3*w_i-N)
            w = w_i
            break
        else:
            w_i += 1

print(h, n, w)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())

for h in range(1, 3501):
    for w in range(1, 3501):
        if 4*h*w-N*(h+w)!=0:
            n=N*h*w/(4*h*w-N*(h+w))
            if n.is_integer() and n>0:
                print(h,int(n),w)
                exit()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
for a in range(1,3501):
  for b in range(1,3501):
    s = n*a*b
    #s=4
    t = 4*a*b-n*b-n*a
    #t=8-4-2
    if t!=0 and s%t==0 and t>0:
      c = s//t
      print(a,b,c)
      exit()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
for h in range(1,3501):
    for n in range(1,3501):
        d = 4*h*n-N*h-N*n
        if d == 0 or N*h*n%d != 0: continue
        w = N*h*n//d
        if w < 0: continue
        print(h,n,w)
        exit()

Submission status: Time Limit Exceeded

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

N = INT()

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
for h in range(1,3501):
  for n in range(1,3501):
    if 4*h*n-N*n-N*h!=0 and (N*h*n)%(4*h*n-N*n-N*h)==0 and (N*h*n)//(4*h*n-N*n-N*h)>0:
      print(h,n,(N*h*n)//(4*h*n-N*n-N*h))
      exit()

Submission status: Time Limit Exceeded

Solution code:
from fractions import Fraction

def main():
    N = int(input())
    a = Fraction(4, N)
    ans = [0,0,0]
    for h in range(N//2,3501):
        b = Fraction(1, h)
        for n in range(N//2,3501):
            c = Fraction(1,n)
            d = a - b - c
            if d > 0 and d.numerator == 1:
                print(h, n, d.denominator)
                exit()






if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

for h in range(1, 3501):
    for n in range(1, 3501):
        x = 4 * h * n - N * n - N * h
        if x != 0 and N * h * n % x == 0:
            w = N * h * n // x
            if w >= 1:
                print(h, n, w)
                exit()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

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

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()

p = factorization(N)[0][0]
r = N//p

if p == 3:
  print(2*r,2*r,3*r)
  exit()
if p == 7:
  print(4*r,4*r,14*r)
  exit()

k = 1
while True:
  if (p*k) % (3*k-1) == 0:
    b = (p*k)//(3*k-1)
    a = p*k
    break
  k += 1
  
print(a*r,b*r,p*r)

Submission status: Time Limit Exceeded

Solution code:
# -*- coding: utf-8 -*-

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####MakePrimes######
def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum

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

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############
N = I()

p = factorization(N)[0][0]
r = N//p

if p == 3:
  print(2*r,2*r,3*r)
  exit()

k = 1
while True:
  if (p*k) % (3*k-1) == 0:
    b = (p*k)//(3*k-1)
    a = p*k
    break
  k += 1
  
print(a*r,b*r,p*r)

Submission status: Time Limit Exceeded

Solution code:
import sys

n = int(input())


for i in range(1, 3500):
    for j in range(1, 3500):
        # 分子
        rest = 4 * i * j - n * i - n * j
        if rest > 0:
            ans = n * i * j / rest
            if ans.is_integer():
                print(i, j, int(ans))
                sys.exit()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

for h in range(1,3501):
  for n in range(1,3501):
    if (4*h*n-N*n-N*h)!= 0:
        w = N*h*n/(4*h*n-N*n-N*h)
        if w >0 and w.is_integer():
          print(h,n,int(w))
          exit()

Submission status: Time Limit Exceeded

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    N = ni()
    lim = 3500

    for h in range(1, lim + 1):
        for n in range(1, lim + 1):
            up = N * h * n
            down = 4 * h * n - N * n - N * h
            if down != 0:
                if up % down == 0:
                    if 0 < up // down:
                        print(h, n, up // down)
                        exit(0)


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

import fractions
#import math
from functools import reduce
def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)
  #return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

for h in range(1, 3501):
    l = lcm_base(N, h)
    for n in range(h, 3501):
        l = lcm_base(l, n)
        x = 4*(l//N)-l//h-l//n
        if x <= 0:
            continue
        else:
            if l%x == 0:
                print(h, n, l//x)
                exit()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

import fractions
#import math
from functools import reduce
def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)
  #return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

for h in range(1, 3501):
    for n in range(h, 3501):
        l = lcm_list([N, h, n])
        x = 4*(l//N)-l//h-l//n
        if x <= 0:
            continue
        else:
            if l%x == 0:
                print(h, n, l//x)
                exit()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

import fractions
#import math
from functools import reduce
def lcm_base(x, y):
  return (x * y) // fractions.gcd(x, y)
  #return (x * y) // math.gcd(x, y)

def lcm_list(numbers):
  return reduce(lcm_base, numbers, 1)

for h in range(1, 3501):
    for n in range(1, 3501):
        l = lcm_list([N, h, n])
        x = 4*(l//N)-l//h-l//n
        if x <= 0:
            continue
        else:
            if l%x == 0:
                print(h, n, l//x)
                exit()