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
def prime_factors(n): i = 2 factors = [] while i * i <= n: if n % i: i += 1 else: n //= i factors.append(i) if n > 1: factors.append(n) return factors m = int(input()) for i in range(m): n = int(input()) if len(prime_factors(n)) < 3: print("NO") else: a = prime_factors(n)[0] if prime_factors(n)[0] == prime_factors(n)[1]: b = prime_factors(n)[1] * prime_factors(n)[2] if len(prime_factors(n)) == 3: print("NO") else: c = 1 for el in prime_factors(n)[3:]: c *= el if a != b != c and a != c: print("YES") print(a, b, c) else: print("NO") else: b = prime_factors(n)[1] c = 1 for el in prime_factors(n)[2:]: c *= el if a != b != c and a != c: 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
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); for (int i = 0; i < t; i++) { int n = sc.nextInt(); int cnt = 0; int[] res = new int[3]; for (int j = 2; j * j <= n; j++) { if(cnt == 2) break; if(n % j == 0) { res[cnt] = j; cnt++; n /= j; } } if(cnt < 2 || n <= res[1]) System.out.println("NO"); else { res[2] = n; System.out.println("YES"); for (int j = 0; j < res.length; j++) { System.out.print(res[j]+" "); } } } sc.close(); } }
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()) while(t): t-=1 n=int(input()) ans=-1 if n<24: print("NO") continue else: root=int(math.sqrt(n)) factors=set() for i in range(2,root+1): if n%i==0: factors.add(i) factors.add(n//i) # print (factors) for i in factors: for j in factors: s=n//(i*j) if i!=j and s in factors: if i!=s and j!=s: ans = [] ans.append(i) ans.append(j) ans.append(s) ans.sort() break if ans!=-1: break if ans==-1: print("NO") #print(ans) 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
def min_dev(n,temp): while temp<n**0.5+1: if n%temp==0: return temp temp+=1 return 0 for _ in range(int(input())): n=int(input()) a=min_dev(n,2) if a==0: print('NO') continue b=min_dev(int(n/a),a+1) if b==0: print('NO') continue c=int(n/(a*b)) if c==0 or c==b or c==1 or c==a: print('NO') continue 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.StringTokenizer; public class _13ProductOfThreeNumbers { public static void main(String[] args) { FastInput input = new FastInput(); PrintWriter output = new PrintWriter(System.out); StringBuilder sb = new StringBuilder(); int t = input.nextInt(); caseLoop: while (t-- > 0) { int n = input.nextInt(), i, j, k; for (i = 2; i <= n / i; i++) { if (n % i == 0 && n / i != i) { int e1 = i; int prov = n / i; for (j = i + 1; j <= n / (i * j); j++) { if (prov % j == 0 && prov / j != j && prov / j != i) { sb.append("YES\n"+ e1 + " " + j + " " + prov / j).append('\n'); continue caseLoop; } } } } sb.append("NO\n"); } output.println(sb); output.close(); } static class FastInput { BufferedReader br; StringTokenizer st; public FastInput() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return 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
import math def prime(n): flag=0 for i in range(2,int(math.sqrt(n))+1): if(n%i==0): flag=1 break if(flag!=1): return 1 else: return 0 t=int(input()) while(t!=0): n=int(input()) n1=n flag=0 if((prime(n)==0) and n>=24): for i in range(2,int(math.sqrt(n))+1): if(n%i==0): a=i break if(prime(n//a)==0): n=n//a for i in range(2,int(math.sqrt(n))+1): if((n%i==0) and i!=a and (n//i)!=a and (n//i)!=i): b=i c=n//b flag=1 break if(flag!=0 and a>=2 and b>=2 and c>=2 and (a*b*c)==n1): print("YES") print(a,b,c) else: print("NO") t-=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
n = int(input()) for _ in range(n): ans = [] x = int(input()) f = 2 while len(ans) < 2 and f ** 2 < x: if x % f == 0: ans.append(f) x //= f f += 1 if len(ans) == 2 and x > ans[1]: print('YES') print(ans[0], ans[1], x) 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; void Doaa() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { Doaa(); int n, t, num1 = 0, count = 0; cin >> t; while (t--) { count = 0; cin >> n; int x = n; bool f = true; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { if (count == 0) { num1 = i; n = n / i; } count++; } if (count == 2) { x = i; if (i * i == n) f = false; else { if (n / i == num1) f = false; else f = true; break; } } } if (count == 2 && f) cout << "YES" << endl << num1 << " " << x << " " << n / x << 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
from __future__ import division, print_function def main(): for _ in range(int(input())): n = int(input()) x = int(n**0.5) i = 2 factors = [] while i <= x and n > 1: if n%i==0: factors.append(i) n=n//i else : i+=1 if n > 1: factors.append(n) a = factors[0] b = 1 i = 1 while i < len(factors) and b <= a: b = b*factors[i] i+=1 if b==1: print("NO") continue c = 1 while i < len(factors): c = c*factors[i] i+=1 if c > 1 and a!=c and b!=c and a!=b: print("YES") print(a,b,c) else : print("NO") ######## Python 2 and 3 footer by Pajenegod and c1729 # Note because cf runs old PyPy3 version which doesn't have the sped up # unicode strings, PyPy3 strings will many times be slower than pypy2. # There is a way to get around this by using binary strings in PyPy3 # but its syntax is different which makes it kind of a mess to use. # So on cf, use PyPy2 for best string performance. py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange import os, sys from io import IOBase, BytesIO BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writable = "x" in file.mode or "w" in file.mode self.write = super(FastIO, self).write if self.writable else None def _fill(self): s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0]) return s def read(self): while self._fill(): pass return super(FastIO,self).read() def readline(self): while self.newlines == 0: s = self._fill(); self.newlines = s.count(b"\n") + (not s) self.newlines -= 1 return super(FastIO, self).readline() def flush(self): if self.writable: os.write(self._fd, self.getvalue()) self.truncate(0), self.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable if py2: self.write = self.buffer.write self.read = self.buffer.read self.readline = self.buffer.readline else: self.write = lambda s:self.buffer.write(s.encode('ascii')) self.read = lambda:self.buffer.read().decode('ascii') self.readline = lambda:self.buffer.readline().decode('ascii') sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip('\r\n') # Cout implemented in Python import sys class ostream: def __lshift__(self,a): sys.stdout.write(str(a)) return self cout = ostream() endl = '\n' # Read all remaining integers in stdin, type is given by optional argument, this is fast def readnumbers(zero = 0): conv = ord if py2 else lambda x:x A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read() try: while True: if s[i] >= b'0' [0]: numb = 10 * numb + conv(s[i]) - 48 elif s[i] == b'-' [0]: sign = -1 elif s[i] != b'\r' [0]: A.append(sign*numb) numb = zero; sign = 1 i += 1 except:pass if s and s[-1] >= b'0' [0]: A.append(sign*numb) return A if __name__== "__main__": main()
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
def factorize(n): l=[] for i in range(2,int(n**0.5)+1): if len(l)==2 and n>=i: l.append(n) break if n<=1: break if n%i==0: n=n//i l.append(i) return l for _ in range(int(input())): n=int(input()) l=factorize(n) if len(l)>=3: print("YES") print(*l) 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.*; import java.math.BigInteger; import java.util.*; public class Main { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out); static int MOD = 1000000007; public static void main(String[] args) throws IOException { Main m = new Main(); m.solve(); m.close(); } void close() throws IOException { pw.flush(); pw.close(); br.close(); } int readInt() throws IOException { return Integer.parseInt(br.readLine()); } long readLong() throws IOException { return Long.parseLong(br.readLine()); } int[] readIntLine() throws IOException { String[] tokens = br.readLine().split(" "); int[] A = new int[tokens.length]; for (int i = 0; i < A.length; i++) A[i] = Integer.parseInt(tokens[i]); return A; } long[] readLongLine() throws IOException { String[] tokens = br.readLine().split(" "); long[] A = new long[tokens.length]; for (int i = 0; i < A.length; i++) A[i] = Long.parseLong(tokens[i]); return A; } void solve() throws IOException { int t = readInt(); for (int ti = 0; ti < t; ti++) { int n = readInt(); Map<Integer, Integer> primeFactors = primeFactorize(n); List<Integer> factors = new ArrayList<>(); for (int p : primeFactors.keySet()) { int k = primeFactors.get(p); for (int i = 0; i < k; i++) factors.add(p); } int[] abc = new int[]{1, 1, 1}; int i = 0; boolean done = false; while (i < factors.size()) { if (abc[0] == 1) { abc[0] = factors.get(i++); } else if (abc[1] == 1) { abc[1] = factors.get(i++); if (abc[1] == abc[0]) { if (i >= factors.size()) { pw.println("NO"); done = true; break; } abc[1] *= factors.get(i++); } } else { while (i < factors.size()) { abc[2] *= factors.get(i++); } } } if (done) continue; if (abc[2] == abc[0] || abc[2] == abc[1] || abc[0] == 1 || abc[1] == 1 || abc[2] == 1) pw.println("NO"); else { pw.println("YES"); pw.println(abc[0] + " " + abc[1] + " " + abc[2]); } } } Map<Integer, Integer> primeFactorize(int n) { Map<Integer, Integer> factors = new HashMap<>(); while (n % 2 == 0) { factors.put(2, factors.getOrDefault(2, 0) + 1); n /= 2; } for (int i = 3; i * i <= n; i += 2) { while (n % i == 0) { factors.put(i, factors.getOrDefault(i, 0) + 1); n /= i; } } if (n > 2) { factors.put(n, factors.getOrDefault(n, 0) + 1); } return factors; } }
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
# Python program to print prime factors import math # A function to print all prime factors of # a given number n def primeFactors(n): a=[] # Print the number of two's that divide n while n % 2 == 0: a.append(2), n = n // 2 # n must be odd at this point # so a skip of 2 ( i = i + 2) can be used for i in range(3,int(math.sqrt(n))+1,2): # while i divides n , print i ad divide n while n % i== 0: a.append(i) n = n // i # Condition if n is a prime # number greater than 2 if n > 2: a.append(n) return a # Driver Program to test above function # This code is contributed by Harshit Agrawal def prod(a): s=1 for i in range(len(a)): s=s*a[i] return s t=int(input()) for i in range(t): n=int(input()) b=primeFactors(n) c=list(set(b)) if len(c)>=3: print("YES") print(c[0],c[1],n//(c[0]*c[1])) elif len(c)==2 and len(b)>=4: print("YES") print(c[0],c[1],n//(c[0]*c[1])) elif len(c)==1 and len(b)>=6: print("YES") print(c[0],c[0]**2,n//(c[0]**3)) 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 _ in range(t): n=int(input()) if(n<24): print("NO") else: l=[] temp=n for i in range(2,math.ceil(math.sqrt(n))+1): if(temp%i==0): l.append(i) temp=temp//i if(len(l)==2): break if(len(l)==2 and temp>l[1]): print("YES") print(l[0],l[1],temp) 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 req(n): k = int(n ** (1 / 2)) for a in range(2, k): if n % a == 0: for b in range(2, k): if b != a: if n % (a * b) == 0: c = n // (a * b) if b != c and a != c: return [a, b, c] return 0 t = int(input()) for i in range(t): n = int(input()) result = req(n) if result == 0: print("NO") else: print("YES") print(*result)
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 factor(n,a): l=[] r=n k=int(math.sqrt(n))+1 d=1 while n%(2**d)==0: if 2**d!=a and r//(2**d)!=a and r//(2**d)!=2**d and 2**d!=r: l.append(2**d) l.append(r//2**d) n//=2**d d+=1 break else: d+=1 for i in range(3,k,2): d=1 while n%(i**d)==0: if i**d!=a and r//(i**d)!=a and r//(i**d)!=i**d and i**d!=n: l.append(i**d) l.append(r//i**d) n//=i**d d+=1 break else: d+=1 return l def factors(n): l=[] r=n k=int(math.sqrt(n))+1 d=1 while n%2==0: l.append(2**d) d+=1 n//=2 for i in range(3,k,2): d=1 while n%i==0: l.append(i**d) d+=1 n//=i if n==1: return l else: l.append(n) return l for _ in range(int(input())): n=int(input()) l=factors(n) if len(l)<3: print("NO") else: t=x=y=z=0 for i in range(len(l)): a=n//l[i] f=factor(a,l[i]) if len(f)>1: x=f[0] y=f[1] z=l[i] t=1 break if t==1: print("YES") print(z,x,y) 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 defaultdict def divisors(n, ans): i = 2 while i <= math.sqrt(n): if (n % i == 0): if (n / i == i): ans.append(i) else: ans.append(i) ans.append(n // i) i = i + 1 for _ in range(int(input())): n = int(input()) d1 = [] # d2 = [] divisors(n, d1) rec = defaultdict(int) for i in d1: rec[i] = 1 flag = 0 for i in d1: d2 = [] divisors(n//i, d2) for j in d2: if rec.get(j, 0) != 0 and rec.get((n//i)//j, 0) != 0 and (n//i)//j != j and (n//i)//j != i and i != j: flag = 1 print('YES') print(i, j, (n//i)//j) 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
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using pll = pair<ll, ll>; using pii = pair<int, int>; const int MOD = 1e9 + 7; const int MAX = 1e5 + 5; const ll INF = 1e18 + 1; void err(...) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { for (auto i : *it) cerr << i; cerr << " = " << a << "\n"; err(++it, args...); } template <class Ch, class Tr, class Container> basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os, Container const& x) { os << "{ "; for (auto& y : x) os << y << " "; return os << "}"; } template <class X, class Y> ostream& operator<<(ostream& os, pair<X, Y> const& p) { return os << "[" << p.first << " : " << p.second << "]"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int T; cin >> T; while (T--) { int n; cin >> n; set<int> s; int a = -1; int b = -1; for (int i = 2; i < sqrt(n); i++) { if (n % i == 0 && n / i != i) { a = i; b = n / i; break; } } if (a == -1) { cout << "NO" << "\n"; continue; } s.insert(a); s.insert(b); int c = -1, d = -1; for (int i = 2; i < sqrt(a); i++) { if (a % i == 0 && a / i != i && i != b && (a / i) != b) { c = i; d = a / i; break; } } if (c != -1) { cout << "YES" << "\n"; cout << b << " " << c << " " << d << "\n"; continue; } for (int i = 2; i < sqrt(b); i++) { if (b % i == 0 && b / i != i && i != a && (b / i) != a) { c = i; d = b / i; break; } } if (c != -1) { cout << "YES" << "\n"; cout << a << " " << c << " " << d << "\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
import math def splitPrime(n): arr = {} for i in range(2, math.ceil((math.sqrt(n))) + 1): while n != 0 and n % i == 0: f = arr.get(i, 0) arr[i] = int(f + 1) n = n // i if n > 1: arr[n] = 1 return arr t = int(input()) for i in range(t): n = int(input()) arr = splitPrime(n) numbersKey = len(arr) if numbersKey >= 3: print('YES') count = 0 result = 1 for key in arr: if count == 2: break print(key, end=' ') result *= key count += 1 print(n // result) elif numbersKey == 2 and sum(arr.values()) >= 4: print('YES') result = 1 for key in arr: print(key, end=' ') result *= key print(n // result) elif numbersKey == 1 and sum(arr.values()) >= 6: print('YES') for key in arr: print(key, int(math.pow(key, 2)), int(n // math.pow(key, 3))) 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()) while(t): n=int(input()) a=[] for i in range(2,int(math.sqrt(n))+1): if n%i==0: a.append(i) n=n//i if len(a)==2: break if len(a)==2 and n!=1: if n not in a: print("YES") print(a[0],a[1],n) else: print("NO") else: print("NO") t-=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
# -*- 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 + v2 < 4: 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
#include <bits/stdc++.h> using namespace std; long long q, n; long long ans1, ans2, ans3; long long cnt, a[1000005]; signed main() { cin >> q; while (q--) { cnt = 0; cin >> n; for (long long i = 2; i * i <= n; i++) if (n % i == 0) { a[++cnt] = i; a[++cnt] = n / i; } if (cnt < 3) { cout << "NO\n"; continue; } bool f = 0; for (long long i = 1; i <= cnt; i++) for (long long j = i + 1; j <= cnt; j++) { long long s = a[i] * a[j]; if (n % s == 0 && n / s != a[i] && n / s != a[j] && s != n) { f = 1; ans1 = a[i]; ans2 = a[j]; ans3 = n / s; } } if (!f) cout << "NO\n"; else cout << "YES\n" << ans1 << ' ' << ans2 << ' ' << ans3 << 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
# cook your dish here import math def primeFactors(n): arr=[] while n % 2 == 0: arr.append(2) n = n / 2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: arr.append(i) n = n / i if n > 2: arr.append(n) return arr t=int(input()) for _ in range(t): n=int(input()) arr=primeFactors(n) if len(arr)>=3: a=arr[0] if arr[0]!=arr[1]: b=arr[1] c=n//(a*b) if c==a or c==b or c<2: print("NO") else: print("YES") print(a,b,c) else: b=arr[1]*arr[2] c=n//(a*b) if c==a or c==b or c<2: print("NO") else: 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
import java.io.*; import java.math.*; import java.util.*; public class A { public static void main(String[] agrs) throws IOException { // PrintWriter pw = new PrintWriter(System.out); FastScanner sc = new FastScanner(); int yo = sc.nextInt(); while(yo-->0) { int n = sc.nextInt(); if(n < 8) { System.out.println("NO"); continue; } Set<Integer> set = new HashSet<>(); for(int i = 2; i*i <= n; i++) { if(n%i == 0 && !set.contains(i)) { n /= i; set.add(i); break; } } for(int i = 2; i*i <= n; i++) { if(n%i == 0 && !set.contains(i)) { n /= i; set.add(i); break; } } if(set.size() < 2 || set.contains(n)) { System.out.println("NO"); } else { System.out.println("YES"); for(int e : set) { System.out.print(e + " "); } System.out.print(n + " "); System.out.println(); } } } static class Pair{ int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } static int gcd(int a, int b) { return a%b == 0 ? b : gcd(b,a%b); } static int mod = 1000000007; static long pow(int a, int b) { if(b == 0) { return 1; } if(b == 1) { return a; } if(b%2 == 0) { long ans = pow(a,b/2); return ans*ans; } else { long ans = pow(a,(b-1)/2); return a * ans * ans; } } static boolean[] sieve(int n) { boolean isPrime[] = new boolean[n+1]; for(int i = 2; i <= n; i++) { if(isPrime[i]) continue; for(int j = 2*i; j <= n; j+=i) { isPrime[j] = true; } } return isPrime; } 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()); } } // For Input.txt and Output.txt // FileInputStream in = new FileInputStream("input.txt"); // FileOutputStream out = new FileOutputStream("output.txt"); // PrintWriter pw = new PrintWriter(out); // Scanner sc = new Scanner(in); }
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 factor(x): p = [] d = 2 while d * d <= x: if x % d == 0: p.append(d) x //= d else: d += 1 if x > 1: p.append(x) return p t = int(input()) for i in range(t): n = int(input()) p = factor(n) a, b, c = 1, 1, 1 ans = 'NO' if len(p) > 2: a = p[0] if p[1] != p[0]: b = p[1] c = 1 for k in p[2:]: c *= k if c != 1 and c != b and c != a: ans = 'YES' else: b = p[1] * p[2] c = 1 for k in p[3:]: c *= k if c != 1 and c != b and c != a: ans = 'YES' if ans == 'YES': 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
import sys, itertools, math T = int(sys.stdin.readline()) def solve(n): for a in range(2, int(math.sqrt(n))+1): if n % a != 0: continue for b in range(a+1, int(math.sqrt(n))+1): r = a * b c = n // r if n % r == 0 and c != a and c != b: print("YES") print(a, b, c) return print("NO") for _ in range(T): n = int(sys.stdin.readline()) 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
#----------------- # cook your dish here #############----------------- ######----- import math ########### ##### try: ####### def func1(t2,io):############# ###### ########## if len(io) >= 3 and len(t2) >= 3:###### ########## y = t2[1]###### ####### x = t2[0]#######3 ##### z = n//(x*y)######## ############ return [x,y,z]######### ###### elif len(io) >= 6 and len(t2) == 1:############33 ####### y = pow(t2[0], 2)## ###### x = t2[0]########## ######### ####### ###### ########## z = n // pow(x, 3)############ ############ return [x,y,z] elif len(io) >= 4 and len(t2) == 2:########## ##### y = t2[1]################## ###### x = t2[0]###### ###### z = n // (y*x)######### ########## return [x,y,z]####### else: ########## return "NO"#######3 def func2(l): ############ io = []########### ########### while l%2 == 0:######## ######## io.append(2)###### ######### l = l//2### ######## for p in range(3, int(math.sqrt(l)) + 1, 2):########## ############# while (l%p == 0):########### ########### io.append(p)########## ######## l = l//p ########## if l > 2:######### ###### io.append(l)######## return io######## ######### tyu = int(input())######## ######## for tyc in range(tyu):######### ########### n = int(input())##### ############# io = func2(n) t2 = list(set(io))######### ############## gy = func1(t2,io)###### ############# if gy=='NO':####### ##### print("NO")########## else: ########### print("YES")###3 print(*gy)### ########### ####### ########## continue ####### ############ except: pass ########## ################ ##### ############# ##########################
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
#C for _ in range(int(input())): n = int(input()) cnt=0 ans = [] for i in range(2,int(n**0.5)+1): if n % i == 0: cnt+=1 ans.append(i) if cnt == 2 and n % (ans[0]*ans[1]) == 0 and n//(ans[0]*ans[1]) != ans[0] and n//(ans[0]*ans[1]) != ans[1]: break if cnt == 2 and n % (ans[0]*ans[1]) != 0: del ans[1] cnt-=1 if cnt == 2: if n % (ans[0]*ans[1]) == 0 and n//(ans[0]*ans[1]) != ans[0] and n//(ans[0]*ans[1]) != ans[1]: ans.append(n//(ans[0]*ans[1])) #print(ans) if len(ans)==3: 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
t=int(input()) for q in range(t): n=int(input()) c=[] i=2 while len(c)<2 and i*i<n: if n%i==0: c.append(i) n=n/i i=i+1 if len(c)==2: print("YES") print(*c,int(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 t in range(int(input())): n = int(input()) try: a = next(i for i in range(2, int(n**0.5)+1) if n%i == 0) n//=a b = next(i for i in range(a+1, int(n**0.5)+1) if n % i == 0) if n//b <= b: raise else: print("YES") print(a, b, n//b) except: 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
#create a string in which no two same char comes together. # assumption only small albhabetical letters used #input format: just enter the string without any space import sys import math input = sys.stdin.readline ############ ---- Input Functions ---- #######Start##### def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) ############ ---- Input Functions ---- #######End##### def pr_list(a): print(*a, sep=" ") def main(): tests = inp() for test in range(tests): n = inp() n1 = math.sqrt(n) + 2 out = [] flag = 1 i = 2 while(i<n1 and len(out)< 3): if n %i == 0 : n = int(n/i) n1 = math.sqrt(n) + 2 if i not in out: out.append(i) if len(out) == 2 and n not in out and n!=1: out.append(n) break i = i + 1 if len(out) == 3: print("YES") pr_list(out) else: print("NO") return #time o(2n) space o(26*2) #sorted(hashm.items(), key=lambda item: item[1]) 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
#include <bits/stdc++.h> using namespace std; int ans1, ans2, n, T; inline int read() { int x = 0; int flag = 0; char ch; ch = getchar(); while (!isdigit(ch)) { if (ch == '-') flag = 1; ch = getchar(); } while (isdigit(ch)) { x = (x << 3) + (x << 1) + ch - 48; ch = getchar(); } if (flag == 1) x = -x; return x; } inline bool solve(int x) { for (register int i = 2; i <= sqrt(x) + 1; i++) { if (x % i == 0 && i != x / i) { ans1 = i; ans2 = x / i; return true; } } return false; } int main() { T = read(); while (T--) { n = read(); int flag = 0; for (register int a = 2; a <= sqrt(n) + 1; a++) { if (n % a == 0) { int rest = n / a; for (register int i = 2; i <= sqrt(rest) + 1; i++) { if (rest % i == 0) { ans1 = i; ans2 = rest / i; if (ans1 != ans2 && ans1 != a && ans2 != a && ans1 != 1 && ans2 != 1) { printf("YES\n%d %d %d\n", a, ans1, ans2); flag = 1; break; } } } if (flag == 1) break; } } if (!flag) { printf("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.util.*; // scanner.nextInt(); public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int test_case = scanner.nextInt(); for(int z = 0; z < test_case; ++z) { int n = scanner.nextInt(); int[] divisores = new int[3]; int size = 0; boolean done = false; for(int i = 2; i*i <= n; ++i) { if(n % i == 0) { divisores[size] = i; ++size; n /= i; if(size == 2 && n > i) { divisores[2] = n; done = true; break; } else if(size == 2) break; } } if(done) { System.out.println("Yes"); System.out.println(divisores[0] + " " + divisores[1] + " " + divisores[2]); } 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
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { set<int> s; int count = 0; int a; cin >> a; for (int i = 2; i * i <= a; i++) { if (a % i == 0) { int u = a / i; s.insert(i); for (int j = i + 1; j * j <= u; j++) { if (u % j == 0) { s.insert(j); if (s.find(u / j) == s.end()) { count = 1; cout << "YES" << endl; cout << i << " " << j << " " << u / j << endl; } break; } } } if (count == 1) { break; } } if (count == 0) { 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
import sys input = sys.stdin.readline def solve(): n = int(input()) ans, ind = [], 2 while len(ans) < 2 and ind < n ** (1 / 2): if not n % ind: n = n // ind ans.append(ind) ind += 1 return ans + [n] for _ in range(int(input())): sol = solve() if len(sol) == 3: print('YES') print(' '.join(list(map(str, sol)))) 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
#!/usr/bin/env python3 R = lambda: list(map(int, input().split())) def solve(): n = R()[0] a, cnt, i = [0, 0], 0, 2 while i * i < n and cnt < 2: if n % i == 0: a[cnt] = i cnt += 1 n //= i i += 1 if cnt < 2: print("NO") else: print("YES\n", a[0], a[1], n) o_o = R()[0] for _ in range(o_o): 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
#include <bits/stdc++.h> using namespace std; const int INF = 1e8 + 1; const long double PI = 3.141592653; bool isp(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return 0; } return 1; } int main() { int tc; cin >> tc; while (tc--) { int n; cin >> n; if (isp(n)) { cout << "NO" << endl; continue; } else { vector<int> pot; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { if (n / i == i) pot.push_back(i); else { pot.push_back(i); pot.push_back(n / i); } } } sort(pot.begin(), pot.end()); int o = pot[0], t = pot[int(pot.size()) - 1]; vector<int> xd; for (int i = 2; i * i <= t; i++) { if (t % i == 0) { if (t / i == i) xd.push_back(i); else { xd.push_back(i); xd.push_back(t / i); } } } sort(xd.begin(), xd.end()); int i = 0, j = int(xd.size()) - 1; bool fin = 0; int p, pp; while (i < j) { if (!(xd[i] != xd[j] && xd[i] != o && xd[j] != o)) { i++; j--; } else { fin = 1; p = i; pp = j; break; } } if (fin) { cout << "YES" << endl; cout << o << " " << xd[p] << " " << xd[pp] << endl; } else { 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
def process(n,i,sol): for j in range(i+1,int(n**(0.5))+1): if n%j==0: sol.append(j) if len(sol)==1: process(n//j,j,sol) break if len(sol)==2: if j!=n//j: sol.append(n//j) break return sol for _ in range(int(input())): n=int(input()) sol=[] process(n,1,sol) if len(sol)==3: print("YES") print(*sol) 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; int32_t main() { ios::sync_with_stdio(false); cin.tie(NULL); ; long long t; cin >> t; while (t--) { long long n; cin >> n; if (n < 24) { cout << "NO" << endl; continue; } long long p = 0; for (long long i = 2; i <= sqrt(n); i++) { if (n % i == 0) { p = 1; break; } } if (!p) { cout << "NO" << endl; continue; } long long a = 0, b = 0, c = 0; for (long long i = 2; i <= sqrt(n); i++) { if (n % i == 0) { a = n / i; b = i; break; } } for (long long i = 2; i <= sqrt(a); i++) { if (a % i == 0) { if (a / i != i && i != b && a / i != b) { c = a / i; a = i; break; } } } if (a != b && b != c && a != c && a >= 2 && b >= 2 && c >= 2) { cout << "YES" << endl; cout << a << " " << b << " " << c << endl; } else 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
def main(): T = int(input()) for t in range(T): m = int(input()) n = m dic = {} i = 2 while i * i <= n: while n % i == 0: dic[i] = dic.get(i, 0) + 1 n //= i i += 1 if m % n == 0 and n != 1: dic[n] = dic.get(n, 0) + 1 keys = list(dic.keys()) # print("*" + str(len(dic))) if len(dic) == 0: print("NO") elif len(dic) == 1: x = keys[0] y = dic[x] if y < 6: print("NO") else: print("YES") print(str(x) + ' ' + str(x**2) + ' ' + str(x**(y-3))) elif len(dic) == 2: x1, x2 = keys[0], keys[1] y1, y2 = dic[x1], dic[x2] if y1 + y2 <= 3: print("NO") else: print("YES") print(str(x1) + ' ' + str(x2) + ' ' + str((x1**(y1-1)) * (x2**(y2-1)))) else: x1, x2 = keys[0], keys[1] y1, y2 = dic[x1], dic[x2] print("YES") print(str(x1**y1) + ' ' + str(x2**y2) + ' ' + str(m // (x1**y1) // (x2**y2))) 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
def nonprime(number,start=2): from math import sqrt for i in range(start,int(sqrt(number))+1): if number%i==0: return [True,i] return [False] testcases=int(input()) for k in range(testcases): numbertobetested=int(input()) initial=nonprime(numbertobetested) if initial[0]: k=nonprime(numbertobetested//initial[1],start=initial[1]+1) if k[0] and (initial[1]!=k[1] and initial[1]!=((numbertobetested//initial[1])//k[1]) and k[1]!=((numbertobetested//initial[1])//k[1])): print("YES") print(str(initial[1])+" "+str(k[1])+" "+str(((numbertobetested//initial[1])//k[1]))) 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.Scanner; public class productod3{ public static void main(String[] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for(int k = 0; k < t; k++){ int n = scan.nextInt(); if(!func(n)){ System.out.println("NO"); } } } public static Boolean func(int n){ if(n % 2 == 0){ int aux = func2(n/2, 2); if(aux != 0 && aux != 2 && ((n / 2) / aux) * (2) * (aux) == n){ System.out.println("YES"); System.out.println((n/2)/aux + " " + 2 + " " + aux); return true; } } for(int i = 3; i < (int) Math.sqrt(n); i++){ if(n % i == 0){ int aux = func2(i, i); if(aux == 0){ aux = func2(n / i, i); } if(aux != 0 && ((n/i)/aux) != i && ((n/i)/aux) != aux && i != aux && ((n/i) / aux) * (i) * (aux) == n){ System.out.println("YES"); System.out.println(((n / i) / aux) + " " + i + " " + aux); return true; } } } return false; } public static int func2(int n, int d){ if(n % 2 == 0){ return 2; } for(int i = 3; i < Math.sqrt(n); i++ ){ if(n % i == 0){ return i; } } return 0; } }
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
n = int(input()) for k in range(n): z = int(input()) l = [] for i in range(2 , z): if z % i == 0: l.append(i) z = z // i break if (i * i) > z: break for j in range(2 , z): if z % j == 0 and j not in l: l.append(j) z = z // j break if (j * j) > z: break if len(l) < 2 or z == 1 or z in l: print('NO') else: print('YES') print(l[0] , l[1] , z)
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 java.security.*; public class Main { public static void main(String[] args)throws Exception { Reader reader = new Reader(); reader.readLine(); int t = reader.readInt(0); StringBuilder res = new StringBuilder(); while (t-- > 0) { reader.readLine(); int num = reader.readInt(0); List<List<Integer>> divisors = getDivisors(num); boolean found = false; for (List<Integer> row:divisors) { int v1 = row.get(0); int v2 = row.get(1); List<List<Integer>> v1Div = getDivisors(v1); if (isValid(v2, v1Div, res)) { found = true; break; } List<List<Integer>> v2Div = getDivisors(v2); if (isValid(v1, v2Div, res)) { found = true; break; } } if (!found) { res.append("NO\n"); } //System.out.println(res); } System.out.println(res.toString().trim()); reader.close(); } static List<List<Integer>> getDivisors(int n) { List<List<Integer>> ans = new ArrayList<>(); for (int i=2; i <= Math.ceil(Math.sqrt(n)); i++) { if (n % i == 0) { if (n / i == i) { if (i != 1 && n / i != 1) //System.out.printf("%d ", i); ans.add(new ArrayList<>(Arrays.asList(i, i))); } else { if (i != 1 && n / i != 1) //System.out.printf("%d %d ", i, n / i); ans.add(new ArrayList<>(Arrays.asList(i, n / i))); } } } return ans; } static boolean isValid(int v, List<List<Integer>> v2Div, StringBuilder ans) { for (List<Integer> row:v2Div) { int v1 = row.get(0); int v2 = row.get(1); if (v != v1 && v != v2 && v1 != v2) { ans.append("YES\n"). append(String.format("%d %d %d\n", v, v1, v2)); return true; } } return false; } } class Pair { int index; int level; public Pair(int index, int level) { this.index = index; this.level = level; } @Override public String toString() { return index + " " + level; } } class Reader { private BufferedReader reader; private String line[]; public Reader() { reader = new BufferedReader(new InputStreamReader(System.in)); } public String[] getLine() { return line; } public boolean readLine() throws IOException { String str = reader.readLine(); if (str == null || str.isEmpty()) return false; line = line = str.split(" "); return true; } public List<Integer> getIntegersList() { List<Integer> res = new ArrayList<>(); for (String str:line) res.add(Integer.parseInt(str)); return res; } public Set<Integer> getIntegersSet() { Set<Integer> res = new HashSet<>(); for (String str:line) res.add(Integer.parseInt(str)); return res; } public List<Long> getLongsList() { List<Long> res = new ArrayList<>(); for (String str:line) res.add(Long.parseLong(str)); return res; } public int readInt(int pos)throws IOException { return Integer.parseInt(line[pos]); } public double readDouble(int pos)throws IOException { return Double.parseDouble(line[pos]); } public long readLong(int pos)throws IOException { return Long.parseLong(line[pos]); } public String readString(int pos)throws IOException { return line[pos]; } public void close()throws IOException { reader.close(); } }
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 solve(): n = int(input()) primes = {} i = 2 while i * i <= n: while n % i == 0: primes[i] = primes.get(i, 0) + 1 n //= i i += 1 if n > 1: primes[n] = primes.get(n, 1) k = list(primes.keys()) v = list(primes.values()) if len(primes) >= 3: print("YES") print(k[0] ** primes[k[0]], k[1] ** primes[k[1]], end=' ') third = 1 for i in range(2, len(k)): third *= k[i] ** primes[k[i]] print(third) else: if len(primes) == 1: if sum(v) >= 6: print("YES") print(k[0], k[0] ** 2, k[0] ** (v[0] - 3)) else: print("NO") elif len(primes) == 2: if v[0] <= 1 and v[1] <= 1: print("NO") elif (v[0] == 1 and v[1] == 2) or (v[0] == 2 and v[1] == 1): print("NO") else: print("YES") print(k[0], k[1], k[0] ** (v[0] - 1) * k[1] ** (v[1] - 1)) t = int(input()) while t > 0: solve() t -= 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
from math import sqrt as s def factorization(n): a=[] while n%2==0: a.append(2) n = n//2 for i in range(3,int(s(n))+1,2): while n%i==0: a.append(i) n = n//i if n>2: a.append(n) return a for i in range(int(input())): n = int(input()) a = factorization(n) flag='hobe' if len(a)<3: flag='miao' else: res = [] res.append(a[0]) if a[1]==a[0]: res.append(a[1]*a[2]) j=3 else: res.append(a[1]) j=2 temp=1 for i in range(j,len(a)): temp=temp*a[i] if temp in res or temp==1: flag='miao' else: res.append(temp) if flag=='miao': print('NO') else: print('YES') print(*res)
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): l = [] n = int(input()) for i in range(2,n): if n%i == 0: l.append(i) n /= i if len(l) == 2 or i*i>n: break if len(l) == 2 and n!=l[0] and n!= l[1] and n>1: print("YES") print(l[0],l[1],int(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 sys import stdin, stdout from collections import defaultdict import math rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() def main(): cases = rll() for line in stdin: n = int(line) ans = [] for f1 in range(2, math.ceil(math.sqrt(n))): if n % f1 == 0: ans.append(f1) break if len(ans) == 0: stdout.write("NO\n") continue m = n//ans[0] for f2 in range(f1+1, math.ceil(math.sqrt(m))): if m % f2 == 0: ans.append(f2) break if len(ans) == 1: stdout.write("NO\n") continue a, b = ans[0], ans[1] c = n//(a*b) if c not in {a, b}: stdout.write("YES\n") stdout.write(" ".join(str(x) for x in [a, b, c])) stdout.write("\n") else: stdout.write("NO\n") stdout.close() 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
#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); } bool isPrime(long long n) { long long root = sqrt(n) + 1; for (long long i = 2; i <= root; i++) { if (n % i == 0) { return false; } } return true; } int main() { ios_base::sync_with_stdio(false); long long tt; cin >> tt; while (tt--) { long long n; cin >> n; long long cube = cbrt(n) + 1; long long a, b, c; bool flag = false; for (long long i = 2; i <= cube; i++) { long long j = i; while (j++) { long long vagfol = (n) / (i * j); long long vagses = (n) % (i * j); if (!vagses) { if (j != vagfol && i != vagfol && vagfol >= 2) { flag = true; a = i, b = j, c = vagfol; break; } } if (vagfol < j) { break; } } if (flag) break; } if (flag) { cout << "YES" << "\n"; cout << a << " " << b << " " << c << "\n"; } else 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
t = int(input()) for i in range(t): n = int(input()) p = [] j = 2 while j * j <= n: while (n % j == 0): p.append(j) n //= j j += 1 if n > 1: p.append(n) if len(p) < 3: print("NO") elif len(p) == 3: if p[0] != p[1] and p[1] != p[2] and p[0] != p[2]: print("YES") print(p[0], p[1], p[2]) else: print("NO") else: mult = 1 for x in p: mult *= x a = p[0] b = -1 for x in p: if x != a: b = x break if b != -1: print("YES") print(a, b, mult // a // b) elif len(p) >= 6: print("YES") print(p[0], p[1] * p[2], mult // p[0] // p[1] // p[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())): n = int(input()) c = [] i=2 while len(c)<2 and i**2<n: if n % i == 0: c.append(i) n=n/i i=i+1 if len(c)==2 and n not in c: print("YES") print(*c,int(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
#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); } bool isPrime(long long n) { long long root = sqrt(n) + 1; for (long long i = 2; i <= root; i++) { if (n % i == 0) { return false; } } return true; } int main() { ios_base::sync_with_stdio(false); long long tt; cin >> tt; while (tt--) { long long n; cin >> n; if (isPrime(n)) { cout << "NO" << "\n"; continue; } long long cube = cbrt(n) + 1; long long a, b, c; bool flag = false; for (long long i = 2; i <= cube; i++) { for (long long j = i + 1; 1; j++) { long long vagfol = (n) / (i * j); long long vagses = (n) % (i * j); if (!vagses) { if (j != vagfol && i != vagfol && vagfol >= 2) { flag = true; a = i, b = j, c = vagfol; break; } } if (vagfol < j) { break; } } if (flag) break; } if (flag) { cout << "YES" << "\n"; cout << a << " " << b << " " << c << "\n"; } else 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> using namespace std; int tab[50000]; int main() { int t; int long long n, a, b, c, maxi; scanf("%lld", &t); while (t--) { int s = 0; int long long i = 2, j = 2, sq; scanf("%lld", &n); sq = sqrt(n); while (n != 0 && i <= sq) { if (n % i == 0) { tab[s] = i; s++; if (s == 2) break; n /= i; } i++; } if (s == 2 && n / i >= (i + 1)) { printf("YES\n%d %d %d\n", tab[0], tab[1], n / i); } else printf("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
from math import sqrt def fatores(n): fat = {} for p in range(2, int(sqrt(n)+1)): while n % p == 0: n/=p if not fat.get(p): fat[p] = 0 fat[p]+=1 p+=1 if n > 1: fat[int(n)] = 1 return fat for _ in range(int(input())): n = int(input()) f = [list(i) for i in fatores(n).items()] q = 0 ans = [1,1,1] for i in range(len(f)): p,m = f[i] cont = 1 while cont <= f[i][1]: f[i][1] -= cont ans[q] *= (f[i][0]**cont) cont += 1 q+=1 if q == 3: break if q == 3: break # print(q) # print(f) for i in f: ans[2] *= i[0]**i[1] if ans[0] != ans[1] and ans[0] != ans[2] and ans[1] != ans[2] and min(ans) >= 2: 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
t = int(input()) for _ in range(t): n = int(input()) d = [] a = n i = 2 while i * i <= a: while a % i == 0: d.append(i) a //= i i += 1 if a != 1: d.append(a) a = d[0] b = 1 c = 1 for i in range(1, len(d)): if a == b or b == 1: b *= d[i] else: c *= d[i] if a != b and b != c and a != c and a != 1 and b != 1 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
import sys import math from collections import defaultdict from collections import deque from itertools import combinations from itertools import permutations input = lambda : sys.stdin.readline().rstrip() read = lambda : list(map(int, input().split())) go = lambda : 1/0 def write(*args, sep="\n"): for i in args: sys.stdout.write("{}{}".format(i, sep)) INF = float('inf') MOD = int(1e9 + 7) YES = "YES" NO = "NO" def f(n): ret, x = defaultdict(int), [] for i in range(2, int(n**0.5) + 1): while n % i == 0: ret[i] += 1 x.append(i) n //= i if n != 1: ret[n] += 1 x.append(n) return ret, x for _ in range(int(input())): try: n = int(input()) arr, x = f(n) if len(arr) >= 3: (x, xcnt), (y, ycnt), *c = list(arr.items()) z = 1 for i, j in c: z *= (i ** j) print(YES) print(x**xcnt, y**ycnt, z) go() if len(arr) == 2: (x, xcnt), (y, ycnt) = arr.items() if xcnt + ycnt <= 3: print(NO) go() if xcnt == 2 and ycnt == 2: print(YES) print(x, y, x*y) go() if xcnt >= 3: print(YES) print(x, x**(xcnt - 1), y**ycnt) go() if ycnt >= 3: print(YES) print(y, y**(ycnt - 1), x**xcnt) go() if len(arr) == 1: #print("== 1") (x, xcnt) = list(arr.items())[0] if xcnt <= 5: print(NO) go() else: print(YES) print(x, x*x, x**(xcnt - 3)) go() except Exception as e: continue
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 tt in range(t): n=int(input()) d={} for i in range(2,int(n**0.5)+1): if n%i==0 and i not in d: d[i]=1 n=n//i break for i in range(2,int(n**0.5)+1): if n%i==0 and i not in d: d[i]=1 n=n//i break if len(d)<2 or (n in d) or n==1: print("NO") else: print("YES") d[n]=1 for key,value in d.items(): print(key,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
import java.io.*; import java.math.BigInteger; import java.util.*; public class Main { static InputReader in = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); static int oo = (int)1e9; // static long oo = (long)1e15; static int mod = 1_000_000_007; // static int mod = 998244353; static int[] dx = {0, -1, -1, -1, 0, 1, 1, 1}; static int[] dy = {-1, -1, 0, 1, 1, 1, 0, -1}; static int M = 310; static double EPS = 1e-13; static int[][][][] memo; static boolean[][][][] visit; static boolean[][] sky; public static void main(String[] args) throws IOException { int t = in.nextInt(); out: while(t --> 0) { long n = in.nextInt(); ArrayList<Long> f = factor(n); if(f.size() == 1) { long a = f.get(0); long b = a * a; if(b >= n || a * b >= n) { System.out.println("NO"); } else { long c = n / a / b; if(c == 1 || c == a || c == b) { System.out.println("NO"); } else { System.out.println("YES"); System.out.println(a + " " + b + " " + c); } } } else { long a = f.get(0); long b = f.get(1); long c = n / a / b; if(c == 1 || c == a || c == b) { System.out.println("NO"); } else { System.out.println("YES"); System.out.println(a + " " + b + " " + c); } } } out.close(); } static ArrayList<Long> factor(long n) { ArrayList<Long> ret = new ArrayList<>(); for(long i = 2; i * i <= n; ++i) { if(n % i == 0) { ret.add(i); while(n % i == 0) n /= i; } } if(n > 1) ret.add(n); return ret; } static void update(int[] f, int i) { while(i < f.length) { f[i]++; i += (i & -i); } } static int query(int[] f, int i) { int ret = 0; while(i > 0) { ret += f[i]; i -= (i & -i); } return ret; } static long invmod(long a, long mod) { BigInteger b = BigInteger.valueOf(a); BigInteger m = BigInteger.valueOf(mod); return b.modInverse(m).longValue(); } static int find(int[] g, int x) { return g[x] = g[x] == x ? x : find(g, g[x]); } static void union(int[] g, int[] size, int x, int y) { x = find(g, x); y = find(g, y); if(x == y) return; if(size[x] < size[y]) { g[x] = y; size[y] += size[x]; } else { g[y] = x; size[x] += size[y]; } } static class Segment { Segment left, right; int size; // int time, lazy; public Segment(long[] a, int l, int r) { super(); if(l == r) { return; } int mid = (l + r) / 2; left = new Segment(a, l, mid); right = new Segment(a, mid+1, r); } boolean covered(int ll, int rr, int l, int r) { return ll <= l && rr >= r; } boolean noIntersection(int ll, int rr, int l, int r) { return ll > r || rr < l; } // void lazyPropagation() { // if(lazy != 0) { // if(left != null) { // left.setLazy(this.time, this.lazy); // right.setLazy(this.time, this.lazy); // } // else { // val = lazy; // } // } // } // void setLazy(int time, int lazy) { // if(this.time != 0 && this.time <= time) // return; // this.time = time; // this.lazy = lazy; // } int querySize(int ll, int rr, int l, int r) { // lazyPropagation(); if(noIntersection(ll, rr, l, r)) return 0; if(covered(ll, rr, l, r)) return size; int mid = (l + r) / 2; int leftSize = left.querySize(ll, rr, l, mid); int rightSize = right.querySize(ll, rr, mid+1, r); return leftSize + rightSize; } int query(int k, int l, int r) { Segment trace = this; while(l < r) { int mid = (l + r) / 2; if(trace.left.size > k) { trace = trace.left; r = mid; } else { k -= trace.left.size; trace = trace.right; l = mid + 1; } } return l; } void update(int ll, int rr, int l, int r) { // lazyPropagation(); if(noIntersection(ll, rr, l, r)) return; if(covered(ll, rr, l, r)) { // setLazy(time, knight); this.size = 1; return; } int mid = (l + r) / 2; left.update(ll, rr, l, mid); right.update(ll, rr, mid+1, r); this.size = left.size + right.size; } } static long pow(long a, long n, long mod) { if(n == 0) return 1; if(n % 2 == 1) return a * pow(a, n-1, mod) % mod; long x = pow(a, n / 2, mod); return x * x % mod; } static int[] getPi(char[] a) { int m = a.length; int j = 0; int[] pi = new int[m]; for(int i = 1; i < m; ++i) { while(j > 0 && a[i] != a[j]) j = pi[j-1]; if(a[i] == a[j]) { pi[i] = j + 1; j++; } } return pi; } static long lcm(long a, long b) { return a * b / gcd(a, b); } static BigInteger lcm2(long a, long b) { long g = gcd(a, b); BigInteger gg = BigInteger.valueOf(g); BigInteger aa = BigInteger.valueOf(a); BigInteger bb = BigInteger.valueOf(b); return aa.multiply(bb).divide(gg); } static boolean nextPermutation(int[] a) { for(int i = a.length - 2; i >= 0; --i) { if(a[i] < a[i+1]) { for(int j = a.length - 1; ; --j) { if(a[i] < a[j]) { int t = a[i]; a[i] = a[j]; a[j] = t; for(i++, j = a.length - 1; i < j; ++i, --j) { t = a[i]; a[i] = a[j]; a[j] = t; } return true; } } } } return false; } static void shuffle(Object[] a) { Random r = new Random(); for(int i = a.length - 1; i > 0; --i) { int si = r.nextInt(i); Object t = a[si]; a[si] = a[i]; a[i] = t; } } static void shuffle(int[] a) { Random r = new Random(); for(int i = a.length - 1; i > 0; --i) { int si = r.nextInt(i); int t = a[si]; a[si] = a[i]; a[i] = t; } } static void shuffle(long[] a) { Random r = new Random(); for(int i = a.length - 1; i > 0; --i) { int si = r.nextInt(i); long t = a[si]; a[si] = a[i]; a[i] = t; } } static int lower_bound(int[] a, int n, int k) { int s = 0; int e = n; int m; while (e - s > 0) { m = (s + e) / 2; if (a[m] < k) s = m + 1; else e = m; } return e; } static int lower_bound(long[] a, int n, long k) { int s = 0; int e = n; int m; while (e - s > 0) { m = (s + e) / 2; if (a[m] < k) s = m + 1; else e = m; } return e; } static int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } static BigInteger gcd(BigInteger a, BigInteger b) { return b.compareTo(BigInteger.ZERO) == 0 ? a : gcd(b, a.mod(b)); } static class Pair implements Comparable<Pair> { int first, second; public Pair(int first, int second) { super(); this.first = first; this.second = second; } @Override public int compareTo(Pair o) { return this.first != o.first ? this.first - o.first : this.second - o.second; } // @Override // public int compareTo(Pair o) { // return this.first != o.first ? o.first - this.first : o.second - this.second; // } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + first; result = prime * result + second; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Pair other = (Pair) obj; if (first != other.first) return false; if (second != other.second) return false; return true; } } } class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream st) { this.stream = st; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { 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 { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = nextInt(); } return a; } 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 String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } }
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 math import ceil def find(n,p,ans): for i in range(2,ceil(n**(1/p))+1,1): if n%i==0: if p==3: ans+=find(n//i,2,[i]) if len(ans)==3: return ans ans=[] elif p==2 and n//i>1: new=ans+[(n//i),i] if len(set(new))==3: return new return ans for i in range(int(input())): n=int(input()) k=find(n,3,[]) if len(k)==3: print("YES") print(*k,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
# -*- coding: utf-8 -*- from math import sqrt def main(): for _ in range(int(input())): n = int(input()) d = n ret = [] for i in range(2, int(sqrt(n))): if d % i == 0: d /= i ret.append(i) if len(ret) == 2: break if len(ret) < 2: print('NO') continue a, b = ret c = n // (a * b) if a == c or b == c or (a * b * c) != n: print('NO') continue print('YES') print(a, b, c) 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
t = int(input()) def find_one_factor(num, a): for i in range(2, int(num ** 0.5) + 1): if num % i == 0: if a == i: continue return i, num // i return -1, -1 while t: t -= 1 n = int(input()) flag = True factors = [] a, num = find_one_factor(n, 0) if a == -1: print("NO") continue b, num = find_one_factor(num, a) if b == -1: print("NO") continue elif b == num: print("NO") continue c = num 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
from math import sqrt T = int(input()) for case in range(T): n = int(input()) ans = False move = True for i in range(2,int(sqrt(n)) + 1): if move is False:break if n%i == 0: a = i b = int(n/a) for j in range(a + 1 , int(sqrt(n)) + 1): if (b%j == 0): b = b//j c = j if (c==b or c==a or a==b):ans = False else: move = False ans = True break if ans is True: 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
//Contribted By - Rahul Roy import java.util.*; import java.lang.*; import java.io.*; public class Main { public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out)); public static void main(String sp[])throws IOException{ FastReader sc = new FastReader(); int t = sc.nextInt(); while(t-->0){ int n = sc.nextInt(); long first = 0; long second = 0; long third = 0; compute(n); Collections.sort(al); if(hm.size()==0) System.out.println("NO"); else if(hm.size()==1){ if(al.size()<6){ System.out.println("NO"); }else{ first = al.get(0); second = al.get(1)*al.get(2); third = 1; for(int i=3;i<al.size();i++) third *= al.get(i); System.out.println("YES"); System.out.println(first+" "+second+" "+third); } }else if(hm.size()==2){ if(al.size()<=3) System.out.println("NO"); else{ first = al.get(0); int index=1; second = 1; for(int i=index;i<al.size();i++){ second*=al.get(i); index+=1; if(first!=second) break; } third = 1; for(int i=index;i<al.size();i++) third *= al.get(i); System.out.println("YES"); System.out.println(first+" "+second+" "+third); } }else{ first = al.get(0); int index=1; second = 1; for(int i=index;i<al.size();i++){ second*=al.get(i); index+=1; if(first!=second) break; } third = 1; for(int i=index;i<al.size();i++) third *= al.get(i); System.out.println("YES"); System.out.println(first+" "+second+" "+third); } hm = new HashMap<Integer,Integer>(); al = new ArrayList<Integer>(); } } static ArrayList<Integer> al = new ArrayList<>(); static HashMap<Integer,Integer> hm = new HashMap<>(); public static void compute(int n){ while (n%2==0) { al.add(2); hm.put(2,0); n /= 2; } // n must be odd at this point. So we can // skip one element (Note i = i +2) for (int i = 3; i <= Math.sqrt(n); i+= 2) { // While i divides n, print i and divide n while (n%i == 0) { al.add(i); hm.put(i,0); n /= i; } } if(n>2){ hm.put(n,0); al.add(n); } } public static class pair{ int x =0; int y=0; } public static class comp implements Comparator<pair>{ public int compare(pair o1, pair o2){ if(o1.x==o2.x) return o1.y-o2.y; return o1.x-o2.x; } } public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception r) { r.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next());//converts string to integer } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (Exception r) { r.printStackTrace(); } return str; } } } /* class Triplet{ int threeSumClosest(ArrayList<Integer> arr, int target) { int flag=0,n = arr.size(); int res=0; Collections.sort(arr); for(int i = 0 ; i < n-2 ; ++ i ) { int j = i+1, k = n-1; while(j<k) { int sum=arr.get(i)+arr.get(j)+arr.get(k); // get the sum of the triplet if(flag==0){ // if its your 1st triplet updated res res=sum; flag=1; } if(Math.abs(sum-target)<=Math.abs(res-target)) { // compare the difference if sum is closer to target then res if(Math.abs(sum-target)==Math.abs(res-target)){ if(res<sum) res=sum; } else res=sum; } if(target>sum) // if sum is smaller than target j++; else // if sum is greater than target k--; } } return res; // return the answer } } */
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
for _ in range(int(input())): n = int(input()) ans = [] i = 2 x = n while i * i <= x: if n % i == 0: if len(ans) < 2: ans.append(i) n //= i i += 1 if n not in ans and len(ans) < 3: ans.append(n) if len(ans) > 2: 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
from math import * for ct in range(int(input())): n = int(input()) flag = False for i in range(2, int(sqrt(n))): if flag: break if n % i == 0: par = n//i for j in range(2, int(sqrt(par))+1): if par % j == 0: k = par // j if i != j and j != k and i != k: print("YES") print(i, j, k) flag = True break else: for j in range(2, int(sqrt(i))+1): if i % j == 0: k = i // j if par != j and j != k and par != k: print("YES") print(par, j, k) flag = True 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 sys from os import path if(path.exists('input.txt')): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') get_int = lambda: int(input()) get_ints = lambda: map(int, input().split()) get_ints_list = lambda: list(get_ints()) from math import sqrt def factorize(n): i = 2 factors = [] while i * i <= n: if n % i == 0: p = 0 while n % i == 0: n //= i p += 1 factors.append(i) i += 1 if n != 1: factors.append(n) return factors t = get_int() for _ in range(t): n = get_int() factors = factorize(n) l = len(factors) if l < 3: print("NO") continue a, b, c = 1, 1, 1 a = factors[0] i = 1 while i < l: b *= factors[i] i += 1 if b != a: break while i < l: c *= factors[i] i += 1 if a != b and a != c and b != c and a != 1 and b != 1 and c != 1 and a*b*c == n: 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
for _ in [0]*int(input()): n = int(input()) i = 2 tt = False delim = [] while i*i <= n: if not n % i: delim.append(i) i += 1 for i in range(len(delim)): if tt == True: break for j in range(i+1, len(delim)): f = n // (delim[i]*delim[j]) if f > 1 and f not in (delim[i], delim[j]) and not n % (delim[i]*delim[j]): tt = True print("YES") print(delim[i], delim[j], f) break if tt == False: 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; for (int i = 0; i < t; i++) { long long int a, b, c, n; cin >> n; int e = 0; long long int d; for (int j = 2; j <= (int)sqrt(n); j++) { if (n % j == 0) { e = 1; d = n / j; a = j; break; } } if (e == 0) cout << "NO\n"; else { for (int j = a + 1; j <= (int)sqrt(d); j++) { if (d % j == 0 && j != d / j) { e = 2; b = j; c = d / j; break; } } if (e == 2) cout << "YES\n" << a << " " << b << " " << c << "\n"; 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
#include <bits/stdc++.h> using namespace std; template <typename T> void inpos(T &x) { x = 0; register T c = getchar(); while (((c < 48) || (c > 57)) && (c != '-')) c = getchar(); bool neg = 0; if (c == '-') neg = 1; for (; c < 48 || c > 57; c = getchar()) ; for (; c > 47 && c < 58; c = getchar()) x = (x << 3) + (x << 1) + (c & 15); if (neg) x = -x; } template <typename T> void outpos(T n) { if (n < 0) { putchar('-'); n *= -1; } char snum[65]; long long i = 0; do { snum[i++] = n % 10 + '0'; n /= 10; } while (n); i = i - 1; while (i >= 0) putchar(snum[i--]); } inline void instr(char *str) { register char c = 0; register long long i = 0; while (c < 33) c = getchar(); while (c != '\n' && c != ' ' && c != EOF) { str[i] = c; c = getchar(); ++i; } str[i] = '\0'; } template <typename T, typename TT> inline void inpos(T &n, TT &m) { inpos(n); inpos(m); } template <typename T, typename TT, typename TTT> inline void inpos(T &n, TT &m, TTT &o) { inpos(n, m); inpos(o); } template <typename T, typename TT, typename TTT, typename TTTT> inline void inpos(T &n, TT &m, TTT &o, TTTT &p) { inpos(n, m); inpos(o, p); } void functionA(long long n) { for (long long i = 2; i <= 1000; i++) { if (i > n || n % i != 0) { continue; } for (long long j = i + 1; j * j <= n; j++) { if (j > n || (n / i) % j != 0) { continue; } long long c = (n / i) / j; if (c != i && c != j) { cout << "YES\n" << i << " " << j << " " << c << '\n'; return; } } } cout << "NO\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; cin >> t; while (t--) { long long n; cin >> n; functionA(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
t = int(input()) for _ in range(t): n = num = int(input()) arr = [] div = 2 while n != 1: if div > int(n**0.5): arr.append(n) n //= div break if n % div == 0: n //= div arr.append(div) continue div += 1 if len(arr) < 3: print("NO") else: cand = [] cur = 1 while arr: cur *= arr.pop(0) if cur not in cand: cand.append(cur) cur = 1 if cur != 1: cand[-1] *= cur if len(cand) < 3: print("NO") else: while len(cand) != 3: cur = cand.pop() cand[-1] *= cur print("YES") print(*cand) # 8589934591 # 1000000007
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()) i = 2 fact = [] while n%i == 0: n = n//i fact.append(i) for i in range(3, int(sqrt(n))+1, 2): while n%i == 0: n = n//i fact.append(i) if n != 1: fact.append(n) if len(fact) < 3: print('NO') continue ans = 1 i = 0 fact.sort() if len(fact) == 3: if len(set(fact)) < 3: print('NO') continue if 4 <= len(fact) <= 5: if len(set(fact)) < 2: print('NO') continue if len(set(fact)) == 1: a = fact[0]*fact[1] b = 1 i = 2 while i < len(fact) - 1: b *= fact[i] i += 1 c = fact[-1] print('YES') print(a, b, c) else: a = fact[0] b = 1 i = 1 while i < len(fact) - 1: b *= fact[i] i += 1 c = fact[-1] 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
for _ in range(int(input())): n = int(input()) prime = [] for i in range(2, int(n ** 0.5) + 1): if n % i == 0: prime.append(i) n //= i if n != 1: prime.append(n) if len(prime) < 3: print("NO") else: if len(set(prime)) < 3: print("NO") else: ans = 1 for i in prime[2:]: ans *= i print("YES") print(prime[0], prime[1], 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 math import sqrt t= int(input()) while t: n= int(input()) r=n a=[] for i in range(2,int(sqrt(n))): if n%i==0: a.append(i) n=int(n/i) if len(a)==2: break if len(a)==2 and a[0]!=a[1] and a[1]!=n and a[0]!=n and n>=2: print("YES",a[0],a[1],n) else: print("NO") t=t-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
#include <bits/stdc++.h> using namespace std; vector<int> primefactors(int n) { vector<int> ans; while (n % 2 == 0) { ans.push_back(2); n = n / 2; } for (int i = 3; i * i <= n; i += 2) { while (n % i == 0) { ans.push_back(i); n = n / i; } } if (n > 2) { ans.push_back(n); } return ans; } int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> ans = primefactors(n); int count = 1; vector<int> un; un.push_back(ans[0]); int temp = 0; for (int i = 1; i < ans.size(); i++) { if (temp == 0) { temp = ans[i]; } else { temp *= ans[i]; } if (temp != un[i - 1]) { un.push_back(temp); break; } } if (un.size() != 2) { cout << "NO" << endl; } else { int num1 = un[0], num2 = un[1]; int num3 = n / (num1 * num2); if (num3 == 1 || num3 == num2 || num1 == num3) { cout << "NO" << endl; } else { cout << "YES" << endl; cout << num1 << " " << num2 << " " << (n / (num1 * num2)) << 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 java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Jaynil */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); CProductOfThreeNumbers solver = new CProductOfThreeNumbers(); int testCount = Integer.parseInt(in.next()); for (int i = 1; i <= testCount; i++) solver.solve(i, in, out); out.close(); } static class CProductOfThreeNumbers { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); if (n % 2 == 0) { n = n / 2; for (int i = 3; i * i < n; i++) { if (n % i == 0 && n / i != 2) { out.println("YES"); out.println(2 + " " + (n / i) + " " + i); return; } } out.println("NO"); return; } if (Maths.isPrime(n)) { out.println("NO"); return; } int x = 0; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { x = i; break; } } n = n / x; if (Maths.isPrime(n)) { out.println("NO"); return; } for (int i = 2; i * i < n; i++) { if (n % i == 0 && i != x && n / i != x) { out.println("YES"); out.println(x + " " + (n / i) + " " + i); return; } } out.println("NO"); } } static class Maths { static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(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
t = int(input()) for _ in range(t): n = int(input()) #n,k = map(int,input().split()) for a in range(2,int(n**0.5)+1): if n%a == 0:break else: print ("NO") continue ne = n//a for b in range(2,int(ne**0.5)+1): if b == a: continue if ne%b == 0:break else: print ("NO") continue if ne//b in (a,b): print ("NO") else: print ("YES") print (a,b,ne//b)
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=[] d=2 while (d*d<n) and len(a)<2: if n%d==0: a.append(d) n//=d d+=1 if len(a)<2: print("NO") else: print("YES") print(n,*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 def fastio(): from io import StringIO from atexit import register global input sys.stdin = StringIO(sys.stdin.read()) input = lambda : sys.stdin.readline().rstrip('\r\n') sys.stdout = StringIO() register(lambda : sys.__stdout__.write(sys.stdout.getvalue())) fastio() for _ in range(int(input())): n = int(input()) s='' f=x=y=0 for i in range(2,int(n**(2/3))+1): if n%i==0 and x==0: s+=str(i)+' ' x=i n//=i elif n%i==0: s+=str(i)+' ' y=i n//=i break if min([x,y,n])<2 or (x==y or y==n or x==n): print("NO") else: s+=str(n)+' ' print("YES"+'\n'+s)
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 _ in range(int(input())): n = int(input()) e = [] a = False for i in range(2, int(sqrt(n)) + 1): m = n / i if m.is_integer() == True: for j in range(2, int(sqrt(m)) + 1): if m % j == 0: if (n / (i * j)).is_integer() == True and i != j and j != (n / (i * j)) and (n / (i * j)) != i: e.append([i, j,int( n / (i * j))]) a=True break if a == False: print("NO") else: print("YES") print(*e[0])
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()) k=[] for i in range(2,10000): if n%i==0: k.append(i) n=n//i break for j in range(2,10000): if n%j==0: if j not in k: k.append(j) n=n//j break if len(k)==2: if n!=1 and n!=k[0] and n!= k[1]: print('YES') print(k[0],k[1],n) 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.Scanner; import java.util.Stack; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while (t-- > 0) { int n = s.nextInt(); int i = 2; int a = -1; int b = -1; while (i * i <= n) { if (n % i == 0) { a = i; b = getB(n / i, a); if (b != -1) break; } i++; } if (a != -1 && b != -1) System.out.println("YES\n" + a + " " + b + " " + (n / (a * b))); else System.out.println("NO"); } } private static int getB(int n, int a) { int i = 2; while (i * i < n) { if (i == a) { i++; continue; } if (n % i == 0 && (n / i) != a) return i; i++; } return -1; } }
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 a = int(input()) for x in range(a): a = int(input()) prime = 2 count = list() while prime <= math.ceil(math.sqrt(a)): if a % prime == 0: a /= prime count.append(prime) if len(count) == 2: if not a in count: print("YES") print(count[0], count[1], int(a)) break prime += 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 sys import math input = sys.stdin.readline ins = lambda: input().rstrip() ini = lambda: int(input().rstrip()) inm = lambda: map(int, input().split()) inl = lambda: list(map(int, input().split())) t = ini() ans = [] andsindex = [0] * t for _ in range(t): n = ini() i = 2 tmp = [] while n >= i * i: if n % i == 0: tmp.append(i) if len(tmp) == 3: break i += 1 if len(tmp) <= 1: ans.append("NO") elif len(tmp) >= 2: if len(tmp) == 3: if tmp[0] * tmp[1] * tmp[2] == n: ans.append("YES") andsindex[len(ans) - 1] = f"{tmp[0]} {tmp[1]} {tmp[2]}" continue y = (n / (tmp[0] * tmp[2])).is_integer() if y and n / (tmp[0] * tmp[2]) not in tmp: ans.append("YES") andsindex[len(ans) - 1] = f"{tmp[0]} {tmp[2]} {n // (tmp[0] * tmp[2])}" continue x = (n / (tmp[0] * tmp[1])).is_integer() if x and n / (tmp[0] * tmp[1]) not in tmp: ans.append("YES") andsindex[len(ans) - 1] = f"{tmp[0]} {tmp[1]} {n // (tmp[0] * tmp[1])}" else: ans.append("NO") for i in range(t): print(ans[i]) if ans[i] == "YES": print(andsindex[i])
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.*; public class Main { public static void main(String []args) throws IOException { FastScanner in = new FastScanner(System.in); PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false); solve(in, out); in.close(); out.close(); } static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); } static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); } private static int fact(int n) { int ans=1; for(int i=2;i<=n;i++) ans*=i; return ans; } public static int[] generatePrimes(int n) { boolean[] prime = new boolean[n + 1]; Arrays.fill(prime, 2, n + 1, true); for (int i = 2; i * i <= n; i++) if (prime[i]) for (int j = i * i; j <= n; j += i) prime[j] = false; int[] primes = new int[n + 1]; int cnt = 0; for (int i = 0; i < prime.length; i++) if (prime[i]) primes[cnt++] = i; return Arrays.copyOf(primes, cnt); } static class FastScanner{ BufferedReader reader; StringTokenizer st; FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;} String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;} st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();} String nextLine() {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;} int nextInt() {return Integer.parseInt(next());} long nextLong() {return Long.parseLong(next());} double nextDouble(){return Double.parseDouble(next());} char nextChar() {return next().charAt(0);} int[] nextIntArray(int n) {int[] arr= new int[n]; int i=0;while(i<n){arr[i++]=nextInt();} return arr;} long[] nextLongArray(int n) {long[]arr= new long[n]; int i=0;while(i<n){arr[i++]=nextLong();} return arr;} int[] nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;} long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;} void close(){try{reader.close();}catch(IOException e){e.printStackTrace();}} } /********* SOLUTION STARTS HERE ************/ static long ans=0L,M=(long)1e9+7; private static void solve(FastScanner in, PrintWriter out){ int t = in.nextInt(); int[] pm = generatePrimes(100000); while(t-->0){ ArrayList<Long> a = new ArrayList<>(); long n = in.nextLong(); long m = n; for(int i:pm){ int c=0; while(n%i==0){ n/=i;c++; } int p=1; while(c>=p){ a.add((long)Math.pow(i,p)); c-=p; ++p; } if(a.size()>1) break; } if(a.size()<2){out.println("NO");continue;} long tmp = m / (a.get(0)*1L*a.get(1)); if(tmp<2 || a.get(0)==tmp || a.get(1)==tmp) {out.println("NO");continue;} out.println("YES"); out.println(a.get(0)+" "+a.get(1)+" "+tmp); } } /************* SOLUTION ENDS HERE **********/ }
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 n, m; int main() { int a, b, c, d, t; scanf("%d", &t); while (t--) { int flag = 0; scanf("%d", &n); a = 0; b = 0; for (int i = 2; i < sqrt(n); i++) { if (n % i == 0) { if (a == 0) { a = i; n /= i; } else { b = i; n /= i; if (a < b && b < n) flag = 1; break; } } } if (flag) printf("YES\n%d %d %d\n", a, b, n); else 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
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int a = 2; while (a * a <= n) { if (n % a == 0) { n /= a; break; } ++a; } int b = a + 1, c = -1; while (b * b < n) { if (n % b == 0) { if (n / b != a) { c = n / b; cout << "YES" << endl << a << ' ' << b << ' ' << c << endl; return; } } ++b; } cout << "NO" << endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { solve(); } 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 math t = int(input()) for i in range(t): n = int(input()) a=0 b=0 c=0 j=2 while(j<=math.sqrt(n)): if(n%j==0): if(a==0): a=j n=int(n/j) j+=1 else: b=j c=int(n/j) break else: j+=1 if(a!=0 and b!=0 and c!=0) and(a!=b and b!=c and a!=c) and (a>=2 and b>=2 and c>=2): 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
import java.util.* ; import java.math.*; import java.io.*; public class javaTemplate { // public static final int M = 1000000007 ; public static final int M = 1000003 ; static FastReader sc = new FastReader(); // static Scanner sc = new Scanner(System.in) ; public static void main(String[] args) { int t= sc.nextInt() ; while(t -- != 0) { int n = sc.nextInt() ; int a = n , b = n , c = n ; for(int i = 2 ; i*i <= n ; i++) { if(n % i == 0) { a = i ; break ; } } n = n/a ; for(int i = 2; i*i <= n ; i++) { if(n%i == 0) { if(i != a) { b = Math.min(b, i) ; break ; } else { if((n/i) != i && (n/i) != a) { b = Math.min(b,(n/i)) ; } } } } c = n/b ; if(a!= b && b!= c && c != a && a >= 2 && b >= 2 && c >= 2) { System.out.println("YES"); System.out.println(a + " " + b + " " + c); } else { System.out.println("NO"); } } } //_________________________//Template//_____________________________________________________________________ // FAST I/O static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // Check Perfect Squre public static boolean checkPerfectSquare(double number) { double sqrt=Math.sqrt(number); return ((sqrt - Math.floor(sqrt)) == 0); } static boolean isPrime(int n) { if (n <= 1) return false; for (int i = 2; i < n; i++) { if (n % i == 0) return false; } return true; } // Modulo static int mod(int a) { return (a%M + M) % M; } // Palindrom or Not static boolean isPalindrome(StringBuilder str, int low, int high) { while (low < high) { if (str.charAt(low) != str.charAt(high)) return false; low++; high--; } return true; } // Euler Tortient fx static int Phi(int n) { int count = 0 ; for(int i = 1 ; i< n ; i++) { if(GCD(i,n) == 1) count ++ ; } return count ; } // Integer Sort 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); } // Long Sort 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); } // boolean Value static void value(boolean val) { System.out.println(val ? "YES" : "NO"); System.out.flush(); } // GCD public static long GCD(long a , long b) { if(b == 0) return a ; return GCD(b, a%b) ; } // sieve public static boolean [] sieveofEratosthenes(int n) { boolean isPrime[] = new boolean[n+1] ; Arrays.fill(isPrime, true); isPrime[0] = false ; isPrime[1] = false ; for(int i = 2 ; i * i <= n ; i++) { for(int j = 2 * i ; j<= n ; j+= i) { isPrime[j] = false ; } } return isPrime ; } // fastPower public static long fastPowerModulo(long a, long b, long n) { long res = 1 ; while(b > 0) { if((b&1) != 0) { res = (res * a % n) % n ; } a = (a % n * a % n) % n ; b = b >> 1 ; } return res ; } // check if sorted or not public static boolean isSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] > a[i + 1]) { return false; } } return true; } // Palindrom or Not static boolean isPalindrome(String str, int low, int high) { while (low < high) { if (str.charAt(low) != str.charAt(high)) return false; low++; high--; } return true; } }
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
'''input 5 64 32 97 2 12345 ''' from collections import defaultdict as dd from collections import Counter as ccd from itertools import permutations as pp from itertools import combinations as cc from random import randint as rd from bisect import bisect_left as bl from bisect import bisect_right as br import heapq as hq from math import gcd ''' Author : dhanyaabhirami Hardwork beats talent if talent doesn't work hard ''' ''' Stuck? See github resources Derive Formula Kmcode blog CP Algorithms Emaxx ''' mod=pow(10,9) +7 def inp(flag=0): if flag==0: return list(map(int,input().strip().split(' '))) else: return int(input()) # Code credits # assert(debug()==true) # for _ in range(int(input())): t=inp(1) while t: t-=1 n=inp(1) a=b=c=0 i=2 while i*i<n: if n%i==0: a=i n//=a break i+=1 if n!=1 and a!=0: i=a+1 while i*i<n: if n%i==0: b=i n//=b break i+=1 if n!=1 and b!=0: c=n print("YES") print(a,b,c) 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
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int k = n; vector<long long int> b; for (int i = 2; i < sqrt(k) + 1; i++) { if (n % i == 0) { b.push_back(i); n /= i; } if (b.size() == 2) break; } if (b.size() == 2 && n > b[1]) { cout << "YES" << "\n"; cout << b[0] << " " << b[1] << " " << n << "\n"; } else 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
def getFactors(n): fact = [] i =2 while i*i <=n: if n%i==0: fact.append(i) if(i!=n//i): fact.append(n//i) i+=1 return fact t = int(input()) while t>0: n = int(input()) fact = getFactors(n) fact.sort() found = False for i in range(len(fact)-1): for j in range(len(fact)): a = fact[i] b = fact[j] c = n//(a*b) if c in fact: if a-b!=0 and b-c!=0 and a-c!=0: print("YES") print(a,b,c) found = True break if found: break if not found: print("NO") t-=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
import math def primeFactors(n,d): # Print the number of two's that divide n while n % 2 == 0: try: if d[2]>=0: d[2]+=1 except: d[2]=1 n = n / 2 # n must be odd at this point # so a skip of 2 ( i = i + 2) can be used for i in range(3,int(math.sqrt(n))+1,2): # while i divides n , print i ad divide n while n % i== 0: try: if d[int(i)]>=0: d[int(i)]+=1 except: d[int(i)]=1 n = n / i # Condition if n is a prime # number greater than 2 if n > 2: d[int(n)]=1 return d t=int(input()) for r in range(t): n=int(input()) d=primeFactors(n,{}) if len(d)<3: try: if d[n]>=0: print("NO") except: if len(d)==1: a=1 for i in d: a=i if d[a]<6: print("NO") else: print("YES") s=str(a)+" "+str(int(a**2))+" "+str(int(a**(d[a]-3))) print(s) else: summ=0 temp=[] for i in d: summ+=d[i] temp.append(i) if summ<=3: print("NO") else: print("YES") a=temp[0] b=temp[1] s=str(int(a))+" "+str(int(b))+" " tempd=(int(a**(d[a]-1)))*(int(b**(d[b]-1))) s+=str(int(tempd)) print(s) else: l=[] for i in d: l.append(i) print("YES") s=str(int(l[0]**d[l[0]]))+" "+str(int(l[1]**d[l[1]]))+" " temp=1 for i in range(2,len(l)): temp*=(int(l[i]**d[l[i]])) s+=str(int(temp)) print(s)
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 main; import java.io.*; import java.util.*; public final class Main { BufferedReader br; StringTokenizer stk; public static void main(String[] args) throws Exception { new Main().run(); } { stk = null; br = new BufferedReader(new InputStreamReader(System.in)); } long mod = 998244353; void run() throws Exception { int t = ni(); test: while(t-- > 0) { int num = ni(); List<Integer> divs = new ArrayList<>(); for(int i = 2; i*i <= num; i++) { if(num % i == 0) { divs.add(i); divs.add(num / i); } } for(int i = 0; i < divs.size(); i++) { for(int j = i + 1; j < divs.size(); j++) { for(int k = j + 1; k < divs.size(); k++) { long a = divs.get(i); long b = divs.get(j); long c = divs.get(k); if(a * b * c == num && a != b && a != c && b != c) { System.out.println("YES"); System.out.println(a + " " + b + " " + c); continue test; } } } } System.out.println("NO"); } } //Reader & Writer String nextToken() throws Exception { if (stk == null || !stk.hasMoreTokens()) { stk = new StringTokenizer(br.readLine(), " "); } return stk.nextToken(); } String nt() throws Exception { return nextToken(); } int ni() throws Exception { return Integer.parseInt(nextToken()); } long nl() throws Exception { return Long.parseLong(nextToken()); } double nd() throws Exception { return Double.parseDouble(nextToken()); } //Some Misc methods int get(int l, int r, int[] a) { return l == 0 ? a[r] : a[r] - a[l - 1]; } void shuffle(int[] a) { Random r = new Random(); for(int i = 0; i < a.length; i++) { int idx = r.nextInt(a.length); int temp = a[i]; a[i] = a[idx]; a[idx] = temp; } } void reverse(char[] a) { for(int i = 0, j = a.length - 1; i < j; i++, j--) { char temp = a[i]; a[i] = a[j]; a[j] = temp; } } }
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 math import * t = int(input()) for z in range(t): n = int(input()) na = True sq = ceil(sqrt(n)) + 1 for a in range(2, sq): if not na: break if n % a == 0: q = n // a sq2 = ceil(sqrt(q)) + 1 for b in range(a + 1, sq2): if q % b == 0: if q // b > b: print('YES') print(a, b, q // b) na = False break if na: print('NO') ##a = n // (b * c) ##b * c = n // a = q ##b * c = q ##b = q // 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
import java.io.*; import java.util.*; public class Bacteria { public static void main(String args[]) throws IOException{ Scanner sc = new Scanner(System.in); PrintWriter pw = new PrintWriter(System.out); int t = sc.nextInt(); while(t--!=0){ int n = sc.nextInt(); int a=-1,b=-1,c=-1; int sq = (int)Math.sqrt(n); for(int i=2;i<=sq;i++){ if(n%i==0){ a=i;n=n/i; break; } } sq = (int)Math.sqrt(n); for(int i=2;i<=sq;i++){ if(n%i==0 && i!=a && i!=n/i){ b=i;c=n/i;break; } } if(a==-1 || b==-1 || c==-1){ pw.println("NO"); }else{ pw.println("YES"); pw.println(a+" "+b+" "+c); } } pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(String file) throws FileNotFoundException { br = new BufferedReader(new FileReader(file)); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public double nextDouble() throws IOException { return Double.parseDouble(next()); } public boolean ready() throws IOException { return br.ready(); } } }
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): vals = [] # Print the number of two's that divide n two = False while n % 2 == 0: vals.append(int(n)) if not two: vals.append(2) two = True n = n / 2 # n must be odd at this point # so a skip of 2 ( i = i + 2) can be used for i in range(3, int(math.sqrt(n)) + 1, 2): # while i divides n , print i ad divide n while n % i == 0: vals.append(int(n)) vals.append(i) n = n / i # Condition if n is a prime # number greater than 2 if n > 2: vals.append(int(n)) if len(vals) != 0: vals.pop(0) vals.sort() i = 1 while i < len(vals): if vals[i-1] == vals[i]: del vals[i] else: i+= 1 return vals def find3(number): factors = primeFactors(number) if len(factors) == 0: return [] finalFactors = [factors[0]] newNumber = int(number/factors[0]) factors = primeFactors(newNumber) if len(factors) == 0: return finalFactors pos = 0 if factors[pos] == finalFactors[0]: newFound = False while not newFound: if factors[pos] != finalFactors[0]: newFound = True else: pos += 1 if pos >= len(factors): return finalFactors if len(factors) == 0: finalFactors.append(newNumber) return finalFactors finalFactors.append(factors[pos]) newNumber = int(newNumber/factors[pos]) for elem in finalFactors: if newNumber == elem: return finalFactors finalFactors.append(newNumber) return finalFactors def solve(number): ans = find3(number) for i in range(len(ans)): ans[i] = str(ans[i]) if len(ans) == 3: print("YES") p = " ".join(ans) print(p) else: print("NO") input() while True: try: val = int(input()) solve(val) except EOFError: 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
/* Author: Anthony Ngene Created: 09/09/2020 - 06:52 */ import java.io.*; import java.util.*; public class C { // CodeForces.Div3.CF1385_656.P1.A mind is like a parachute. It doesn't work if it isn't open. - Frank Zappa void solver() throws IOException { int cases = in.intNext(); for (int t = 1; t <= cases; t++) { out.println(solve(in.longNext())); } } String solve(long n) { long num = n; long i = 2; StringBuilder res = new StringBuilder("YES\n"); int count = 0; long last = 0; while (i * i <= n) { if (i > num) break; if (num % i == 0) { if (count == 2) { res.append(num); return res.toString(); } count++; res.append(i).append(" "); num = num / i; last = i; } i++; } if (count >= 2 && num > last) { res.append(num); return res.toString(); } return "NO"; } // Generated Code Below: // checks: 1. edge cases 2. overflow 3. possible errors (e.g 1/0, arr[out]) 4. time/space complexity private static final FastWriter out = new FastWriter(); private static FastScanner in; static ArrayList<Integer>[] adj; private static long e97 = (long)1e9 + 7; public static void main(String[] args) throws IOException { in = new FastScanner(); new C().solver(); out.close(); } static class FastWriter { private static final int IO_BUFFERS = 128 * 1024; private final StringBuilder out; public FastWriter() { out = new StringBuilder(IO_BUFFERS); } public FastWriter p(Object object) { out.append(object); return this; } public FastWriter p(String format, Object... args) { out.append(String.format(format, args)); return this; } public FastWriter pp(Object... args) { for (Object ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; } public FastWriter pp(int[] args) { for (int ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; } public FastWriter pp(long[] args) { for (long ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; } public FastWriter pp(char[] args) { for (char ob : args) { out.append(ob).append(" "); } out.append("\n"); return this; } public void println(long[] arr) { for(long e: arr) out.append(e).append(" "); out.append("\n"); } public void println(int[] arr) { for(int e: arr) out.append(e).append(" "); out.append("\n"); } public void println(char[] arr) { for(char e: arr) out.append(e).append(" "); out.append("\n"); } public void println(double[] arr) { for(double e: arr) out.append(e).append(" "); out.append("\n"); } public void println(boolean[] arr) { for(boolean e: arr) out.append(e).append(" "); out.append("\n"); } public <T>void println(T[] arr) { for(T e: arr) out.append(e).append(" "); out.append("\n"); } public void println(long[][] arr) { for (long[] row: arr) out.append(Arrays.toString(row)).append("\n"); } public void println(int[][] arr) { for (int[] row: arr) out.append(Arrays.toString(row)).append("\n"); } public void println(char[][] arr) { for (char[] row: arr) out.append(Arrays.toString(row)).append("\n"); } public void println(double[][] arr) { for (double[] row: arr) out.append(Arrays.toString(row)).append("\n"); } public <T>void println(T[][] arr) { for (T[] row: arr) out.append(Arrays.toString(row)).append("\n"); } public FastWriter println(Object object) { out.append(object).append("\n"); return this; } public void toFile(String fileName) throws IOException { BufferedWriter writer = new BufferedWriter(new FileWriter(fileName)); writer.write(out.toString()); writer.close(); } public void close() throws IOException { System.out.print(out); } } static class FastScanner { private InputStream sin = System.in; private final byte[] buffer = new byte[1024]; private int ptr = 0; private int buflen = 0; public FastScanner(){} public FastScanner(String filename) throws FileNotFoundException { File file = new File(filename); sin = new FileInputStream(file); } private boolean hasNextByte() { if (ptr < buflen) { return true; }else{ ptr = 0; try { buflen = sin.read(buffer); } catch (IOException e) { e.printStackTrace(); } if (buflen <= 0) { return false; } } return true; } private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;} private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;} public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();} public String next() { if (!hasNext()) throw new NoSuchElementException(); StringBuilder sb = new StringBuilder(); int b = readByte(); while(isPrintableChar(b)) { sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public long longNext() { if (!hasNext()) throw new NoSuchElementException(); long n = 0; boolean minus = false; int b = readByte(); if (b == '-') { minus = true; b = readByte(); } if (b < '0' || '9' < b) { throw new NumberFormatException(); } while(true){ if ('0' <= b && b <= '9') { n *= 10; n += b - '0'; }else if(b == -1 || !isPrintableChar(b) || b == ':'){ return minus ? -n : n; }else{ throw new NumberFormatException(); } b = readByte(); } } public int intNext() { long nl = longNext(); if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException(); return (int) nl; } public double doubleNext() { return Double.parseDouble(next());} public long[] nextLongArray(final int n){ final long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = longNext(); return a; } public int[] nextIntArray(final int n){ final int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = intNext(); return a; } public double[] nextDoubleArray(final int n){ final double[] a = new double[n]; for (int i = 0; i < n; i++) a[i] = doubleNext(); return a; } public ArrayList<Integer>[] getAdj(int n) { ArrayList<Integer>[] adj = new ArrayList[n + 1]; for (int i = 1; i <= n; i++) adj[i] = new ArrayList<>(); return adj; } public ArrayList<Integer>[] adjacencyList(int nodes, int edges) throws IOException { return adjacencyList(nodes, edges, false); } public ArrayList<Integer>[] adjacencyList(int nodes, int edges, boolean isDirected) throws IOException { adj = getAdj(nodes); for (int i = 0; i < edges; i++) { int a = intNext(), b = intNext(); adj[a].add(b); if (!isDirected) adj[b].add(a); } return adj; } } static class u { public static int upperBound(long[] array, long obj) { int l = 0, r = array.length - 1; while (r - l >= 0) { int c = (l + r) / 2; if (obj < array[c]) { r = c - 1; } else { l = c + 1; } } return l; } public static int upperBound(ArrayList<Long> array, long obj) { int l = 0, r = array.size() - 1; while (r - l >= 0) { int c = (l + r) / 2; if (obj < array.get(c)) { r = c - 1; } else { l = c + 1; } } return l; } public static int lowerBound(long[] array, long obj) { int l = 0, r = array.length - 1; while (r - l >= 0) { int c = (l + r) / 2; if (obj <= array[c]) { r = c - 1; } else { l = c + 1; } } return l; } public static int lowerBound(ArrayList<Long> array, long obj) { int l = 0, r = array.size() - 1; while (r - l >= 0) { int c = (l + r) / 2; if (obj <= array.get(c)) { r = c - 1; } else { l = c + 1; } } return l; } static <T> T[][] deepCopy(T[][] matrix) { return Arrays.stream(matrix).map(el -> el.clone()).toArray($ -> matrix.clone()); } static int[][] deepCopy(int[][] matrix) { return Arrays.stream(matrix).map(int[]::clone).toArray($ -> matrix.clone()); } static long[][] deepCopy(long[][] matrix) { return Arrays.stream(matrix).map(long[]::clone).toArray($ -> matrix.clone()); } private static void sort(int[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); } private static void sort(long[][] arr){ Arrays.sort(arr, Comparator.comparingDouble(o -> o[0])); } private static <T>void rSort(T[] arr) { Arrays.sort(arr, Collections.reverseOrder()); } private static void customSort(int[][] arr) { Arrays.sort(arr, new Comparator<int[]>() { public int compare(int[] a, int[] b) { if (a[0] == b[0]) return Integer.compare(a[1], b[1]); return Integer.compare(a[0], b[0]); } }); } public static int[] swap(int[] arr, int left, int right) { int temp = arr[left]; arr[left] = arr[right]; arr[right] = temp; return arr; } public static int[] reverse(int[] arr, int left, int right) { while (left < right) { int temp = arr[left]; arr[left++] = arr[right]; arr[right--] = temp; } return arr; } public static boolean findNextPermutation(int[] data) { if (data.length <= 1) return false; int last = data.length - 2; while (last >= 0) { if (data[last] < data[last + 1]) break; last--; } if (last < 0) return false; int nextGreater = data.length - 1; for (int i = data.length - 1; i > last; i--) { if (data[i] > data[last]) { nextGreater = i; break; } } data = swap(data, nextGreater, last); data = reverse(data, last + 1, data.length - 1); return true; } public static int biSearch(int[] dt, int target){ int left=0, right=dt.length-1; int mid=-1; while(left<=right){ mid = (right+left)/2; if(dt[mid] == target) return mid; if(dt[mid] < target) left=mid+1; else right=mid-1; } return -1; } public static int biSearchMax(long[] dt, long target){ int left=-1, right=dt.length; int mid=-1; while((right-left)>1){ mid = left + (right-left)/2; if(dt[mid] <= target) left=mid; else right=mid; } return left; } public static int biSearchMaxAL(ArrayList<Integer> dt, long target){ int left=-1, right=dt.size(); int mid=-1; while((right-left)>1){ mid = left + (right-left)/2; if(dt.get(mid) <= target) left=mid; else right=mid; } return left; } private static <T>void fill(T[][] ob, T res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}} private static void fill(boolean[][] ob,boolean res){for(int i=0;i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}} private static void fill(int[][] ob, int res){ for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}} private static void fill(long[][] ob, long res){ for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}} private static void fill(char[][] ob, char res){ for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}} private static void fill(double[][] ob, double res){for(int i=0; i<ob.length; i++){ for(int j=0; j<ob[0].length; j++){ ob[i][j] = res; }}} private static void fill(int[][][] ob,int res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}} private static void fill(long[][][] ob,long res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}} private static <T>void fill(T[][][] ob,T res){for(int i=0;i<ob.length;i++){for(int j=0;j<ob[0].length;j++){for(int k=0;k<ob[0][0].length;k++){ob[i][j][k]=res;}}}} private static void fill_parent(int[] ob){ for(int i=0; i<ob.length; i++) ob[i]=i; } private static boolean same3(long a, long b, long c){ if(a!=b) return false; if(b!=c) return false; if(c!=a) return false; return true; } private static boolean dif3(long a, long b, long c){ if(a==b) return false; if(b==c) return false; if(c==a) return false; return true; } private static double hypotenuse(double a, double b){ return Math.sqrt(a*a+b*b); } private static long factorial(int n) { long ans=1; for(long i=n; i>0; i--){ ans*=i; } return ans; } private static long facMod(int n, long mod) { long ans=1; for(long i=n; i>0; i--) ans = (ans * i) % mod; return ans; } private static long lcm(long m, long n){ long ans = m/gcd(m,n); ans *= n; return ans; } private static long gcd(long m, long n) { if(m < n) return gcd(n, m); if(n == 0) return m; return gcd(n, m % n); } private static boolean isPrime(long a){ if(a==1) return false; for(int i=2; i<=Math.sqrt(a); i++){ if(a%i == 0) return false; } return true; } static long modInverse(long a, long mod) { /* Fermat's little theorem: a^(MOD-1) => 1 Therefore (divide both sides by a): a^(MOD-2) => a^(-1) */ return binpowMod(a, mod - 2, mod); } static long binpowMod(long a, long b, long mod) { long res = 1; while (b > 0) { if (b % 2 == 1) res = (res * a) % mod; a = (a * a) % mod; b /= 2; } return res; } private static int getDigit2(long num){ long cf = 1; int d=0; while(num >= cf){ d++; cf = 1<<d; } return d; } private static int getDigit10(long num){ long cf = 1; int d=0; while(num >= cf){ d++; cf*=10; } return d; } private static boolean isInArea(int y, int x, int h, int w){ if(y<0) return false; if(x<0) return false; if(y>=h) return false; if(x>=w) return false; return true; } private static ArrayList<Integer> generatePrimes(int n) { int[] lp = new int[n + 1]; ArrayList<Integer> pr = new ArrayList<>(); for (int i = 2; i <= n; ++i) { if (lp[i] == 0) { lp[i] = i; pr.add(i); } for (int j = 0; j < pr.size() && pr.get(j) <= lp[i] && i * pr.get(j) <= n; ++j) { lp[i * pr.get(j)] = pr.get(j); } } return pr; } static long nPrMod(int n, int r, long MOD) { long res = 1; for (int i = (n - r + 1); i <= n; i++) { res = (res * i) % MOD; } return res; } static long nCr(int n, int r) { if (r > (n - r)) r = n - r; long ans = 1; for (int i = 1; i <= r; i++) { ans *= n; ans /= i; n--; } return ans; } static long nCrMod(int n, int r, long MOD) { long rFactorial = nPrMod(r, r, MOD); long first = nPrMod(n, r, MOD); long second = binpowMod(rFactorial, MOD-2, MOD); return (first * second) % MOD; } static void printBitRepr(int n) { StringBuilder res = new StringBuilder(); for (int i = 0; i < 32; i++) { int mask = (1 << i); res.append((mask & n) == 0 ? "0" : "1"); } out.println(res); } static String bitString(int n) {return Integer.toString(n);} static int setKthBitToOne(int n, int k) { return (n | (1 << k)); } // zero indexed static int setKthBitToZero(int n, int k) { return (n & ~(1 << k)); } static int invertKthBit(int n, int k) { return (n ^ (1 << k)); } static boolean isPowerOfTwo(int n) { return (n & (n - 1)) == 0; } static HashMap<Character, Integer> counts(String word) { HashMap<Character, Integer> counts = new HashMap<>(); for (int i = 0; i < word.length(); i++) counts.merge(word.charAt(i), 1, Integer::sum); return counts; } static HashMap<Integer, Integer> counts(int[] arr) { HashMap<Integer, Integer> counts = new HashMap<>(); for (int value : arr) counts.merge(value, 1, Integer::sum); return counts; } static HashMap<Long, Integer> counts(long[] arr) { HashMap<Long, Integer> counts = new HashMap<>(); for (long l : arr) counts.merge(l, 1, Integer::sum); return counts; } static HashMap<Character, Integer> counts(char[] arr) { HashMap<Character, Integer> counts = new HashMap<>(); for (char c : arr) counts.merge(c, 1, Integer::sum); return counts; } static long hash(int x, int y) { return x* 1_000_000_000L +y; } static final Random random = new Random(); static void sort(int[] a) { int n = a.length;// shuffle, then sort for (int i = 0; i < n; i++) { int oi = random.nextInt(n), temp = a[oi]; a[oi] = a[i]; a[i] = temp; } Arrays.sort(a); } static void sort(long[] arr) { shuffleArray(arr); Arrays.sort(arr); } static void shuffleArray(long[] arr) { int n = arr.length; for(int i=0; i<n; ++i){ long tmp = arr[i]; int randomPos = i + random.nextInt(n-i); arr[i] = arr[randomPos]; arr[randomPos] = tmp; } } } static class Tuple implements Comparable<Tuple> { long a; long b; long c; public Tuple(long a, long b) { this.a = a; this.b = b; this.c = 0; } public Tuple(long a, long b, long c) { this.a = a; this.b = b; this.c = c; } public long getA() { return a; } public long getB() { return b; } public long getC() { return c; } public int compareTo(Tuple other) { if (this.a == other.a) { if (this.b == other.b) return Long.compare(this.c, other.c); return Long.compare(this.b, other.b); } return Long.compare(this.a, other.a); } @Override public int hashCode() { return Arrays.deepHashCode(new Long[]{a, b, c}); } @Override public boolean equals(Object o) { if (!(o instanceof Tuple)) return false; Tuple pairo = (Tuple) o; return (this.a == pairo.a && this.b == pairo.b && this.c == pairo.c); } @Override public String toString() { return String.format("(%d %d %d) ", this.a, this.b, this.c); } } private static int abs(int a){ return (a>=0) ? a: -a; } private static int min(int... ins){ int min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; } private static int max(int... ins){ int max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; } private static int sum(int... ins){ int total = 0; for (int v : ins) { total += v; } return total; } private static long abs(long a){ return (a>=0) ? a: -a; } private static long min(long... ins){ long min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; } private static long max(long... ins){ long max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; } private static long sum(long... ins){ long total = 0; for (long v : ins) { total += v; } return total; } private static double abs(double a){ return (a>=0) ? a: -a; } private static double min(double... ins){ double min = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] < min) min = ins[i]; } return min; } private static double max(double... ins){ double max = ins[0]; for(int i=1; i<ins.length; i++){ if(ins[i] > max) max = ins[i]; } return max; } private static double sum(double... ins){ double total = 0; for (double v : ins) { total += v; } return total; } }
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.*; import java.io.*; public class Main{ public static void main(String[] args)throws IOException{ Scanner sc = new Scanner(System.in); long a,b,c,d,e,f,g,h,i,j,k; a = sc.nextLong(); for(b = 0;b < a;b++){ c = sc.nextLong(); d = (long)Math.sqrt(c); if(c % 2 == 0){ e = c/2; i = 0; g = 0; h = 0; for(f = 3;f <= d;f++){ if(e % f == 0 && e % (e/f) == 0 && (e/f) > 2 && (e/f) != f){ g = f; h = e/f; i = 1; break; } } if(i == 1){ System.out.println("YES"); System.out.println(2+" "+g+" "+h); }else{ System.out.println("NO"); } }else{ e =c; i = 0; j = 0; k = 0; g = 0; h = 0; for(f = 3;f <= d;f++){ if(c % f == 0){ e = c/f; k = f; i = 1; break; } } if(i == 1){ for(f = 2;f <= d;f++){ if(e % f == 0 && e % (e/f) == 0 && (e/f) >= 2 && (e/f) != f && (e/f) != k && f != k){ g = f; h = e/f; j = 1; break; } } if(j == 1){ System.out.println("YES"); System.out.println(k+" "+g+" "+h); }else{ System.out.println("NO"); } }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
t=int(input()) for _ in range(t): n=int(input()) tf=False for i in range(2,int(n**(1/2))+1): if n%i==0: a=i b=n//i tf=True break if tf: tf=False for i in range(2,int(b**(1/2))+1): if b%i==0: if i!=a and b//i!=a and b//i!=i: c=b//i b=i tf=True break if tf: print('YES') print(a,b,c) 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 ceil, sqrt t = int(input()) for _ in range(t): n = int(input()) if n < 24: print('NO') else: try: for i in range(4, ceil(sqrt(n)) + 1): if n % i == 0: a = n // i b = i for j in range(2, ceil(sqrt(a))): if a % j == 0 and j != b and a // j != b and a // j > 1: print('YES') print(b, j, a // j) raise SystemExit for j in range(2, ceil(sqrt(b))): if b % j == 0 and j != a and b // j != a and b // j > 1: print('YES') print(a, j, b // j) raise SystemExit except SystemExit: continue 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): n = int(input()) L, a, r = [], n, [] m = math.ceil(math.sqrt(n)) f = False for j in range(2, m+1): if a % j == 0: c = 0 while a % j == 0: a //= j c += 1 L.append((j, c)) if c >= 3: if c >= 6: if j not in r: r.append(j) if j * j not in r: r.append(j * j) if j ** 3 not in r: r.append(j ** 3) a *= j ** (c - 6) else: if j not in r: r.append(j) if j * j not in r: r.append(j * j) a *= j ** (c - 3) else: if j not in r: r.append(j) a *= j ** (c - 1) if len(r) > 3: c = 1 for k in range(3, len(r)): c *= r[k] r[2] *= c while len(r) > 3: r.pop() if len(r) == 3: r[2] *= a f = True break elif len(r) == 2 and a > 1 and a != r[0] and a != r[1]: r.append(a) f = True break if f: print("YES") print(r[0], r[1], r[2]) else: print("NO")
PYTHON3