Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for i in range(t): n = int(input()) divisorarr = [] for divisor in range(2, int(n ** 0.5) + 2): if n % divisor == 0: while n % divisor == 0: n = n // divisor divisorarr.append(divisor) if n != 1: divisorarr.append(n) if len(divisorarr) < 3: print('NO') else: a = divisorarr[0] b = divisorarr[1] index = 2 while b == a and index < len(divisorarr) - 1: b *= divisorarr[index] index += 1 c = 1 for divisor in range(index, len(divisorarr)): c *= divisorarr[divisor] if not a != b != c != a: print('NO') else: print('YES') print(a, b, c)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
I = input for _ in [0]*int(I()): temp = int(I()) ans = [] for i in range(2,temp,1): if(temp % i == 0): ans.append(i) break elif i *i > temp: break if(len(ans) == 0 or ans[0]*ans[0] >= temp): print("NO");continue temp //= ans[0] for i in range(ans[0],int(temp),1): if(int(temp) % i == 0 and i != ans[0]): ans.append(i) temp //= i break elif i *i > temp: break if(len(ans) == 1): print("NO");continue if(int(temp) != ans[0] and int(temp) != ans[1]): ans.append(int(temp)) print("YES") for i in ans: print(i,end = ' ') print('') else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int ans[2], j = -1, i; long long n; cin >> n; for (i = 2; i * i <= n && j != 1; i++) { if (n % i == 0) { ans[++j] = i; n = n / i; } } long long ch = ans[0] * ans[1]; if (j < 1 || (ans[0] == n || ans[1] == n)) cout << "NO" << endl; else { cout << "YES" << endl; cout << ans[0] << " " << ans[1] << " " << n << endl; } } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for _ in range(t): n = int(input()) nn = n fac = [] i = 2 while i * i <= n: cnt = 0 while n % i == 0: cnt += 1 n //= i if cnt: fac.append((i, cnt)) i += 1 if n > 1: fac.append((n, 1)) ok = False ans = None if len(fac) > 2 or len(fac) == 2 and fac[0][1] + fac[1][1] > 3: ok = True ans = (fac[0][0], fac[1][0]) elif len(fac) == 1 and fac[0][1] >= 6: ok = True ans = (fac[0][0], int(fac[0][0] ** 2)) if not ok: print("NO") else: print("YES") print(ans[0], ans[1], nn // ans[0] // ans[1])
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
""" Author : Aman Thakur mantra: chor kya hi kar sakte hai!! """ import math class Solution: def __init__(self): self.arr = [] def solution(self): n = int(input()) for i in range(2, n): if n % i == 0: self.arr.append(i) n //= i if len(self.arr) == 2 or n < i*i: break if len(self.arr) == 2 and n != self.arr[0] and n != self.arr[1] and n > 1: print('YES') print(self.arr[0], self.arr[1], n) else: print('NO') if __name__ == '__main__': for _ in range(int(input())): ob = Solution() ob.solution()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import * for i in range(int(input())): n=int(input()) j=2 count=0 num=[] while j**2<=n: if n%j==0: if len(num)==1: if n%(j*num[0])!=0: j+=1 continue num.append(j) count+=1 if count==2: break j+=1 #print(num) if count<2: print("NO") continue if count==2: val=n//(num[0]*num[1]) if val in num: print("NO") continue if val*num[0]*num[1]!=n: print("NO") continue print("YES") print(num[0], num[1], val)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
""" Author : Aman Thakur mantra: chor kya hi kar sakte hai!! """ import math class Solution: def __init__(self): self.c = 0 self.arr = [] def solution(self): n = int(input()) for i in range(2, n): if n % i == 0: self.arr.append(i) n //= i if len(self.arr) == 2 or n < i*i: break if len(self.arr) == 2 and n != self.arr[0] and n != self.arr[1] and n > 1: print('YES') print(self.arr[0], self.arr[1], n) else: print('NO') if __name__ == '__main__': for _ in range(int(input())): ob = Solution() ob.solution()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n=int(input()) sq=int(n**0.5 +1) a=[] d={} for i in range(2,sq): if(n%i==0): x=n//i a.append(i) d[i]=x d[x]=i ch=1 for i in range(len(a)): for j in range(i+1,len(a)): try: x=d[ a[i]*a[j] ] y=a[i] z=a[j] if(x!=y)and(x!=z): ch=2 break except: continue if(ch==2): break if(ch==2): print("YES") print(x,y,z) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def ans(n): a, b = -1, -1 for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: a = i break if a == -1: print('NO') return for i in range(a + 1, int(math.sqrt(n)) + 1): if (n % i == 0) & (n % (a * i) == 0): b = i break if b == -1: print('NO') return if (n / (a * b) != 1) & (n / (a * b) != a) & (n / (a * b) != b): print('YES') print(a, b, int(n / (a * b))) return print('NO') return t = int(input()) while(t): t = t - 1 n = int(input()) ans(n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys import math from math import gcd from heapq import heappop from heapq import heappush from heapq import heapify from bisect import insort from bisect import bisect_right from bisect import bisect_left from sys import stdin,stdout from collections import defaultdict, deque from math import log2, ceil, floor inp=lambda : int(input()) sip=lambda : input() mulip =lambda : map(int,input().split()) lst=lambda : list(map(int,input().split())) slst=lambda: list(sip()) arr2d= lambda x: [[int(j) for j in input().split()] for i in range(x)] odds = lambda l: len(list(filter(lambda x: x%2!=0, l))) evens = lambda l: len(list(filter(lambda x: x%2==0, l))) mod = pow(10,9)+7 #------------------------------------------------------- Judge = 0 if Judge: sys.stdin = open("input.in",'r') #sys.stdout = open("output.in",'w') for _ in range(inp()): n = inp() x = n d = {} i = 2 while i*i <= x: cnt = 0 while(n%i==0 and n!=0): n = n//i #print(n,i) cnt += 1 d[i] = cnt i += 1 if n>2: d[n] = 1 if len(d)==0: print("NO") elif len(d)==1: l = list(d.keys()) if d[l[0]]>=6: print("YES") print(l[0],pow(l[0],2),pow(l[0],d[l[0]]-3)) else: print("NO") elif len(d)==2: l = list(d.keys()) if d[l[0]]+d[l[1]]>=4: print("YES") print(l[0],l[1],x//(l[0]*l[1])) else: print("NO") else: l = list(d.keys()) print("YES") print(pow(l[0],d[l[0]]),pow(l[1],d[l[1]]),end=" ") ans = 1 for i in range(2,len(l)): ans *= pow(l[i],d[l[i]]) print(ans)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for _ in range(int(input())): n = int(input()) p = tuple((n, 1)) lt = [] while n % 2 == 0: lt.append(2) n = n / 2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: lt.append(i), n = n / i if n > 2: lt.append(int(n)) #print(lt) if len(lt)>5: print('YES') print(lt[0], end =' ') print(lt[1]*lt[2], end =' ') print(int(p[0]/(lt[0]*lt[1]*lt[2]))) if len(lt)<3: print('NO') continue if len(lt)==3: if (lt[0]==lt[1] or lt[1]==lt[2] or lt[0]==lt[2]): print('NO') continue else: print('YES') print(lt[0], end=' ') print(lt[1], end=' ') print(lt[2]) continue if len(lt)==4: a=lt[0] b=lt[1]*lt[2] c=lt[3] if a!=b and b!=c and c!=a: print('YES') print(a, end =' ') print(b, end =' ') print(c) continue else: print('NO') continue if len(lt)==5: if len(set(lt))==1: print('NO') continue if len(set(lt))==2: if lt[0]==lt[1]==lt[2]==lt[3]: print('YES') print(lt[0], end =' ') print(lt[0]**3, end =' ') print(lt[-1]) continue elif lt[0]==lt[1]==lt[2] and lt[3]==lt[4]: print('YES') print(lt[0], lt[1]*lt[2], lt[3]*lt[4]) elif lt[0]==lt[1]and lt[2]==lt[3]==lt[4]: print('YES') print(lt[0]**2, lt[2], lt[2]**2) else: print('YES') print(lt[0], end =' ') print(lt[1]**3, end =' ') print(lt[1]) continue if len(set(lt))==3: if lt[0]==lt[1]==lt[2]: print('YES') print(lt[0]**3, lt[-2], lt[-1]) continue if lt[1]!=lt[0] and lt[2]==lt[1] and lt[3]==lt[4]: print("YES") print(lt[0], lt[1]*lt[2], lt[3]*lt[4]) continue if lt[0]==lt[1] and lt[3]==lt[4]: print('YES') print(lt[0]*lt[1], lt[2], lt[3]*lt[4]) continue if lt[0]==lt[1] and lt[3]==lt[2]: print("YES") print(lt[0]*lt[1], lt[2]*lt[3], lt[4]) if lt[1]==lt[2]==lt[3]: print('YES') print(lt[0], lt[1]**3, lt[-1]) continue if lt[-1]==lt[-2]==lt[-3]: print('YES') print(lt[0], lt[1], lt[2]**3) continue if len(set(lt))==4: print('YES') print(lt[0], lt[2]*lt[1], lt[3]*lt[4]) continue if len(set(lt))==5: print('YES') print(lt[0],lt[1], lt[2]*lt[3]*lt[4])
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from collections import Counter def min_del(n, mn): for x in range(max(2, mn), int(n ** .5) + 1): if n % x == 0: return x return n for _ in range(int(input())): n = int(input()) a = min_del(n, 1) ab = n // a b = min_del(ab, a + 1) c = n // b // a if c != a and c != b and c > 1: print("YES") print(a, b, c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; while (t--) { long long n, a = 2, b = 1, c = 1, t, cnt = 0; cin >> n; t = n; while (cnt < 2 && n > 1) { if (n % a == 0) { if (cnt == 0) { b = a; } else { c = a; } n = n / a; cnt++; a++; } else if (a * a >= n) { break; } else a++; } if (cnt == 2 && c != t / (b * c) && b != t / (b * c) && t / (b * c) != 1) { cout << "YES\n"; cout << b << " " << c << " " << t / (b * c) << endl; } else { cout << "NO\n"; } } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.*; import java.util.*; import java.math.*; import java.lang.*; import static java.lang.Math.*; public class Numbers implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } // if modulo is required set value accordingly public static long[][] matrixMultiply2dL(long t[][],long m[][]) { long res[][]= new long[t.length][m[0].length]; for(int i=0;i<t.length;i++) { for(int j=0;j<m[0].length;j++) { res[i][j]=0; for(int k=0;k<t[0].length;k++) { res[i][j]+=t[i][k]+m[k][j]; } } } return res; } static long combination(long n,long r) { long ans=1; for(long i=0;i<r;i++) { ans=(ans*(n-i))/(i+1); } return ans; } public static void main(String args[]) throws Exception { new Thread(null, new Numbers(),"Numbers",1<<27).start(); } // **just change the name of class from Main to reuquired** public void run() { InputReader sc = new InputReader(System.in); PrintWriter w = new PrintWriter(System.out); int tc=sc.nextInt(); while(tc-->0) { int n=sc.nextInt(); int a=0,b=0,c=0; boolean f=false; outer: for(int i=2;i*i<=n;++i) { if(n%i==0) { int n2=n/i; for(int j=i+1;j*j<=n2;++j) { if(n2%j==0) { c=n2/j; if((i!=c) && (j!=c) && c>=2) { w.println("YES"); w.println(i+" "+j+" "+c); f=true; break outer; } } } } } if(!f) w.println("NO"); } System.out.flush(); w.close(); } } class Factor { int num; int pow; Factor(int n, int p) { num=n; pow=p; } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from itertools import combinations as com from math import sqrt for _ in range (int (input())): k=[] a=int(input()) for i in range (2,int(sqrt(a))+1): if a%i ==0: if a//i==i: k.append(i) else: k.append(i) k.append(a//i) if(len(k)<3): print("NO") else: p=com(k,3) for i in p : if i[0]*i[1]*i[2]==a: print("YES") print(i[0],i[1],i[2]) break else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt n=int(input()) for i in range(n): m=int(input()) m1=m c=2 p=[] while len(p)<3 and c<=sqrt(m1): if m%c==0: m=m//c p.append(c) else: if c==2: c=c+1 else: c=c+2 if len(p)==3: if p[0]==p[1]: p[1]=p[1]*p[2] p[2]=m1//p[0]//p[1] if len(p)==2: p.append(m1//p[0]//p[1]) if len(p)==3 and p[2]>1 and p[0]!=p[2] and p[1]!=p[2] and p[0]!=p[1]: print ('YES') print (*p) else: print ('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin, stdout from collections import defaultdict import math rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() def main(): cases = int(input()) for line in stdin: n = int(line) ans = [] f1 = 2 while f1 <= math.sqrt(n): if n % f1 == 0: ans.append(f1) break f1 += 1 if len(ans) == 0: stdout.write("NO\n") continue m = n//f1 f2 = f1 + 1 while f2 <= math.sqrt(m): if m % f2 == 0: ans.append(f2) break f2 += 1 if len(ans) == 1: stdout.write("NO\n") continue f3 = n//(f1*f2) if f3 not in {f1, f2}: stdout.write("YES\n") stdout.write(" ".join((str(x) for x in [f1, f2, f3]))) stdout.write("\n") else: stdout.write("NO\n") if __name__ == "__main__": main()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
/*package whatever //do not write package name here */ import java.util.*; public class Main { public static void main (String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); for(int tt=0;tt<t;tt++) { int n = s.nextInt(); int no = 0; ArrayList<Integer> x = new ArrayList<>(); for(int i=2;i<=Math.sqrt(n);i++) { if( n%i==0 ) { x.add(i); no++; n = n/i; if(no==2) break; } } if(n!=1&&no==2 && n!=x.get(0) && n!=x.get(1) ) { System.out.println("YES"); System.out.println( x.get(0) + " " + x.get(1) + " " + n ); } else System.out.println("NO"); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin from functools import reduce def solve(): for _ in range(int(stdin.readline())): n=int(stdin.readline()) #a=list(set(reduce(list.__add__,([i,n//i]for i in range(1,int(n**(.5))+1) if n%i==0)))) flag,a1,a2,a3,tmp=0,0,0,0,0 for i in range(2,int(n**.5)+1): if flag==1: break if n%i==0: tmp=n//i a1=i for j in range(2,int((tmp)**.5)+1): if tmp%j==0: a2=j a3=tmp//j if a1!=a2 and a2!=a3 and a3!=a1: flag=1 break if flag==1: print('YES') print(a1,a2,a3,sep=' ') else: print('NO') solve()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#Author: ghoshashis545 -Ashis Ghosh from __future__ import division, print_function import os,sys from io import BytesIO, IOBase from math import ceil,sqrt if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().strip().split(" ")) def li(): return list(mi()) mod=1000000007 #mod=998244353 inf = float("inf") vow=['a','e','i','o','u'] dx,dy=[-1,1,0,0],[0,0,1,-1] def getKey(item): return item[0] def sort2(l):return sorted(l, key=getKey) def d2(n,m,num):return [[num for x in range(m)] for y in range(n)] def isPowerOfTwo (x): return (x and (not(x & (x - 1))) ) def decimalToBinary(n): return bin(n).replace("0b","") def ntl(n):return [int(i) for i in str(n)] abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} abc='abcdefghijklmnopqrstuvwxyz' def powerMod(x,y,p): res = 1 x %= p while y > 0: if y&1: res = (res*x)%p y = y>>1 x = (x*x)%p return res def gcd(x, y): while y: x, y = y, x % y return x def isPrime(n) : # Check Prime Number or not if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True def fact(n): f=1 for i in range(1,n+1): f*=i return f def f(n): a=[] a.append(1) for i in range(2,int(sqrt(n))+1): if(n%i==0): if(i==n//i): a.append(i) else: a.append(i) a.append(n//i) return a '''''''''''''''''''''''''''''''''''''''''''''''''''''' t=ii() while(t): t-=1 n=ii() f=0 for i in range(2,int(sqrt(n))+1): if(n%i==0): a=[] a.append(i) x=n//i for j in range(2,int(sqrt(x))+1): if(x%j==0 and j not in a): a.append(j) a.append(x//j) if(len(set(a))==3): print("YES") print(*a) f=1 break if(f==1): break a=[] a.append(n//i) x=i for j in range(2,int(sqrt(x))+1): if(x%j==0 and j not in a): a.append(j) a.append(x//j) if(len(set(a))==3): print("YES") print(*a) f=1 break if(f==1): break if(f==0): print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for i in range(t): count = 0 flag = 0 a = [] n = int(input()) for j in range(2,int(n**0.5)+1): if (count == 2 and n < j): print("NO") flag = 1 break elif (count == 2 and n>j): print("YES") for x in a: print(x,end = " ") print(int(n)) count = count + 1 break elif(count == 2 and n == j): if j in a: print("NO") flag = 1 break else: print("YES") for x in a: print(x,end = " ") print(int(n)) count = count + 1 break if( n % j == 0): if j not in a: n = n/j count += 1 a.append(j) if (count <=2 and flag == 0): print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; while (n--) { int flag = 0; long long int q; cin >> q; for (long int i = 2; i <= sqrt(q); i++) { if (q % i == 0) { for (long int j = i + 1; j <= sqrt(q / i); j++) { if ((q / i) % j == 0 && j != ((q / i) / j)) { flag = 1; cout << "YES" << endl; cout << i << " " << j << " " << (q / i) / j << endl; break; } } if (flag == 1) break; } } if (flag == 0) cout << "NO" << endl; } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys from math import sqrt input=sys.stdin.readline f=lambda :list(map(int, input().split())) for _ in range(int(input())): n=int(input()) a=0 for i in range(2, int(sqrt(n))+1): if n%i==0: a=i break b=0 if a: for i in range(a+1, int(sqrt(n//a))+1): if (n//a)%i==0: b=i break c=0 if b and n%(a*b)==0: c=n//(a*b) if c and c!=1 and c!=a and c!=b: print('YES\n', a, b, c) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for i in range(int(input())): n = int(input()) ans1 = 1 ans2 = 1 ans3 = 1 p = 2 while n % p == 0: if ans1 == 1: ans1 *= p elif ans2 == 1 or ans2 == ans1: ans2 *= p else: ans3 *= p n //= p p = 3 while p <= n ** 0.5: while n % p == 0: if ans1 == 1: ans1 *= p elif ans2 == 1 or ans2 == ans1: ans2 *= p else: ans3 *= p n //= p p += 2 if n != 1: if ans1 == 1: ans1 *= n elif ans2 == 1 or ans2 == ans1: ans2 *= n else: ans3 *= n if ans1 != 1 and ans2 != 1 and ans3 != 1: if ans1 != ans2 and ans1 != ans3 and ans2 != ans3: print('YES') print(ans1, ans2, ans3) else: print('NO') else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt t = int(input()) for _ in range(t): n = int(input()) ans = [] for i in range(2, int(sqrt(n))+1): if len(ans) == 2 and n>ans[-1]: ans.append(n) n = 1 break elif n%i==0: ans.append(i) n//=i if n==1: break if len(ans) and n<=ans[-1]: break if n!=1 or len(ans)<3: print("NO") else: print("YES") prod = 1 for i in range(2, len(ans)): prod*=ans[i] print(ans[0], ans[1], prod)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; vector<int> printDivisors(int n) { vector<int> v; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) v.push_back(i); else { v.push_back(n / i); v.push_back(i); } } } return v; } int main() { int t; cin >> t; for (int i = 0; i < t; i++) { int n; cin >> n; bool p = false; vector<int> v = printDivisors(n); sort(v.begin(), v.end()); for (int r = 0; r < v.size(); r++) { int j = v.at(r); int n1 = n / j; for (int k = 2; k <= sqrt(n1); k++) { if (n1 % k == 0) { if (n1 / k == k) continue; else { if (j != k && j != n1 / k) { cout << "YES" << endl; cout << j << " " << k << " " << n1 / k << endl; p = true; break; } } } } if (p) break; } if (!p) cout << "NO" << endl; } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
rr = raw_input rri = lambda: int(raw_input()) rrm = lambda: map(int, raw_input().split()) MOD = 10 ** 9 + 7 INF = float('inf') NINF = float('-inf') YES, NO = "YES", "NO" ## def factorize(n): d = 2 facs = [] while d * d <= n: e = 0 while n % d == 0: n //= d e += 1 if e: facs.append((d,e)) d += 1 if d==2 else 2 if n > 1: facs.append((n,1)) return facs def solve(N): # 2 <= a,b,c and abc = n or no # a,b,c distinct facs = factorize(N) if len(facs) >= 3: a = facs[0][0] ** facs[0][1] b = facs[1][0] ** facs[1][1] c = 1 for i in range(2, len(facs)): c *= facs[i][0] ** facs[i][1] return a,b,c if len(facs) == 1: p,e = facs[0] if e < 6: return None a,b,c= p, p*p, p**(e-3) return a,b,c (p1,e1),(p2,e2) = facs if e1 == e2 == 1: return None a = p1 b = p2 c = p1**(e1-1) c *= p2 **(e2-1) if a != b != c != a: return a,b,c return None ## T = rri() for tc in xrange(T): ans = solve(rri()) if ans is None: print NO else: print YES print "{} {} {}".format(*ans)
PYTHON
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math from operator import mul from functools import reduce def isPrime(n) : # Corner cases if (n <= 1) : return False if (n <= 3) : return True # This is checked so that we can skip # middle five numbers in below loop if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True T = int(input()) for _ in range(T): N = int(input()) n = N zz = False for i in range(2, math.floor(n**.5) + 1): if n % i == 0: n = n//i for j in range(2, math.floor(n**.5) + 1): if n % j == 0 and j != i: n = n//j if n != i and n != j and n > 1: print ('YES') print ('{} {} {}'.format(i, j, n)) zz=True break if zz: break if zz: continue print ('NO') ''' # find the prime divisors of n exp = [] while n > 1: for m in range(2, n + 1): if isPrime(m) and (n % m) == 0: e = 1 while True: if n % m**e == 0: e += 1 else: exp.append((m, e - 1)) break break n = n//(m**(e - 1)) if len(exp) >= 3: break abc = [] if len(exp) >= 3: print ('YES') # abc.append(exp[0][0]) abc.append(exp[1][0]) abc.append(N//(abc[0]*abc[1])) print (' '.join(map(str, abc))) continue if len(exp) == 2: if sum([j for i, j in exp]) >= 4: print ('YES') # abc.append(exp[0][0]) abc.append(exp[1][0]) abc.append(N//(abc[0]*abc[1])) print (' '.join(map(str, abc))) continue if len(exp) == 1: if sum([j for i, j in exp]) >= 6: print('YES') abc.append(exp[0][0]) abc.append(exp[0][0]**2) abc.append(N//(abc[0]*abc[1])) print (' '.join(map(str, abc))) continue print ('NO') '''
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
// Working program using Reader Class // Probably fastest import java.io.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; import java.util.StringTokenizer; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Random; import java.util.StringTokenizer; import java.util.List; import java.util.Collections; import java.util.Map; import java.util.HashMap; import java.util.Comparator; import java.util.stream.IntStream; import java.util.ArrayDeque; import java.util.Set; import java.util.HashSet; import java.util.PriorityQueue; public class Main1 { private static PrintWriter out = new PrintWriter(System.out); // private static Scanner sc = new Scanner(System.in); public static void main(String[] args) { int t = fs.nextInt(); outer :while(t-->0) { List<Integer> list = new ArrayList<>(); // Set<Integer> set = new HashSet<>(); int n = fs.nextInt(); int n1 =n; int count =0; // int arr[] = new int [1001]; int res[] = new int[2]; int kl = 0; // int res[] = new int[2]; for(int i=2;i*i<=n;i++) { if(n%i==0 &&kl<2) { count++; res[kl] = i; // System.out.println(i); kl++; } while(n%i==0) { list.add(i); n/=i; } } if(n>1) { if(kl==1 && n != res[kl-1]) { res[kl] = n; count++; } list.add(n); } if(list.size()>=6) { out.println("YES"); int m = list.size(); int a1 = list.get(m-1); int b1 = list.get(m-2)*list.get(m-3); int c1 =1; for(int i=0;i<(m-3);i++) c1 *= list.get(i); out.println(a1+" "+b1+" "+c1); } else if(count>=2) { int a = res[0]; int b = res[1]; // System.out.println(a+" "+b); if(n1%(a*b)==0 && (n1/(a*b)) !=a && (n1/(a*b)) !=b && (n1/(a*b)) !=1) { out.println("YES"); out.println(a+" "+b+" "+(n1/(a*b))); } else out.println("NO"); } else out.println("NO"); } out.close(); } interface Input { public String next(); public String nextLine(); public int nextInt(); public long nextLong(); public double nextDouble(); } static class StdIn implements Input { final private int BUFFER_SIZE = 1 << 16; final private int STRING_SIZE = 1 << 11; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public StdIn() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public StdIn(String filename) { try{ din = new DataInputStream(new FileInputStream(filename)); } catch(Exception e) { throw new RuntimeException(); } buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String next() { byte[] buf = new byte[STRING_SIZE]; // string length int cnt = 0, c; while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r')); while (c != -1) { if (c == ' ' || c == '\n'||c=='\r') break; buf[cnt++] = (byte) c; c=read(); } return new String(buf, 0, cnt); } public String nextLine() { byte[] buf = new byte[STRING_SIZE]; // line length int cnt = 0, c; while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r')); while (c != -1) { if (c == '\n'||c=='\r') break; buf[cnt++] = (byte) c; c = read(); } return new String(buf, 0, cnt); } public int nextInt() { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public int[] readIntArray(int n) { int[] ar = new int[n]; for(int i=0; i<n; ++i) ar[i]=nextInt(); return ar; } public long nextLong() { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() { try{ if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } catch(IOException e) { throw new RuntimeException(); } } public void close() throws IOException { if (din == null) return; din.close(); } } private static StdIn fs = new StdIn(); }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def primeFactors(n): temp = [] while n % 2 == 0: temp.append(2) n = n / 2 for i in range(3, int(math.sqrt(n))+1,2): while n % i== 0: temp.append(i) n = n / i if n > 2: temp.append(int(n)) return temp t = int(input()) while t: t += -1 n = int(input()) prime = primeFactors(n) if len(prime) < 3: print("NO") else: prime.sort() ans = [prime[0]] if prime[0] == prime[1]: ans.append(prime[1] * prime[2]) p = 1 for i in range(3, len(prime)): p *= prime[i] if p != 1: ans.append(p) if len(set(ans)) != 3: print("NO") else: print("YES") print(*ans) else: ans.append(prime[1]) p = 1 for i in range(2, len(prime)): p *= prime[i] if p != 1: ans.append(p) if len(set(ans)) != 3: print("NO") else: print("YES") print(*ans)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long MX = 2e5 + 5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int tc; cin >> tc; while (tc--) { int n; cin >> n; vector<int> v; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { v.push_back(i); n = n / i; break; } } for (int i = 2; i * i <= n; i++) { if (n % i == 0 && i != v[0] && i != n / i) { v.push_back(i); v.push_back(n / i); break; } } if (v.size() == 3) cout << "YES\n" << v[0] << ' ' << v[1] << ' ' << v[2] << endl; else cout << "NO\n"; } cerr << "\ntime taken : " << (float)clock() / CLOCKS_PER_SEC << " secs\n"; return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
// package Contest1294; import java.util.*; import java.lang.*; import java.io.*; public class C { private static FastReader fr; private static OutputStream out; private static int mod = (int)(1e9+7); private void solve() { int t = fr.nextInt(); while(t-- > 0) { long n = fr.nextLong(); ArrayList<Long> factors = factors(n); if(factors.size() < 3) { println("NO"); continue; } Collections.sort(factors); boolean bool = false; long a = factors.get(0); long b = 1; long c = 1; // for(long val: factors) { // print(val + " "); // } for(int i=1;i<factors.size();i++) { b = factors.get(i); if(n % (b * a) == 0) { c = n / (a * b); }else { c = 1; } if(a > 1 && b > 1 && c > 1 && a != b && a != c && b != c && a * b * c == n) { bool = true; break; } } if(bool) { println("YES"); println(a + " " + b + " " + c); }else { println("NO"); } } } public ArrayList<Long> factors(long num){ ArrayList<Long> arr = new ArrayList<>(); for(long i=2;i*i<=num;i++) { if(num % i == 0) { arr.add(i); if(num / i != i) { arr.add(num / i); } } } return arr; } public static void main(String args[]) throws IOException{ new C().run(); } private ArrayList<Integer> factors(int n, boolean include){ ArrayList<Integer> factors = new ArrayList<>(); if(n < 0) return factors; if(include) { factors.add(1); if(n > 1) factors.add(n); } int i = 2; for(;i*i<n;i++) { if(n % i == 0) { factors.add(i); factors.add(n / i); } } if(i * i == n) { factors.add(i); } return factors; } private ArrayList<Integer> PrimeFactors(int n) { ArrayList<Integer> primes = new ArrayList<>(); int i = 2; while (i * i <= n) { if (n % i == 0) { primes.add(i); while (n % i == 0) { n /= i; } } i++; } if (n > 1) { primes.add(n); } return primes; } private boolean isPrime(int n) { if(n == 0 || n == 1) { return false; } if(n % 2 == 0) { return false; } for(int i=3;i*i<=n;i+=2) { if(n % i == 0) { return false; } } return true; } private ArrayList<Integer> Sieve(int n){ boolean bool[] = new boolean[n+1]; Arrays.fill(bool, true); bool[0] = bool[1] = false; for(int i=2;i*i<=n;i++) { if(bool[i]) { int j = 2; while(i*j <= n) { bool[i*j] = false; j++; } } } ArrayList<Integer> primes = new ArrayList<>(); for(int i=2;i<=n;i++) { if(bool[i]) primes.add(i); } return primes; } private HashMap<Integer, Integer> addToHashMap(HashMap<Integer, Integer> map, int arr[]){ for(int val: arr) { if(!map.containsKey(val)) { map.put(val, 1); }else { map.put(val, map.get(val) + 1); } } return map; } private int factorial(int n) { long fac = 1; for(int i=2;i<=n;i++) { fac *= i; fac %= mod; } return (int)(fac % mod); } private static int pow(int base,int exp){ if(exp == 0){ return 1; }else if(exp == 1){ return base; } int a = pow(base,exp/2); a = ((a % mod) * (a % mod)) % mod; if(exp % 2 == 1) { a = ((a % mod) * (base % mod)); } return a; } private static int gcd(int a,int b){ if(a == 0){ return b; } return gcd(b%a,a); } private static int lcm(int a,int b){ return (a * b)/gcd(a,b); } private void run() throws IOException{ fr = new FastReader(); out = new BufferedOutputStream(System.out); solve(); out.flush(); out.close(); } private static class FastReader{ private static BufferedReader br; private static StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); out = new BufferedOutputStream(System.out); } public String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } public char[] nextCharArray() { return next().toCharArray(); } public int[] nextIntArray(int n) { int arr[] = new int[n]; for(int i=0;i<n;i++) { arr[i] = nextInt(); } return arr; } public long[] nextLongArray(int n) { long arr[] = new long[n]; for(int i=0;i<n;i++) { arr[i] = nextLong(); } return arr; } public String[] nextStringArray(int n) { String arr[] = new String[n]; for(int i=0;i<n;i++) { arr[i] = next(); } return arr; } } public static void print(Object str) { try { out.write(str.toString().getBytes()); } catch (IOException e) { e.printStackTrace(); } } public static void println(Object str) { try { out.write((str.toString() + "\n").getBytes()); } catch (IOException e) { e.printStackTrace(); } } public static void println() { println(""); } public static void printArray(Object str[]){ for(Object s : str) { try { out.write(str.toString().getBytes()); } catch (IOException e) { e.printStackTrace(); } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; public class vc2 { // public static int[]arr=new int[100001]; public static void main(String[] args) { Scanner scn=new Scanner(System.in); int t=scn.nextInt(); // prime(); while(t-- !=0) { int n=scn.nextInt(); int i=2; boolean found=false; int count=0;int[]a=new int[2]; for(;i<Math.sqrt(n) && !found;i++) { if(n%i==0) { int m=n/i; for(int j=i+1;j<Math.sqrt(m);j++) { if(m%j==0) { System.out.println("YES"); System.out.println(i+" "+j+" "+(m/j)); found=true; break; } } } } if(!found) System.out.println("NO"); } } // public static void prime() { // for(int i=2;i<100000;i++) { // if(arr[i]==0) { // for(int j=i+1;j<100000;j++) { // if(j%i==0 && arr[j]==0) // arr[j]=i; // } // } // } // } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t=int(input()) for i in range(0,t): n=int(input()) n1=0 n2=0 n3=0 for j in range(2,int(math.ceil((math.sqrt(n))))): if n%j==0: n1=j n3=n/j break else: continue z=0 for j in range(n1+1,(int(math.ceil((math.sqrt(n3)))))): if n3%j==0 and j!=n3/j and (n3/j)!=n1: z=1 n2=j n3=int(n3/j) break else: continue if z==0: print("NO") else: print("YES") print(n1,n2,n3)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; long long myCeil(long long num, long long divider) { long long result = num / divider; if ((result * divider) == num) return result; return result + 1; } long long gcd(long long a, long long b) { if (!b) return a; return gcd(b, a % b); } int main() { ios_base::sync_with_stdio(false); long long tt; cin >> tt; while (tt--) { long long n; cin >> n; long long limit = sqrt(n) + 1; vector<long long> V; long long tempN = n; for (long long i = 2; i <= limit; i++) { if (tempN % i == 0) { V.push_back(i); tempN /= i; if (V.size() == 2) { V.push_back(tempN); break; } } } if (V.size() == 3) { if (V[1] < V[2]) { cout << "YES" << "\n"; for (long long i = 0; i < 3; i++) { cout << V[i] << " "; } cout << "\n"; continue; } } cout << "NO" << "\n"; } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> int main() { long long int n, t, m, i, a, b, c, k; scanf("%lld", &t); for (m = 1; m <= t; m++) { k = 0; scanf("%lld", &n); for (i = 2; i <= sqrt(n); i++) { if (n % i == 0) { a = i; n = n / i; k++; break; } } if (k > 0) { for (i = a + 1; i <= sqrt(n); i++) { if (n % i == 0) { break; } } if (i != n / i && n / i != a && i * (n / i) == n && n / i != 1) { b = i; c = n / i; printf("YES\n"); printf("%lld %lld %lld\n", a, b, c); } else { printf("NO\n"); } } if (k == 0) { printf("NO\n"); } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for y in range(t): n = int(input()) i = 2 a = n ans = [] while(i*i <= n): if(a%i == 0): ans.append(i) a //= i i += 1 if len(ans) == 2: break if(len(ans) != 2): print("NO") elif(a == ans[0] or a == ans[1]): print("NO") else: print("YES") print(ans[0],ans[1],a)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys from collections import defaultdict import math dic=defaultdict(int) t=int(sys.stdin.readline()) for _ in range(t): dic=defaultdict(int) m=int(sys.stdin.readline()) d=m l=[] while m%2==0: m=m//2 dic[2]+=1 #print(m,'mm') for i in range(3,int(math.sqrt(d))+1,2): #print(i,m) while m%i==0: #print('yes',i) dic[i]+=1 m=m//i if m>2: dic[m]+=1 #print(dic,'dic') if len(dic)>=3: print("YES") l=[] for i in dic: l.append(i) if len(l)==2: break l.append(d//(l[0]*l[1])) print(*l) elif len(dic)==2: a=[] for i in dic: a.append(i) z=True if dic[a[0]]>2 and z: l=[a[0],a[0]**(dic[a[0]]-1)] l.append(d//(l[0]*l[1])) print("YES") print(*l) z=False elif dic[a[1]]>2 and z: l=[a[1],a[1]**(dic[a[1]]-1)] l.append(d//(l[0]*l[1])) print("YES") print(*l) z=False elif dic[a[1]]==dic[a[0]]==2 and z: l=[a[0],a[1],a[0]*a[1]] print("YES") print(*l) z=False else: print("NO") elif len(dic)==1: for i in dic: if dic[i]>5: print("YES") l=[i,i**2,d//(i**3)] print(*l) else: print("NO") else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; import java.io.*; import java.math.*; import javafx.util.Pair; public class Fff { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException { BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); StringBuffer out = new StringBuffer(); int t=Integer.parseInt(bf.readLine()); while (t-- > 0) { int n = Integer.parseInt(bf.readLine()); ArrayList<Integer> al = new ArrayList(); StringBuffer out1 = new StringBuffer(); for (int i = 2; i * i <= n; i++) { if (n % i == 0) { al.add(i); al.add(n / i); } } Collections.sort(al); boolean tf=false; for (int k = 0; k < al.size(); k++) { int x = al.get(k); for (int j = 2; j*j <= x; j++) { if (x % j == 0) { if (x / j != j&& x / j != al.get(al.size()-k-1)&&al.get(al.size()-k-1)!=j) { out1.append((x/j)+" "+ j +" "+ al.get(al.size()-k-1)); tf=true;break;} } }if(tf){break;} } if(!tf){out.append("NO\n");} else{out.append("YES\n"+out1+"\n");} } System.out.print(out); } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, i, x = 0, y = 0, j; cin >> n; for (i = 2; i <= sqrt(n); i++) { if (n % i == 0) { x = i; n /= i; for (j = i + 1; j <= sqrt(n); j++) { if (n % j == 0) { y = j; n /= j; break; } } if (x != 0 && y != 0) break; } } if (x != 0 && y != 0 && x != y && y != n && n != x) cout << "YES" << endl << x << " " << y << " " << n << endl; else cout << "NO" << endl; } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> const long long int mod = 1e9 + 7; const long long int INF = 10000000000000; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int t = 0; cin >> t; while (t--) { long long int n = 0; cin >> n; long long int tn = n; vector<long long int> fac; for (long long int i = 2; i * i <= n; ++i) { if (n % i == 0) { fac.push_back(i); n /= i; } } fac.push_back(n); long long int p = 1; if (fac.size() < 3) cout << "NO\n"; else { for (long long int i = 3; i < fac.size(); ++i) { fac[2] *= fac[i]; } if ((fac[0] == fac[1]) || (fac[1] == fac[2]) || fac[2] == fac[0]) cout << "NO\n"; else { cout << "YES\n"; cout << fac[0] << " " << fac[1] << " " << fac[2] << "\n"; } } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys from collections import defaultdict from math import sqrt input=sys.stdin.readline for _ in range(int(input())): n=int(input()) nn=n d=defaultdict(int) while n%2==0: d[2]+=1 n//=2 for i in range(3,int(sqrt(n))+1,2): while n%i==0: d[i]+=1 n//=i if n>1: d[n]=1 if len(d)==1 and sum(d.values())<6: print("NO") continue if len(d)==1: a=list(d.keys())[0] b=a*2 c=nn//(a*b) print("YES") print(a,b,c) continue if len(d)==2 and sum(d.values())<4: print("NO") continue x=list(d.keys()) a=x[0] b=x[1] c=nn//(a*b) print("YES") print(a,b,c)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# Why do we fall ? So we can learn to pick ourselves up. from functools import reduce def factors(n): k = sorted(list(set(reduce(list.__add__, ([i,n//i] for i in range(1,int(n**0.5+1)) if n%i == 0))))) return k[1:] def solve(): n = int(input()) f = factors(n) if len(f) < 3: print('NO') else: sss = 'NO' a, b, c = -1, -1, -1 for i in range(0, len(f)): for j in range(i + 1, len(f)): temp = n // f[i] temp //= f[j] if temp in f and temp != f[i] and temp != f[j]: a, b, c = f[i], f[j], temp sss = 'YES' break if sss == 'YES': break if sss == 'YES': print(sss) print(a, b, c) else: print(sss) t = int(input()) for _ in range(0,t): solve()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from collections import Counter def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) a = Counter(a) return a t = int(input()) for i in range(t): n = int(input()) a = prime_factorize(n) flag = True ans = "" if len(a.keys()) == 1: for k, v in a.items(): if v <= 5: flag = False else: ans = "{} {} {}".format(k, k**2, k**(v-3)) elif len(a.keys()) == 2: v_pair = [] vk_pair = [] for k, v in a.items(): v_pair.append(v) vk_pair.append((v, k)) if max(v_pair) >= 3 or (v_pair[0] >= 2 and v_pair[1] >= 2): ans = "{} {} {}".format( vk_pair[0][1], vk_pair[1][1], vk_pair[0][1] ** (vk_pair[0][0] - 1) * vk_pair[1][1] ** (vk_pair[1][0] - 1)) else: flag = False else: b = 1 for j, (k, v) in enumerate(a.items()): if j <= 1: ans += "{} ".format(str(k ** v)) else: b *= k ** v ans += "{}".format(b) if flag: print("YES") print(ans) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def printDivisors(n) : i = 2 factors = {} while i <= math.sqrt(n): if (n % i == 0) : if (n // i == i) : factors[i] = 1 else : factors[n//i] = 1 factors[i] = 1 i = i + 1 return factors for t in range(int(input())): n = int(input()) f = printDivisors(n) factors = list(f.keys()) factors.sort() if len(factors) < 3: print('NO') else: i = 1 flag = False while i < len(factors)//2: temp = factors[0]*factors[i] try: x = f[temp] if n//temp != factors[0] and n//temp != factors[i]: print('YES') print(factors[0],factors[i],n//temp) flag = True break else: i += 1 except KeyError: i += 1 if not(flag): print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t = int(input()) for _ in range(t): n = int(input()) a = [] count = 0 for i in range(2, int(math.sqrt(n))): if n%i==0: n = n//i a.append(i) count += 1 if count == 2: break if count == 2 and a[1]!=n and a[0]!=n and n!=1: print("YES") print(a[0], a[1], n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math n = int(input()) Resulting_bool_list = [] Resulting_factor_list = [] for i in range(0,n): factor_list = [] temp = [] num = int(input()) lim = math.floor(math.sqrt(num)) for i in range(2,lim+1): if num % i == 0: factor_list.append(i) len_ = len(factor_list) if len_ < 3: Resulting_bool_list.append('NO') Resulting_factor_list.append([]) else: Resulting_bool_list.append('YES') temp.append(factor_list[0]) num = num / factor_list[0] for j in range(1,len_): if num % factor_list[j] == 0: temp.append(factor_list[j]) temp.append(int(num/factor_list[j])) break Resulting_factor_list.append(temp) for i in range(0,n): if Resulting_bool_list[i] == 'NO': print(Resulting_bool_list[i]) else: print(Resulting_bool_list[i]) for j in Resulting_factor_list[i]: print(j,end=' ') print('')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for i in range(int(input())): n = int(input()) a = [] i=2 while(len(a)<2 and i*i <n): if n%i ==0: n=n//i a.append(i) i+=1 if len(a)==2 and n not in a:print("YES");print(n,*a) else:print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys,math,itertools from collections import Counter,deque,defaultdict from bisect import bisect_left,bisect_right from heapq import heappop,heappush,heapify, nlargest from copy import deepcopy mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split())) def inps(): return sys.stdin.readline() def inpsl(x): tmp = sys.stdin.readline(); return list(tmp[:x]) def err(x): print(x); exit() def prime_factorize(n): if n == 1: return [1] a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a for _ in range(inp()): n = inp() pp = prime_factorize(n) c = Counter(pp) bad = False if (len(c.keys()) == 1 and len(pp)<6) or (len(c.keys())==2 and len(pp)<4): print('NO') else: keys = list(c.keys()) if len(c.keys()) > 1: a = keys[0]; c[keys[0]] -= 1 b = keys[1]; c[keys[1]] -= 1 C = 1 for key in keys: if c[key] == 0: continue C *= key**c[key] else: a = keys[0]*1; b = keys[0]**2 C = keys[0]**(c[keys[0]]-3) print('YES') print(a,b,C)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt for i in range(int(input())): a=int(input()) for j in range (2,int(sqrt(a))+1): if a%j==0: a=a//j for k in range(j+1,int(sqrt(a))+1): if a%k==0: a=a//k if a>k: print("YES") print(j,k,a) break else: print("NO") break else: print("NO") break break else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; public class CSES { static long mod = 1000000007; public static void main(String[] args) throws IOException { FastScanner s=new FastScanner(); int t1 = s.nextInt(); // int t1 =1; while(t1-->0){ long n = s.nextLong(); long a=0,b=0,c=0; for(int i=2;i*i<=n;i++){ if(n%i==0) { if (a == 0 ){ a=i; n/=i; break; } } } for(int i=2;i*i<=n;i++){ if(n%i==0) { if(b==0 && i!=a){ b=i; n/=i; } } } if(a==0 || b==0 || n==1 || n==a || n==b) System.out.println("NO"); else{ System.out.println("YES"); System.out.println(a + " " + b + " " + n); } } } static long gcd(long a, long b)throws IOException{return (b==0)?a:gcd(b,a%b);} static int gcd(int a, int b)throws IOException{return (b==0)?a:gcd(b,a%b);} static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } int[] readArray(int n) { int[] a=new int[n]; for (int i=0; i<n; i++) a[i]=nextInt(); return a; } long nextLong() { return Long.parseLong(next()); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; const int N = (int)998244353; const int M = (int)1000000007; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; cin >> t; for (int j = 0; j < t; j++) { int n, count = 0, b = 0, c = 0, flag = 0; cin >> n; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { c = i; n = n / i; flag = 1; break; } } for (int i = c + 1; i < sqrt(n) + 1 && flag; ++i) { if (n % i == 0) { b = i; n = n / i; break; } } if (n == 0 || b == 0 || c == 0 || b == n || c == n) cout << "NO" << "\n"; else { cout << "YES" << "\n"; cout << c << " " << b << " " << n << "\n"; } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
nn = int(input()) import math def isprime(n): if n <= 7: return False, 1 sqrt = int( math.sqrt(n) ) + 1 for i in range(2, sqrt): if n % i == 0: return True, i return False, 1 def isprime2(n): if n <= 3: return False, 1 sqrt = int( math.sqrt(n) ) + 1 for i in range(2, sqrt): if n % i == 0: return True, i return False, 1 for dfdfdi in range(nn): v = int(input()) if v <= 7: print("NO") continue firstTrue, firstPrime = isprime(v) if not firstTrue: print("NO") continue v = v // firstPrime secondTrue, secondPrime = isprime2(v) if not secondTrue: print("NO") continue final = v // secondPrime if firstPrime == secondPrime or secondPrime == final: thirdTrue, thirdPrime = isprime2(final) if not thirdTrue: print("NO") else: secondPrime *= thirdPrime final = final // thirdPrime #if secondPrime == final: if secondPrime == final or secondPrime == firstPrime or final == firstPrime: print("NO") continue else: print("YES") print(str(firstPrime) + " " + str(secondPrime) + " " + str(final)) else: print("YES") print(str(firstPrime) + " " + str(secondPrime) + " " + str(final))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# -*- coding: utf-8 -*- # @Date : 2020-01-23 16:32:49 # @Author : raj lath ([email protected]) # @Link : link # @Version : 1.0.0 import sys sys.setrecursionlimit(10**5+1) inf = int(10 ** 20) max_val = inf min_val = -inf RW = lambda : sys.stdin.readline().strip() RI = lambda : int(RW()) RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()] RWI = lambda : [x for x in sys.stdin.readline().strip().split()] for _ in range(RI()): inp = RI() answer = [] i = 2 while len(answer) < 2 and i * i < inp: if inp % i == 0: answer.append(i) inp //= i i += 1 if len(answer) == 2 and inp not in answer: print("YES") print(*answer, inp) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math from collections import Counter # def printDivisors(n) : # i = 1 # l = [] # while i <= math.sqrt(n): # if (n % i == 0) : # if (n / i == i) : # l.append(i) # else : # l.append(i) # l.append(n//i) # i = i + 1 # return l def primeFactors(n): l = [] while n % 2 == 0: l.append(2) n = n // 2 for i in range(3,int(math.sqrt(n))+1,2): while n % i == 0: l.append(i) n = n // i if n > 2: l.append(n) return l for _ in range(int(input())): n = int(input()) k = primeFactors(n) # print(*k) klen = len(set(k)) if len(k) < 3: print("NO") elif klen == 3 and len(k) == 3: print("YES") print(*k) elif klen == 2 and len(k) >= 4: print("YES") a = k[0] b = k[-1] c = 1 for t in k[1:len(k)-1]: c *= t print(a, b, c) elif klen >= 3: print("YES") kl = set(k) jk = list(kl) a = jk[0] b = jk[1] x = 1 for t in k: x *= t print(a, b, ((x//a)//b)) elif len(k) >= 6: print("YES") a = k[0] b = k[1]*k[2] c = 1 for t in range(3, len(k)): c *= k[t] print(a, b, c) else: a = k[0] flag = 0 x = 1 for t in k[1::]: x *= t b = -1 c = -1 for t in range(1, len(k)): b = k[t] c = x//k[t] x //= k[t] if a != b and b != c and a != c and a*b*c == n: print("YES") flag = 1 print(a, b, c) break if flag == 0: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def div(n): y=n c=0 ans=[] for i in range(2,int(math.sqrt(n))+1): if y%i==0: c+=1 y=y//i ans.append(i) if c>=2: break print("YES" if c>=2 and y not in ans else "NO") if c>=2 and y not in ans: print(*(ans+[y])) for _ in range(int(input())): n = int(input()) div(n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys from math import sqrt inp = sys.stdin.readline for i in range(int(inp())): n = int(inp()) arr = "" c = 0 flag = 0 for i in range(2, round(sqrt(n))+1): if n % i == 0: c += 1 arr += str(i)+" " n = n//i if c == 2 and n > i: flag = 1 arr += str(n) break if flag: print("YES\n" + arr) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t=int(input()) for i in range(t): s=int(input()) s1=0 d=0 f=0 for j in range(2,int(math.sqrt(s))+1): if s%j==0: s1=j d=s/j for k in range(2,int(math.sqrt(d))+1): if d%k==0: s2=k s3=d/k if s2!=s3 and s3!=s1 and s2!=s1: print("YES") print(int(s1),int(s2),int(s3)) f=1 break if f==1: break for k in range(2,int(math.sqrt(s1))+1): if s1%k==0: s2=k s3=s1/k if s2!=s3 and s3!=d and s2!=d: print("YES") print(int(s1),int(s2),int(s3)) f=1 break if f==1: break if f==0: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for i in range(int(input())): n = int(input()) m = [] i = 2 while i**2 < n and len(m) != 2: if n % i == 0: m.append(i) n = n / i i += 1 if len(m) != 2 or n == 1: print('NO') continue m.append(int(n)) print('YES') for i in m: print(i, end = ' ') print()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> divisors; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { divisors.push_back(i); if (i * i < n) divisors.push_back(n / i); } } divisors.push_back(n); vector<int> ans; int val; for (auto it1 : divisors) { for (auto it2 : divisors) { if (it1 == it2) continue; val = n; val /= it1; val /= it2; if (val >= 2 && ((val * it1) * it2) == n && val != it1 && val != it2) { ans.push_back(it1); ans.push_back(it2); ans.push_back(val); break; } } if (!ans.empty()) break; } if (!ans.empty()) { cout << "YES\n"; for (auto it : ans) cout << it << " "; } else cout << "NO"; cout << "\n"; } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy8[] = {1, -1, 1, -1, 0, 0, -1, 1}; const double PI = acos(-1.0); const double EPS = 1e-6; const int MOD = (int)1e9 + 7; const int maxn = (int)2e5 + 5; const int LOGN = 20; bitset<10000005> isprime; vector<long long> prime; vector<long long> ans; void sieve() { isprime[0] = isprime[1] = 1; prime.push_back(2); for (long long i = 3; i * i <= 10000005; i += 2) { if (!isprime[i]) { for (long long j = i * i; j <= 10000005; j += i + i) { isprime[j] = 1; } } } for (long long i = 3; i <= 10000005; i += 2) { if (!isprime[i]) { prime.push_back(i); } } } int main() { long long a, b, cnt, n, s, t; cin >> t; sieve(); while (t--) { int f = 0; cin >> n; b = n; for (int i = 0; prime[i] * prime[i] <= n && i < prime.size(); i++) { if (n % prime[i] == 0) { while (n % prime[i] == 0) { n /= prime[i]; ans.push_back(prime[i]); } } } if (n != 1) ans.push_back(n); int x = ans[0], y = 1, z = 1, j; for (int i = 1; i < ans.size(); i++) { y *= ans[i]; if (y == x) continue; else { j = i; break; } } for (j++; j < ans.size(); j++) { z *= ans[j]; } if (x != 1 && y != 1 && z != 1 && x != y && x != z && y != z) { cout << "YES" << endl; cout << x << " " << y << " " << z << endl; } else cout << "NO" << endl; ans.clear(); } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def factor(n): s=set() for i in range(2,int(n**0.5)+1): if n%i==0: s.add(i) s.add(n//i) f=list(s) f.sort() return f t=int(input()) while t: t-=1 n=int(input()) f=factor(n) # print(f) b=0 if f: for i in range(len(f)//2): for j in range(i+1,len(f)//2): if n%(f[i]*f[j])==0: l=[f[i],f[j],n//(f[i]*f[j])] if len(set(l))==3: print('YES') print(*l) b=1 break if b:break if b==0: print('NO') else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) import math for i in range(t): n = int(input()) res = [] c = 0 a = 0 q = int(math.sqrt(n)) + 2 for j in range(2,q): if n % j == 0: n = n // j res.append(j) a = j + 1 c += 1 break if c == 1: q = int(math.sqrt(n)) + 2 for j in range(a,q): if n % j == 0: n = n // j res.append(j) c += 1 break if c < 2 or res[0] == n or res[1] == n: print('No') else: print('Yes') print(res[0],res[1],n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
/** * BaZ :D */ import java.util.*; import java.io.*; import static java.lang.Math.*; public class Main { static MyScanner scan; static PrintWriter pw; static long MOD = 1_000_000_007; static long INF = 1_000_000_000_000_000_000L; static long inf = 2_000_000_000; public static void main(String[] args) { new Thread(null, null, "BaZ", 1 << 27) { public void run() { try { solve(); } catch (Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } static void solve() throws IOException { //initIo(true); initIo(false); StringBuilder sb = new StringBuilder(); int t = ni(); while(t-->0) { long n = ni(); long temp = n; ArrayList<Long> primes = new ArrayList<>(); for(long i=2;i*i<=temp;++i) { if(temp%i==0) { primes.add(i); while(temp%i==0) { temp/=i; } } } if(temp>1) { primes.add(temp); } if(primes.size()==1) { long p = primes.get(0); long curr = p; for(int i=2;i<=6;++i) { curr*=p; if(curr>n) { break; } } //pl("curr : "+curr); if(curr<=n) { pl("YES"); pl(p+" "+(p*p)+" "+(n/(p*p*p))); } else { pl("NO"); } } else { long pro = primes.get(0) * primes.get(1); if(n!=pro && n/pro != primes.get(0) && n/pro != primes.get(1)) { pl("YES"); pl(primes.get(0)+" "+primes.get(1)+" "+(n/pro)); } else { pl("NO"); } } } pw.flush(); pw.close(); } static void initIo(boolean isFileIO) throws IOException { scan = new MyScanner(isFileIO); if(isFileIO) { pw = new PrintWriter("/Users/amandeep/Desktop/output.txt"); } else { pw = new PrintWriter(System.out, true); } } static int ni() throws IOException { return scan.nextInt(); } static long nl() throws IOException { return scan.nextLong(); } static double nd() throws IOException { return scan.nextDouble(); } static String ne() throws IOException { return scan.next(); } static String nel() throws IOException { return scan.nextLine(); } static void pl() { pw.println(); } static void p(Object o) { pw.print(o+" "); } static void pl(Object o) { pw.println(o); } static void psb(StringBuilder sb) { pw.print(sb); } static void pa(String arrayName, Object arr[]) { pl(arrayName+" : "); for(Object o : arr) p(o); pl(); } static void pa(String arrayName, int arr[]) { pl(arrayName+" : "); for(int o : arr) p(o); pl(); } static void pa(String arrayName, long arr[]) { pl(arrayName+" : "); for(long o : arr) p(o); pl(); } static void pa(String arrayName, double arr[]) { pl(arrayName+" : "); for(double o : arr) p(o); pl(); } static void pa(String arrayName, char arr[]) { pl(arrayName+" : "); for(char o : arr) p(o); pl(); } static void pa(String listName, List list) { pl(listName+" : "); for(Object o : list) p(o); pl(); } static void pa(String arrayName, Object[][] arr) { pl(arrayName+" : "); for(int i=0;i<arr.length;++i) { for(Object o : arr[i]) p(o); pl(); } } static void pa(String arrayName, int[][] arr) { pl(arrayName+" : "); for(int i=0;i<arr.length;++i) { for(int o : arr[i]) p(o); pl(); } } static void pa(String arrayName, long[][] arr) { pl(arrayName+" : "); for(int i=0;i<arr.length;++i) { for(long o : arr[i]) p(o); pl(); } } static void pa(String arrayName, char[][] arr) { pl(arrayName+" : "); for(int i=0;i<arr.length;++i) { for(char o : arr[i]) p(o); pl(); } } static void pa(String arrayName, double[][] arr) { pl(arrayName+" : "); for(int i=0;i<arr.length;++i) { for(double o : arr[i]) p(o); pl(); } } static class MyScanner { BufferedReader br; StringTokenizer st; MyScanner(boolean readingFromFile) throws IOException { if(readingFromFile) { br = new BufferedReader(new FileReader("/Users/amandeep/Desktop/input.txt")); } else { br = new BufferedReader(new InputStreamReader(System.in)); } } String nextLine()throws IOException { return br.readLine(); } String next() throws IOException { if(st==null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(next()); } long nextLong() throws IOException { return Long.parseLong(next()); } double nextDouble() throws IOException { return Double.parseDouble(next()); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def product(n): for i in range(2,int(n**(1/2))): if n%i==0: for j in range(2,int((n)**(1/2))): if (n//i)%j==0 and j!=i and (n//i)/j!=i and j!=(n//i)**(1/2): print("YES") print(i,j,(n//i)//j) return print("NO") return t=int(input()) a=[] for i in range(t): a.append(int(input())) for x in a: product(x)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# imports """Fill in here""" import math # Set to False for input from standard in debug = False if debug: f = open('test', 'r') else: f = None def line(file): if debug: return file.__next__().strip() return input() # Solve """Fill in here""" # array = [int(i) for i in line(f).split(' ')] # Instead of using input() use line(f) test_cases = int(line(f)) for _ in range(test_cases): n = int(line(f)) def solve(n): throot = int(math.pow(n, 1/3)) + 1 for a in range(2, throot): if n % a == 0: twroot = int(math.sqrt(n / a)) + 1 for b in range(a + 1, twroot): if (n / a) % b == 0: c = int(n / a / b) if c != b: return f'{a} {b} {c}' raise EnvironmentError() try: string = solve(n) print('YES') print(string) except EnvironmentError: print('NO') #### if debug: f.close()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
fast=lambda:stdin.readline().strip() zzz=lambda:[int(i) for i in fast().split()] z,zz=input,lambda:list(map(int,z().split())) szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz()) from re import * from sys import * from math import * from heapq import * from queue import * from bisect import * from string import * from itertools import * from collections import * from math import factorial as f from bisect import bisect as bs from bisect import bisect_left as bsl from collections import Counter as cc from itertools import accumulate as ac def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2)) def output(answer):stdout.write(str(answer)) ###########################---Test-Case---################################# """ If you Know me , Then you probably don't know me ! """ ###########################---START-CODING---############################## num=int(z()) for _ in range( num ): n=int(fast()) x=int(n**.5) lst=[] for i in range(2,x+1): if n%i==0: lst.append(i) n//=i if len(lst)==2: if lst[1]!=n and lst[0]!=n: lst.append(n) break if len(lst)==3: print('YES') print(*lst) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int i, j, t, n; cin >> t; while (t--) { cin >> n; if (n == 1) { cout << "NO" << endl; continue; } int m = n; map<int, int> mp; vector<int> v; for (i = 2; i <= sqrt(n) + 1 && m > 1; i++) { if (m % i == 0) v.push_back(i); else continue; while (m % i == 0) { m /= i; mp[i]++; } } if (m != 1) { v.push_back(m); mp[m]++; } if (v.size() == 0) { cout << "NO" << endl; continue; } if (v.size() > 2) { cout << "YES" << endl; cout << v[0] << " "; n /= v[0]; cout << v[1] << " "; n /= v[1]; cout << n << endl; continue; } if (v.size() == 1) { int x = mp[v[0]]; if (x < 6) { cout << "NO" << endl; continue; } int y = v[0]; n /= pow(y, 3); cout << "YES" << endl; cout << y << " " << y * y << " " << n << endl; continue; } else { int x = mp[v[0]], y = mp[v[1]]; if ((x < 2 && y < 2) || x + y < 4) { cout << "NO" << endl; continue; } cout << "YES" << endl; n /= (v[0] * v[1]); cout << v[1] << " " << v[0] << " " << n << endl; continue; } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys T = int(sys.stdin.readline()) for _ in range(T): n = int(sys.stdin.readline()) res = set() start_i = 2 for _ in range(2): for i in range(start_i, int(n**0.5)+1): if not n%i: n//=i start_i=i+1 res.add(i) break res.add(n) if len(res)==3: print('YES') [print(a, end=' ') for a in res] print() else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys import math import itertools import functools import collections import operator import fileinput import copy ORDA = 97 # a def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return [int(i) for i in input().split()] def lcm(a, b): return abs(a * b) // math.gcd(a, b) def revn(n): return str(n)[::-1] def dd(): return collections.defaultdict(int) def ddl(): return collections.defaultdict(list) def sieve(n): if n < 2: return list() prime = [True for _ in range(n + 1)] p = 3 while p * p <= n: if prime[p]: for i in range(p * 2, n + 1, p): prime[i] = False p += 2 r = [2] for p in range(3, n + 1, 2): if prime[p]: r.append(p) return r def divs(n, start=2): r = [] for i in range(start, int(math.sqrt(n) + 1)): if (n % i == 0): if (n / i == i): r.append(i) else: r.extend([i, n // i]) return r def divn(n, primes): divs_number = 1 for i in primes: if n == 1: return divs_number t = 1 while n % i == 0: t += 1 n //= i divs_number *= t def prime(n): if n == 2: return True if n % 2 == 0 or n <= 1: return False sqr = int(math.sqrt(n)) + 1 for d in range(3, sqr, 2): if n % d == 0: return False return True def convn(number, base): new_number = 0 while number > 0: new_number += number % base number //= base return new_number def cdiv(n, k): return n // k + (n % k != 0) def ispal(s): # Palindrome for i in range(len(s) // 2 + 1): if s[i] != s[-i - 1]: return False return True # a = [1,2,3,4,5] -----> print(*a) ----> list print krne ka new way for i in range(ii()): n = ii() r = sieve(int(n**0.5)) #n = ii() if prime(n): print('NO') continue else: a = [] for i in r: if n% i == 0: a.append(i) n = n//i break i= 2 while i < n**0.5: if n %i == 0 and i not in a: if n//i != i: a.append(i) a.append(n//i) break i += 1 if len(a) == 3: print('YES') print(a[0],a[1],a[2]) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for p in range(int(input())): num=int(input()) b=[] a=num for i in range(2,int(math.sqrt(num))+1): if(len(b)<2): if(a%i==0): b.append(int(i)) a/=i else: break if((a not in b) and (len(b)==2)): print('YES') print(str(b[0])+' '+str(b[1])+' '+str(int(a))) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def pr(a,m): n=len(a) d={} l=[] for i in range(n): d[a[i]]=i c=0 for i in range(n-1): for j in range(i+1,n): if ((a[i]*a[j]<=m) and (a[i]*a[j]!=0) and (m%(a[i]*a[j])==0)): check=m//(a[i]*a[j]) if( check!=1 and check!=a[i] and check!=a[j] and check in d and d[check]>i and d[check]>j): l=[a[i],a[j],check] return l def p(n) : l=[] i = 1 while i <= math.sqrt(n): if (n % i == 0) : if (n / i == i) : if(i!=1): l.append(i) else : if(i!=1): l.append(i) if(n//i!=1): l.append(n//i) i = i + 1 return l for _ in range(int(input())): x=int(input()) l=p(x) l.sort() #print(l,"d") aa=pr(l,x) if(aa==None): print("NO") else: print("YES") aa.sort() print(*aa) #print(aa)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): num = int(input()) done = False for i in range(2, int(num ** (1/3)) + 8): if num % i != 0: continue new_num = num // i for j in range(i + 1, int(num ** .5) + 8): if new_num % j == 0 and new_num // j not in [i, j, 1]: print('YES') print(f'{i} {j} {new_num // j}') done = True break if done: break if not done: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; vector<long long> vec; void primeFactors(long long n) { while (n % 2 == 0) { vec.push_back(2); n = n / 2; } for (long long i = 3; i <= sqrt(n); i = i + 2) { while (n % i == 0) { vec.push_back(i); n = n / i; } } if (n > 2) vec.push_back(n); } int main() { long long t; cin >> t; while (t--) { long long n, i; cin >> n; primeFactors(n); if (vec.size() < 3) { cout << "NO" << endl; } else { set<long long> s; s.insert(vec[0]); long long x = 1; for (i = 1; i < vec.size(); i++) { x *= vec[i]; if (x != vec[0]) break; } s.insert(x); x = (n / x) / vec[0]; if (x != 1) s.insert(x); if (s.size() == 3) { cout << "YES" << endl; for (auto it = s.begin(); it != s.end(); it++) { cout << *it << " "; } cout << endl; } else { cout << "NO" << endl; } } vec.clear(); } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for _ in range(t): n = int(input()) rt = int(n**.5) st = set() flag=0 for i in range(2,rt+1): if(n%i==0): k = n//i v = int(k**.5) for j in range(2,v+1): if(k%j==0 and i!=j): if(k//j!=i and k//j !=j): print("YES") print(i,j,k//j) flag=1 break if(flag==1): break if(flag==0): print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for queries in range(t): n = int(input()) m = n r = 2 array = [] while r <= 25000: if n % r == 0: array.append(r) n //= r r += 1 if len(array) == 2: break if len(array) == 2 and n > array[1]: print("YES") print(array[0],array[1],m//array[0]//array[1]) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class Main { InputStream is; PrintWriter out; String INPUT = ""; void solve() { outer: for(int T = ni(); T > 0; T--) { long n = nl(); long[][] f = factorX(n); for(int i = 0; i < f.length; i++) { if(f[i][0] < 2 || f[i][1] < 2) continue; long[] ret = ok(f[i][0], f[i][1], n); if(ret != null) { if(ret[0] >= 2 && ret[1] >= 2 && ret[2] >= 2) { out.println("YES"); for(int x = 0; x < ret.length; x++) { out.print(ret[x]+" "); } out.println(); continue outer; } } ret = ok(f[i][1], f[i][0], n); if(ret != null) { if(ret[0] >= 2 && ret[1] >= 2 && ret[2] >= 2) { out.println("YES"); for(int x = 0; x < ret.length; x++) { out.print(ret[x]+" "); } out.println(); continue outer; } } } out.println("NO"); } } public long[] ok(long a, long b, long n) { for(long i = 2; i * i <= a; i++) { if(n % i == 0) { if(i * (a / i) * b == n) { if(i != a / i && i != b && a / i != b) return new long[] {i, a / i, b}; } } } return null; } public long[][] factorX(long n) { long[][] f = new long[1000][2]; int p = 0; for(int i = 2; i * i <= n; i++) { if(n % i == 0) { f[p][0] = i; f[p++][1] = n / i; } } return Arrays.copyOf(f, p); } void run() throws Exception { is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes()); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); if (!INPUT.isEmpty()) tr(System.currentTimeMillis() - s + "ms"); } public static void main(String[] args) throws Exception { new Main().run(); } private byte[] inbuf = new byte[1024]; public int lenbuf = 0, ptrbuf = 0; private int readByte() { if (lenbuf == -1) throw new InputMismatchException(); if (ptrbuf >= lenbuf) { ptrbuf = 0; try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); } if (lenbuf <= 0) return -1; } return inbuf[ptrbuf++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } private double nd() { return Double.parseDouble(ns()); } private char nc() { return (char) skip(); } private String ns() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } private char[] ns(int n) { char[] buf = new char[n]; int b = skip(), p = 0; while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b; b = readByte(); } return n == p ? buf : Arrays.copyOf(buf, p); } private char[][] nm(int n, int m) { char[][] map = new char[n][]; for (int i = 0; i < n; i++) map[i] = ns(m); return map; } private int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private int ni() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private long nl() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.Scanner; public class Main { /** * @param args */ public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); doTheTask(n); } } static void doTheTask (int n) { for (int i=2; i*i<=n; i++) { if (n % i == 0) { int d = n/i; for (int j=i+1; j*j<d; j++) { if (d % j == 0) { System.out.printf ("YES\n%d %d %d\n",i,j,d/j); return; } } } } System.out.println ("NO\n"); } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t = int(input()) for _ in range(t): n = int(input()) ul = math.sqrt(n) ul = int(ul) ul += 1 l = [] count = 0 flag = 0 for i in range(2,ul+1): if count == 2: break if n%i==0: l.append(i) count += 1 n = n//i if count == 2 and n not in l and n!=1: print("YES") for i in range(2): print(l[i],end=" ") print(n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import * t=int(input()) for _ in range(t): n=int(input()) c=0 l=[] r=floor(sqrt(n))+1 for i in range(2,r): if n%i==0: l.append(i) c=c+1 n=n//i if c==2: break if len(l)==2: if n==l[0] or n==l[1]: print('NO') else: print('YES') print(l[0],l[1],n) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for x in range(int(input())): n = int(input()) k=0 a=set() for i in range(2,int(n**0.5)+1): if(n%i==0 and k<2): n//=i k+=1 a.add(i) #print(i) if(k==2 and n>1): a.add(n) if(len(a)==3 ): #a.append(n) a=sorted(a) print('YES') print(*a) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def solve(n): a, b, c = None, None, n i = 2 while c >= 2 and i * i <= c: if c % i == 0: c //= i if a is None: a = i elif c >= 2 and len(set((a, i, c))) == 3: return a, i, c i += 1 raise ValueError() for T in range(int(input())): try: a, b, c = solve(int(input())) print('YES') print(a, b, c) except ValueError: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.IOException; import java.util.*; import javax.lang.model.util.ElementScanner6; import java.lang.*; import java.io.*; public class Solution { public static void main(String args[])throws IOException {/* InputStreamReader isr=new InputStreamReader(System.in); BufferedReader br=new BufferedReader(isr); int a=Integer.parseInt(br.readLine());*/ FastReader in=new FastReader(System.in); long n,d,d2,a,b,c; long i,j,k=0; int t=in.nextInt(); for(i=0;i<t;i++) { n=in.nextLong(); d=n; d2=(long)Math.sqrt(n)+1; int fg=0; a=0; b=0; c=0; if(n==3 || n==2 || n==1 || n==0) { System.out.println("NO"); } for(j=2;j<d2;j++) { if(d%j==0 && fg==0) { a=j; fg=1; d=d/a; } else if(d%j==0 && fg==1) { b=j; c=d/b; if(a==c || b==c) { j=a+1; a=0;b=0;c=0; d=n; fg=0; } else { System.out.println("YES"); System.out.println(a+" "+b+" "+c); break; } } else { ; } if(j>=d) { System.out.println("NO"); break; } if(j==d2-1) { if(c==0) System.out.println("NO"); } } } } } class FastReader { byte[] buf = new byte[2048]; int index, total; InputStream in; FastReader(InputStream is) { in = is; } int scan() throws IOException { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) { return -1; } } return buf[index++]; } String next() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) { sb.append((char) c); } return sb.toString(); } String nextLine() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c != 10 && c != 13; c = scan()) { sb.append((char) c); } return sb.toString(); } char nextChar() throws IOException { int c; for (c = scan(); c <= 32; c = scan()) ; return (char) c; } int nextInt() throws IOException { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } long nextLong() throws IOException { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') { c = scan(); } for (; c >= '0' && c <= '9'; c = scan()) { val = (val << 3) + (val << 1) + (c & 15); } return neg ? -val : val; } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def find(num): a=0 b=0 i=2 while (i*i)<=num: if num%i==0: if a==0:a=i elif b==0:b=i num=num//i if a>0 and b>0: return [a,b] i+=1 return None for i in range(int(input())): n=int(input()) A=find(n) if not A or n<=2:print("NO") else: a=A[0] b=A[1] c=a*b if n%a==0 and n//a!=a and n//a!=b and (a*b*(n//a))==n: print("YES") print(a,b,n//a) if n%b==0 and n//b!=a and n//b!=b and (a*b*(n//b))==n: print("YES") print(a,b,n//b) elif n%c==0 and n//c!=a and n//c!=b and (a*b*(n//c))==n: print("YES") print(a,b,n//c) else:print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# -*- coding: utf-8 -*- import sys def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)] def ceil(x, y=1): return int(-(-x // y)) def INT(): return int(input()) def MAP(): return map(int, input().split()) def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)] def Yes(): print('Yes') def No(): print('No') def YES(): print('YES') def NO(): print('NO') # sys.setrecursionlimit(10 ** 9) INF = 10 ** 18 MOD = 10 ** 9 + 7 def factorize(num: int) -> dict: from math import sqrt from collections import Counter d = Counter() for i in range(2, int(sqrt(num))+1): while num % i == 0: num //= i d[i] += 1 if num == 1: break if num != 1: d[num] += 1 return d for _ in range(INT()): N = INT() primes = sorted(factorize(N).items()) ans = [1] * 3 if len(primes) == 1: k, v = primes[0] if v < 6: NO() continue ans[0] = k ans[1] = k ** 2 ans[2] = k ** (v-3) elif len(primes) == 2: k1, v1 = primes[0] k2, v2 = primes[1] if v1 == 1 and v2 <= 2 or v1 <= 2 and v2 == 1: NO() continue ans[0] = k1 ans[1] = k2 ans[2] = k1**(v1-1) * k2**(v2-1) else: for i, (k, v) in enumerate(primes): if i < 2: ans[i] = k ** v else: ans[2] *= k ** v YES() print(*ans)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from collections import defaultdict, deque from itertools import permutations from sys import stdin,stdout from bisect import bisect_left, bisect_right from copy import deepcopy #from random import randint int_input=lambda : int(stdin.readline()) string_input=lambda : stdin.readline() multi_int_input =lambda : map(int, stdin.readline().split()) multi_input = lambda : stdin.readline().split() list_input=lambda : list(map(int,stdin.readline().split())) string_list_input=lambda: list(string_input()) MOD = pow(10,9)+7 import math test = int_input() def solve(n): for i in range(2, int(math.sqrt(n))+1): if(n%i==0): a=i tmp=n//i for j in range(i+1, int(math.sqrt(tmp))+1): if(tmp%j==0 and (tmp//j!=a and tmp//j!=j)): print("YES") print(a,j,tmp//j) return print("NO") return for _ in range(test): n = int_input() solve(n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int pri[100003], top, n; bool ntp[100002]; struct node { int a, b; bool operator<(const node &rhs) const { return b > rhs.b; } }; void euler() { for (int i = 2; i <= 100000; ++i) { if (!ntp[i]) pri[top++] = i; for (int j = 0; j < top && pri[j] * i <= 100000; ++j) { ntp[pri[j] * i] = 1; if (i % pri[j] == 0) break; } } } int main() { ios::sync_with_stdio(false); cin.tie(0); euler(); int t; cin >> t; while (t--) { cin >> n; int bn = n; vector<node> v; int sz = 1; for (int i = 0; i < top && n != 1; ++i) { if (n % pri[i] == 0) { node x; x.a = pri[i]; x.b = 0; while (n % pri[i] == 0) ++x.b, n /= pri[i]; sz *= (x.b + 1); v.push_back(x); } } if (n != 1) { node x; x.a = n; x.b = 1; v.push_back(x); } if (v.size() == 0) { cout << "NO\n"; } else if (v.size() == 1) { if (v[0].b < 6) { cout << "NO\n"; } else { cout << "YES\n"; const int &t = v[0].a; cout << t << ' ' << t * t << ' ' << bn / (t * t * t) << '\n'; } } else if (v.size() == 2) { if (v[0].b + v[1].b < 4) { cout << "NO\n"; } else { cout << "YES\n"; cout << v[0].a << ' ' << v[1].a << ' ' << bn / v[0].a / v[1].a << '\n'; } } else { cout << "YES\n"; cout << v[0].a << ' ' << v[1].a << ' ' << bn / v[0].a / v[1].a << '\n'; } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
/*package whatever //do not write package name here */ import java.io.*; import java.util.*; public class GFG { static String solve(ArrayList<Integer> div,int n) { HashSet<Integer> set=new HashSet<>(); int sz=div.size(); for(int i=0;i<sz;i++) set.add(div.get(i)); for(int i=0;i<sz;i++) { for(int j=i+1;j<sz;j++) { int a=div.get(i); int b=div.get(j); if(a!=b){ int ab=a*b; if(n%ab==0) { int c=n/ab; if(set.contains(c)&&(a!=c)&&(b!=c)) { return "YES\n"+c+" "+a+" "+" "+b; } } } } } return "NO"; } static void findDiv(int n,ArrayList<Integer> div) { int p=(int)Math.sqrt(n); for(int i=2;i<=p;i++) { if(n%i==0) { if(n/i==i) { div.add(i); } else { div.add(n/i); div.add(i); } } } } public static void main (String[] args) throws Exception{ BufferedReader bf=new BufferedReader(new InputStreamReader(System.in)); int t=Integer.parseInt(bf.readLine()); StringBuffer str=new StringBuffer(""); while(t-->0) { int n=Integer.parseInt(bf.readLine()); ArrayList<Integer> div=new ArrayList<>(); findDiv(n,div); Collections.sort(div); str.append(solve(div,n)+"\n"); } System.out.println(str); } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t=int(input()) for _ in range(t): n=int(input()) a=b=c=-1 for i in range(2,int(n**0.5)+1): if n%i==0: a=i n//=i break for i in range(2,int(n**0.5)+1): if n%i==0 and i!=a: b=i n//=i break if b!=-1 and n!=a and n!=b: c=n if c==-1: print('NO') else: print('YES') print('{} {} {}'.format(a,b,c))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using Int = long long; using namespace std; vector<pair<Int, Int>> primeFactors(Int n) { vector<pair<Int, Int>> result; Int factor = 0; Int factorCount = 0; Int q = n; if (n >= 2) { for (Int i = 2; i * i <= n;) { if (q % i == 0) { if (i != factor) { factor = i; factorCount = 1; } else { factorCount++; } q /= i; } else { if (factor > 0) { result.push_back(make_pair(factor, factorCount)); factor = 0; } i++; } } } if (q > 1) { result.push_back(make_pair(q, 1)); } return result; } int main() { int t; cin >> t; for (int i = 0, i_len = (int)(t); i < i_len; i++) { Int n; cin >> n; auto factors = primeFactors(n); if (((int)(factors).size()) == 1) { auto p = factors[0].first; auto e = factors[0].second; if (e >= 6) { puts("YES"); printf("%lld %lld %lld \n", p, p * p, n / (p * p * p)); } else { puts("NO"); } } else if (((int)(factors).size()) == 2) { auto p0 = factors[0].first; auto e0 = factors[0].second; auto p1 = factors[1].first; auto e1 = factors[1].second; if (e0 + e1 <= 3) { puts("NO"); } else { puts("YES"); printf("%lld %lld %lld \n", p0, p1, n / (p0 * p1)); } } else { auto p = factors[0].first; auto q = factors[1].first; puts("YES"); printf("%lld %lld %lld \n", p, q, n / (p * q)); } } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; void helper(long long int n) { set<int> nums; for (int i = 2; i * i <= n; i++) { if (n % i == 0 && !nums.count(i)) { nums.insert(i); n /= i; break; } } for (int i = 2; i * i <= n; i++) { if (n % i == 0 && !nums.count(i)) { nums.insert(i); n /= i; break; } } if (nums.size() < 2 || nums.count(n) || n <= 1) { cout << "NO" << endl; } else { cout << "YES" << endl; nums.insert(n); for (auto i : nums) { cout << i << " "; } cout << endl; } } int main() { int t; cin >> t; while (t--) { int n; cin >> n; helper(n); } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9; const long long N = 1e3 + 500; const long long mod = 1e9 + 7; const long double eps = 1E-7; long long n, mx, mn, cnt, m, ans; long long a, b, c; string s; long long used[N]; char z; int main() { ios_base::sync_with_stdio(0); long long T; cin >> T; while (T--) { cin >> n; vector<long long> v; for (long long i = 2; i <= 1000000; i++) { if (n % i == 0 and v.size() < 2) { v.push_back(i); n /= i; } else if (v.size() == 2) break; } if (v.size() == 2 and n != v[0] and n != v[1] and n > 1) { v.push_back(n); } if (v.size() == 3) cout << "YES\n" << v[0] << " " << v[1] << " " << v[2] << endl; else cout << "NO\n"; v.clear(); } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n = int(input()) l = [] til = int(n**0.5)+1 i = 2 while i < til: if n%i==0: til = int((n//i)**0.5)+1 n= (n//i) l.append(i) if len(l)==2: break i+=1 if n > 1 and n not in l and len(l)==2: print("YES") print(l[0],l[1], n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for _ in range(t): n = int(input()) i = 2 arr = [0,0,0] k = 0 while(i * i <= n): if (n % i == 0): arr[k] = i n = int(n/i) k+=1 if (k == 2): break i+=1 arr[2] = n if(arr[1] >1 and arr[0] > 1 and arr[2] > 1): if (arr[0] == arr[1] or arr[1] == arr[2] or arr[0] == arr[1]): print ("NO") else: print("YES") print(str(arr[0]) + " " + str(arr[1]) + " " + str(arr[2])) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): num=int(input()) list1=[] j=2 while(j*j<num and len(list1)<2): if(num%j==0): num=num//j list1.append(j) j+=1 if(len(list1)==2 and num not in list1): print("YES") for k in list1: print(k,end=" ") print(num) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math b= int(input()) t=[] for j in range(b): t.append(int(input())) for a in t : c=3 i = 2 s = '' while a > 1 and a // i >= 1 and i <=math.pow(a,1/c): if (a % i == 0): a = a // i s = s + i.__str__() + ' ' c=c-1 if (s.split(' ').__len__()>2 and a//(i+1)>0): s = s + a.__str__() + ' ' a=0 elif s.split(' ').__len__()>2: a=0 i = i + 1 if s.split(' ').__len__()>3: print("YES \n", s, sep='') else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for i in range(t): n, s = int(input()), [] for i in range(2, int(n**(1/2)+1)): if n % i == 0: s.append(i) n = n // i if len(s) == 2 and s[0]!=n and s[1]!=n: break if len(s) == 2 and s[0]!=n and s[1]!=n: print('YES') print(str(s[0])+' '+str(s[1])+' '+str(n)) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math n = int(input()) def sd(n, notin): i = 2 while i * i < n: if n % i == 0 and i not in notin: return i i += 1 return n for i in range(n): a = int(input()) aa = a sq = int(math.sqrt(a)) + 1 divisor = [] while True: s = sd(a, divisor) if s == a: print("NO") break a = a // s divisor.append(s) if len(divisor) == 2: if a != divisor[0] and a != divisor[1]: print("YES") print(divisor[0], divisor[1], a) else: print("NO") break
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def product_of_three_numbers(): num_test = int(input()) count = 0 n_list = [] while count < num_test: n_list += [int(input())] count += 1 answer_list = [] for idx, n in enumerate(n_list): if n <= 5: answer_list += ["NO"] continue breakit = False for a in range(2, n+1): if (a-1)*(a-1) >= n: answer_list += ["NO"] break if n%a == 0: divbya = int(n/a) if divbya <= a: answer_list += ["NO"] break for b in range(a, divbya): if (b-1)*(b-1) >= divbya: answer_list += ["NO"] breakit = True break if divbya%b == 0: if b==a: continue divbyb = int(divbya/b) if divbyb <= b: answer_list += ["NO"] breakit = True break answer_list += ["YES"] answer_list += [str(a)+" "+str(b)+" "+str(divbyb)] breakit = True break if breakit: break for answer in answer_list: print(answer) product_of_three_numbers()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
v = int(input()) for i in range(v): b = list(map(int,input().split()))[:v] c = 0 a = [] for j in b: for h in range(2,int(j**(0.5))+1): if j%h==0: c+=1 j = j//h a.append(h) if len(a)==2: break if len(a)==2 and j not in a: print("YES") print(*a,j) else: print("NO")
PYTHON3