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 smallestDivisor(n, a): if not n & 1 and a != 2: return 2 i = 3 while i*i <= n: if n % i == 0 and a != i: return i i += 1 return n t = int(input()) for _ in range(t): n = int(input()) a = smallestDivisor(n, 1) b = smallestDivisor(n//a, a) c = n//(a*b) if a < b and b < 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
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; vector<long long> ans; pair<long long, long long> a[N]; long long n, T; void f(long long n) { ans.clear(); long long x = n; for (long long i = 2; i * i <= x; i++) { while (x % i == 0) { ans.push_back(i); x = x / i; } } ans.push_back(x); if (x == n) { cout << "NO" << endl; } else { if (ans.size() >= 3) { long long k = 2; long long x1 = ans[0]; long long x2 = ans[1]; if (x2 == x1) x2 = ans[1] * ans[2], k = 3; long long x3 = 1; for (long long i = k; i < ans.size(); i++) { x3 *= ans[i]; } if (x2 != x3 && x1 != x3 && x3 != 1) { cout << "YES" << endl; cout << x1 << " " << x2 << " " << x3 << endl; } else { cout << "NO" << endl; } } else { cout << "NO" << endl; } } } int main() { cin >> T; while (T--) { cin >> n; f(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 java.io.*; import java.util.*; public class Solution{ static FastReader in = new FastReader(); //static BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws Exception{ int t = in.nextInt(); while(t-- > 0){ int n = in.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"); } in.close(); } 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; } static class FastReader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public FastReader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public FastReader(String file_name) throws IOException { din = new DataInputStream(new FileInputStream(file_name)); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public String readLine() throws IOException { byte[] buf = new byte[64]; // line length int cnt = 0, c; while ((c = read()) != -1) { if (c == '\n') break; buf[cnt++] = (byte) c; } return new String(buf, 0, cnt); } public int nextInt() throws IOException { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public long nextLong() throws IOException { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (neg) return -ret; return ret; } public double nextDouble() throws IOException { double ret = 0, div = 1; byte c = read(); while (c <= ' ') c = read(); boolean neg = (c == '-'); if (neg) c = read(); do { ret = ret * 10 + c - '0'; } while ((c = read()) >= '0' && c <= '9'); if (c == '.') { while ((c = read()) >= '0' && c <= '9') { ret += (c - '0') / (div *= 10); } } if (neg) return -ret; return ret; } private void fillBuffer() throws IOException { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws IOException { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } public void close() throws IOException { if (din == null) return; din.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
t = int(input()) for _ in range(t): n = int(input()) l1 = [] i = 2 while len(l1)<2 and i*i <n: if n%i == 0: l1.append(i) n = n//i i+=1 if len(l1)==2: print('YES') for i in l1: print (i,end = ' ') print(n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def find_div(x, j): for i in range(2, int(x**.5)+1): if x % i == 0 and i != j and x//i !=j and i != x//i: return True, i, x//i return False, -1, -1 t = int(input()) for _ in range(t): n = int(input()) for i in range(2, int(n**.5)+1): if n % i == 0: ok, a, b = find_div(n//i, i) if ok: print('YES') print(i, a, b) 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
t=int(input()) while(t): t-=1 n=int(input()) f=set() for i in range(2,int(pow(n,0.5))+1): if(n%i==0): f.add(i) f.add(n//i) flag=0 for i in f: x=n//i for j in f: if(x%j==0): z=[i,x//j,j] p=i*j*(x//j) if(len(set(z))==3 and p==n and i!=1 and x!=1 and x//j!=1): flag=1 break if(flag==1): break if(flag==0): print("NO") else: print("YES") print(*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.Scanner; public class ProductofThreeNumbers { public static int findFirstDivisor(int n, int t) { for (int i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0 && n / i != t && i != t && n != i && n / i != i) { return i; } } return 0; } public static void main(String args[]) { Scanner scan = new Scanner(System.in); int testCase = scan.nextInt(); StringBuffer sb = new StringBuffer(); while (testCase-- > 0) { int n = scan.nextInt(); int firstSmallestDivisor = 0; int firstBigestDivisor = 0; boolean ch = false; for (int i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) { firstSmallestDivisor = i; firstBigestDivisor = n / i; break; } } if (firstSmallestDivisor == 0) { sb.append("NO\n"); continue; } else { int f = findFirstDivisor(firstSmallestDivisor, firstBigestDivisor); int l = findFirstDivisor(firstBigestDivisor, firstSmallestDivisor); if (f == 0 && l == 0) { sb.append("NO\n"); continue; } else { if (f > 0) { if (f != firstBigestDivisor && firstSmallestDivisor / f > 1 && firstSmallestDivisor / f != firstBigestDivisor) { sb.append("YES\n"); sb.append(f + " " + firstSmallestDivisor / f + " " + firstBigestDivisor + "\n"); continue; } } if (l > 0 && !ch) { if (l != firstSmallestDivisor && firstBigestDivisor / l > 1 && firstBigestDivisor / l != firstSmallestDivisor) { sb.append("YES\n"); sb.append(l + " " + firstSmallestDivisor + " " + firstBigestDivisor / l + "\n"); continue; } } sb.append("NO\n"); } } } System.out.println(sb); } }
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 from collections import Counter def primeFactors(n): # Print the number of two's that divide n l = [] while n % 2 == 0: l.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: l.append(int(i)) n = n / i # Condition if n is a prime # number greater than 2 if n > 2: l.append(int(n)) return l, Counter(l) if __name__ == '__main__': for _ in range(int(input().strip())): n = int(input().strip()) ll, pf = primeFactors(n) ll.sort() if len(pf) >= 3: print("YES") a = ll[0] b = ll[-1] c = 1 for i in range(1, len(ll) - 1): c *= ll[i] print(int(a), int(b), int(c)) elif len(pf) == 2: if len(ll) >= 4: print("YES") a = ll[0] b = ll[-1] c = 1 for i in range(1, len(ll) - 1): c *= ll[i] print(int(a), int(b), int(c)) else: print("NO") else: if len(ll) >= 6: print("YES") tot = ll[0] ** len(ll) print(ll[0], ll[0] ** 2, (tot // (ll[0] * (ll[0] * ll[0])))) 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()) ok = False for i in range(2, int(n**0.5)+1): if n % i ==0: p = n//i if p == i: continue for j in range(i+1, int(p**0.5)+1): if p%j == 0: if j*j!=p and p//j != i: print('YES') print(i,j,p//j) ok = True break if ok: break if not ok: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for _ in range(int(input())): n=int(input()) l=[] for i in range(2,int(math.sqrt(n))+1): if(n%i==0): t=n l.append(i) t=t//i for j in range(2,int(math.sqrt(t)+1)): if(t%j==0): l.append(j) l.append(t//j) if(len(set(l))==3): break if(len(set(l))==3): break else: l=[] if(len(l)==3): print("YES") print(l[0],l[1],l[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
/*package whatever //do not write package name here */ import java.util.*; public class GFG { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); while(t-- > 0){ long num = sc.nextLong(); long n = num; int count = 0; long[] arr = new long[3]; for(long i = 2;i * i <= num;i++){ if(n % i == 0){ n /= i; arr[count] = i; count++; } if(count == 2){ arr[count] = n; break; } } if(count < 2 || arr[0] == arr[2] || arr[1] == arr[2]){ System.out.println("NO"); }else{ System.out.println("YES"); System.out.println(arr[0] + " " + arr[1] + " " + arr[2]); } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin, stdout cin = stdin.readline cout = stdout.write mp = lambda:list(map(int, cin().split())) t, = mp() for _ in range(t): n, = mp() if n < 24: cout('NO\n') continue y = int(n**.5) l = [] for i in range(2, y+1): if not n%i: l += [i, n//i] if len(l)<4: cout('NO\n') continue l.sort() #print(l) for i in range(len(l)): if not n%(l[i]*l[i+1]) and l[i]*l[i+1] < n and (n//(l[i]*l[i+1]) != l[i] and n//(l[i]*l[i+1]) != l[i+1]): cout('YES\n') cout(str(l[i]) + ' ' + str(l[i+1]) + ' ' + str(n//(l[i]*l[i+1])) + '\n') break elif l[i]*l[i+1] >= n: cout('NO\n') break #print(l)
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 Solution{ public static void main(String[] args) throws Exception{ BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(buffer.readLine()); while(t-- > 0){ long num = Long.parseLong(buffer.readLine()); int a=-1,b= -1, c=-1; boolean check = false; for(int i=2; i*i<=num; i++){ if(num % i == 0){ a = i; int n = (int)num/a; for(int j=2; j*j<=n && j!= a && n/j != a; j++){ if(n % j == 0){ if(j != n/j){ b = j; c = n/j; check = true; break; } } } if(check) break; } } if(check){ System.out.println("YES"); System.out.println(a + " " + b + " " + c); } 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
for _ in range(int(input())): n=int(input()) a=[] f=n i=2 while len(a)<2 and i*i<=n: if n%i==0: a.append(i) n=n//i i+=1 if len(a)<2 or n in a: print('NO') else: print('YES') print(*a,n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; import java.util.HashSet; import java.util.Scanner; import java.util.StringTokenizer; public class Main { static int MOD = (int) (1e9 +7); public static class Point implements Comparable<Point> { public static final double EPS = 1e-9; public double x, y; public Point(double a, double b) { x = a; y = b; } public int compareTo(Point p) { if(Math.abs(x - p.x) > EPS) return x > p.x ? 1 : -1; if(Math.abs(y - p.y) > EPS) return y > p.y ? 1 : -1; return 0; } } public static void main(String[] args) throws NumberFormatException, IOException { //BufferedReader br = new BufferedReader(new FileReader("input.txt")); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st ; Scanner sc = new Scanner(System.in); //PrintWriter out = new PrintWriter("output.txt"); PrintWriter out = new PrintWriter(System.out); int test = sc.nextInt(); sieve(1000000); while(test-->0) { int n = sc.nextInt(); ArrayList<Integer> fact = new ArrayList<>(); fact = primeFactors(n); if(fact.size() >= 3) { int a = fact.get(0); int b = fact.get(1); int i = 2; while(b == a && i<fact.size()) { b*=fact.get(i); i++; } int c = n/(b*a); if(a == b || a == c || c == b || c == 1) out.println("NO"); else { out.println("YES"); out.println(a+" " +b+" "+c); } } else out.println("NO"); } out.flush(); out.close(); } static ArrayList<Integer> primes; static int[] isComposite; /* * 1. Generating a list of prime factors of N */ static ArrayList<Integer> primeFactors(int N) // O(sqrt(N) / ln sqrt(N)) { ArrayList<Integer> factors = new ArrayList<Integer>(); //take abs(N) in case of -ve integers int idx = 0, p = primes.get(idx); while(p * p <= N) { while(N % p == 0) { factors.add(p); N /= p; } p = primes.get(++idx); } if(N != 1) // last prime factor may be > sqrt(N) factors.add(N); // for integers whose largest prime factor has a power of 1 return factors; } static void sieve(int N) // O(N log log N) { isComposite = new int[N+1]; isComposite[0] = isComposite[1] = 1; // 0 indicates a prime number primes = new ArrayList<Integer>(); for (int i = 2; i <= N; ++i) //can loop till i*i <= N if primes array is not needed O(N log log sqrt(N)) if (isComposite[i] == 0) //can loop in 2 and odd integers for slightly better performance { primes.add(i); if(1l * i * i <= N) for (int j = i * i; j <= N; j += i) // j = i * 2 will not affect performance too much, may alter in modified sieve isComposite[j] = 1; } } /* * 2. Primality Test * * Preprocessing: call sieve with sqrt(N), O(sqrt(N) log log sqrt(N)) * Query: best case O(1), worst case O(sqrt(N) / log sqrt(N)) */ static boolean isPrime(int N) { if(N < isComposite.length) return isComposite[N] == 0; for(int p: primes) //may stop if p * p > N if(N%p==0) return false; return true; } /* * 3. Sieve of Eratostheses in linear time */ static void sieveLinear(int N) { ArrayList<Integer> primes = new ArrayList<Integer>(); int[] lp = new int[N + 1]; //lp[i] = least prime divisor of i for(int i = 2; i <= N; ++i) { if(lp[i] == 0) { primes.add(i); lp[i] = i; } int curLP = lp[i]; for(int p: primes) if(p > curLP || p * i > N) break; else lp[p * i] = i; } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
/* package codechef; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Codechef { public static ArrayList<Long> primeFactors(long n) { ArrayList<Long> arr=new ArrayList<>(); // Print the number of 2s that divide n while (n%2==0) { arr.add(2l); n /= 2; } // n must be odd at this point. So we can // skip one element (Note i = i +2) for (long i = 3; i <= Math.sqrt(n); i+= 2) { // While i divides n, print i and divide n while (n%i == 0) { arr.add(i); n /= i; } } // This condition is to handle the case whien // n is a prime number greater than 2 if (n > 2) arr.add(n); return arr; } public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int y=0;y<t;++y) { long n=sc.nextLong(); ArrayList<Long> arr = primeFactors(n); if(arr.size()<3) { System.out.println("NO"); continue; } if(arr.size()==3) { long a=arr.get(0); long b=arr.get(1); long c=arr.get(2); if(a==b || b==c || a==c) { System.out.println("NO"); continue; } else{ System.out.println("YES"); System.out.println(a+" "+b+" "+c); continue; } } long a=arr.get(0); long b=0; if(arr.get(0)==arr.get(1)) { b=arr.get(1)*arr.get(2); } else{ b=arr.get(1); } long c=n/(a*b); //System.out.println(a+" akshay "+b+" "+c); if(a==b || b==c || a==c) { System.out.println("NO"); continue; } else{ System.out.println("YES"); System.out.println(a+" "+b+" "+c); continue; } } } }
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 sqrt def two_dist(n, k): ans = [] for i in range(2, int(sqrt(n))+5): if n % i == 0: if i != n//i and i != k and n//i != k and n//i >= 2: return [i, n//i] return False for _ in range(int(input())): n = int(input()) ans = [] for p in range(2, int(sqrt(n))+4): if n % p == 0: find = two_dist(n//p, p) if find: ans = [p]+find break if ans: print("YES") print(" ".join(str(k) for k in 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
def foo(n): x=pow(n,.5) x=int(x)+1 l=[] for i in range(2,x): if n%i==0: z=n//i l.append(i) if z!=i: l.append(z) l.sort() if len(l)>=3: for i in range(0,len(l)-1): k=l[i]*l[i+1] z=n//k if (z in l) and z!=l[i] and z!=l[i+1]: print("YES") k=[l[i],l[i+1],z] print(*k) return print("NO") else: return print("NO") t=int(input()) for t1 in range(0,t): n=int(input()) foo(n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.PriorityQueue; import java.util.StringTokenizer; public class productOfThree { static BufferedReader b = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter p = new PrintWriter(System.out); public static void main(String arg[]) throws IOException { int t = Integer.parseInt(b.readLine()); while(t > 0){ t--; int prod = Integer.parseInt(b.readLine()); int k = prod; int a = 0; int b = 0; int c = 0; for(int x = 2; x < Math.sqrt(k); x++){ if(k % x == 0){ if(a == 0){ a = x; } else { b = x; break; } k /= x; } } if(a == 0 || b == 0){ p.println("NO"); } else { c = prod / a / b; if(c == a || c == b || c == 1){ p.println("NO"); } else { p.println("YES"); p.println(a + " " + b + " " + c); } } } p.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 java.util.ArrayList; import java.util.Collections; import java.util.Scanner; import java.util.TreeSet; public class C { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for (int test = 0; test < t; test++) { n = in.nextLong(); long original = n; //TreeSet<Long> factors = factors(n); //TreeSet<Long> res = new TreeSet(); TreeSet<Long> res = factors2(n); for (long x: res){ original/=x; } if (original == 1 && res.size()==3){ System.out.println("YES"); for (long x: res){ System.out.print(x+" "); } System.out.println(); } else System.out.println("NO"); // if (factors.size()>2) { // long smallestDiv = factors.pollFirst(); // res.add(smallestDiv); // n /= smallestDiv; // // for (Long x : factors) { // if (!res.contains(x)) { // if (factors.contains(n / x)) { // res.add(x); // res.add(n / x); // break; // } // } // } // // if (res.size()==3){ // System.out.println("YES"); // for (long val: res){ // System.out.print(val+" "); // } // System.out.println(); // } // else System.out.println("NO"); // }else System.out.println("NO"); } } static long n; public static TreeSet<Long> factors2(long n) { long original = n; TreeSet<Long> list = new TreeSet<>(); for (int i = 2; i <= Math.sqrt(original); i++) { if (n % i == 0) { if (!list.contains((long)i)){ list.add((long)i); n/=i; } if (list.size()==2){ if (original % n == 0){ list.add(n); break; } } } } //list.add(n); return list; } public static TreeSet<Long> factors(long n) { TreeSet<Long> list = new TreeSet<>(); for (int i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) { if (n / i == i) { list.add((long)i); } else { list.add((long)i); list.add(n / i); } } } return list; } static long countTwo = 0; public static TreeSet<Long> primeFactors(Long n) { ArrayList<Long> list = new ArrayList<>(); TreeSet<Long> tree = new TreeSet(); for (int i = 2; i * i <= n; i++) { while (n % i == 0) { if (i == 2)countTwo++; tree.add((long)i); n /= i; } } if (n > 1) { if (n == 2) countTwo++; tree.add(n); } return tree; } }
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.io.*; import java.math.*; import java.util.*; import java.lang.*; public class Main implements Runnable { static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } public static void main(String args[]) throws Exception { new Thread(null, new Main(), "Main", 1 << 26).start(); } public void run() { InputReader sc = new InputReader(System.in); // Scanner sc=new Scanner(System.in); // Random sc=new Random(); PrintWriter out = new PrintWriter(System.out); int t=sc.nextInt(); while (t-->0){ int n=sc.nextInt(); int m=n; int i=2; ArrayList<Integer> l=new ArrayList<>(); while(i*i<=n){ if(n%i==0){ while (n%i==0){ l.add(i); n/=i; } } if(i==2)i=3; else i+=2; } if(n!=1){ l.add(n); } if(l.size()==1){ out.println("NO"); } else{ int mul=1; TreeSet<Integer> h=new TreeSet<>(); for (int j = 0; j <l.size() ; j++) { mul*=l.get(j); if(!h.contains(mul)){ h.add(mul); mul=1; } } // out.println("h.size "+h.size()+" "+l); if(h.size()<3){ out.println("NO"); } else{ out.println("YES"); int f=h.pollFirst(); int s=h.pollFirst(); out.println(f+" "+s+" "+(m/(f*s))); } } } out.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 java.util.*; public class S{ static ArrayList<Integer> al=new ArrayList<>(); public static ArrayList<Integer> primeFactors(int n) { // Print the number of 2s that divide n while (n%2==0) { al.add(2); //System.out.print(2 + " "); 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) { //System.out.print(i + " "); al.add(i); n /= i; } } // This condition is to handle the case when // n is a prime number greater than 2 if (n > 2) al.add(n); //System.out.print(n); return al; } 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(); ArrayList<Integer> list = primeFactors(n); Set<Integer> s = new HashSet<>(list); //System.out.println(list); //System.out.println(s); int l = list.size(); if (l < 3) { System.out.println("NO"); } else if (l == 3) { if (s.size() == l) { System.out.println("YES"); //System.out.println(list); for(int j=0;j<list.size();j++) { System.out.print(list.get(j)+" "); } System.out.println(""); } else { System.out.println("NO"); } } else { ArrayList<Integer> ll=new ArrayList<>(); int str=0; ll.add(list.get(0)); if(list.get(1)!=list.get(0)) { ll.add(list.get(1)); str=n/(ll.get(0)*ll.get(1)); } else { ll.add(list.get(1)*list.get(2)); str=n/(ll.get(0)*ll.get(1)); } // ll.add(list.get(1)*list.get(2)); // int str=n/(ll.get(0)*ll.get(1)); if(str!=ll.get(0) && str!=ll.get(1) && str>2) { System.out.println("YES"); ll.add(str); for(int j=0;j<ll.size();j++) { System.out.print(ll.get(j)+" "); } System.out.println(""); } else { System.out.println("NO"); } } list.clear(); s.clear(); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.Scanner; /** * Created by abhay.kumar on 26/01/20. * 1294 C */ public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] query = new int[n]; for (int i = 0; i < n; i++) { query[i] = sc.nextInt(); } productOfThree(query); } private static void productOfThree(int[] query) { for (int val : query) { int a = 0; for (int i = 2; i * i <= val; i++) { if (val % i == 0) { a = i; val = val / a; break; } } if (a < 2) { System.out.println("NO"); continue; } boolean found = false; for (int i = 2; i * i <= val; i++) { if (val % i == 0 && i != a && val / i != i) { System.out.println("YES"); System.out.println(a + " " + i + " " + val / i); found = true; break; } } if (!found) { 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
import java.util.HashSet; import java.util.Iterator; import java.util.Scanner; public class Solution { private static HashSet<Integer> set = new HashSet<>(); private static void process(int num, int init){ for(int i = init; i * i <= num; i++){ if(num % i == 0){ if(set.size() == 1){ if(i != num){ set.add(i); set.add(num/ i); break; } } set.add(i); process(num / i, i + 1); break; } } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i = 0; i < n; i++){ //test cases int num = sc.nextInt(); process(num, 2); if(set.size() >= 3){ System.out.println("YES"); Iterator<Integer> it = set.iterator(); while(it.hasNext()){ System.out.print(it.next() + " "); } } else { System.out.println("NO"); } set.clear(); } } }
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> const int INF = 0x3f3f3f3f; using namespace std; const int MAXN = 1000; int prime[MAXN + 1]; void getPrime() { memset(prime, 0, sizeof(prime)); for (int i = 2; i <= MAXN; i++) { if (!prime[i]) prime[++prime[0]] = i; for (int j = 1; j <= prime[0] && prime[j] <= MAXN / i; j++) { prime[prime[j] * i] = 1; if (i % prime[j] == 0) break; } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; getPrime(); for (int te = 0; te < t; te++) { int n; cin >> n; int res[3]; int flag = 0; for (int i = 2; i <= 10000; i++) { if (n % i != 0) { continue; } else { int temp = n / i; for (int j = i + 1; j <= 10000; j++) { if (temp % j != 0) { continue; } else if (temp / j <= j) { break; } else { res[0] = i; res[1] = j; res[2] = temp / res[1]; flag = 1; break; } } if (flag == 1) { break; } } } if (flag == 1) { cout << "YES" << "\n"; cout << res[0] << " " << res[1] << " " << res[2] << "\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
import java.util.*; public class MyClass { 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 b=0; int arr[]=new int[3]; for(int j=2;j*j<n;j++) { if(n%j==0) { arr[0]=j; int h=n/j; for(int k=j+1;k*k<h;k++) { if(h%k==0) { arr[1]=k; arr[2]=h/k; break; } } break; } } int g=0; Arrays.sort(arr); for(int j=0;j<2;j++) { if(arr[j]==arr[j+1]||arr[j]==0||arr[j+1]==0) g=1; } if(g==0) { System.out.println("YES"); System.out.println(arr[0]+" "+arr[1]+" "+arr[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; template <class T> void read(T &u) { u = 0; char c = getchar(); long long flag = 0; while (c < '0' || c > '9') flag |= (c == '-'), c = getchar(); while (c >= '0' && c <= '9') u = (u << 3) + (u << 1) + (c ^ 48), c = getchar(); if (flag) u = -u; } template <class T> void write(T u) { if (u < 0) printf("-"), u = -u; if (u < 10) putchar(48 + u); else write(u / 10), putchar(48 + u % 10); } void write(char u) { putchar(u); } template <class T, class... Arg> void read(T &u, Arg &...v) { read(u); read(v...); } template <class T, class... Arg> void write(T u, Arg... v) { write(u); write(v...); } template <class T> bool checkmin(T &a, T b) { return (b < a ? a = b, 1 : 0); } template <class T> bool checkmax(T &a, T b) { return (b > a ? a = b, 1 : 0); } template <class T> T _min(T a, T b) { return (a < b ? a : b); } template <class T> T _max(T a, T b) { return (a > b ? a : b); } const long long N = 100005; vector<pair<long long, long long> > v; long long n; void fac(long long n) { for (long long i = 2; i * i <= n; ++i) { if (n % i == 0) { long long tmp = 0; while (n % i == 0) n /= i, ++tmp; v.push_back(make_pair(i, tmp)); } } if (n > 1) v.push_back(make_pair(n, 1)); } void init() { scanf("%lld", &n); v.clear(); fac(n); } void solve() { if ((long long)v.size() >= 3) { long long p = n; puts("YES"); for (long long i = 0; i < 2; ++i) { long long tmp = 1; for (long long j = 1; j <= v[i].second; ++j) { tmp *= v[i].first; } p /= tmp; write(tmp, ' '); } write(p, '\n'); return; } if ((long long)v.size() == 1) { if (v[0].second < 6) printf("NO\n"); else { long long t = v[0].first; printf("YES\n"); write(t, ' ', t * t, ' ', n / t / t / t, '\n'); } } else { long long a = v[0].first, b = v[1].first, c = n / a / b; if (a != b && b != c && c != a && c >= 2 && a >= 2 && b >= 2) { printf("YES\n%lld %lld %lld\n", a, b, c); } else printf("NO\n"); } } int main() { int t; scanf("%d", &t); while (t--) { init(); 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 for _ in range(int(input())) : n=int(input()) li=list() j=2 while len(li)<2 and j*j<n : if n%j==0 : li.append(j) n=n//j j+=1 if len(li)==2 and n not in li : print("YES") for i in li : print(i,end=" ") print(n) else : print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a # import numpy as np t = int(input()) ans = [] for _ in range(t): n = int(input()) l = prime_factorize(n) L = l[0] R = l[-1] if L == R and len(l) > 3: R *= l[-2] l.pop(-1) if len(l) >=3 and L != R: # prod = np.prod(l[1:-1]) prod = 0 for i in range(len(l[1:-1])): prod = prod*(l[1+i]) if prod != 0 else l[1] if prod != L and prod != R: ans.append('YES') ans.append(str(L) + ' ' + str(prod) + ' ' + str(R)) else: ans.append('NO') else: ans.append('NO') for i in range(len(ans)): print(ans[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
for _ in range(int(input())): n=int(input()) i=2 ans=[] while(i*i<n): if(n%i==0): ans.append(i) n=n//i if(len(ans)==2 and n not in ans): ans.append(n) break i+=1 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
for i in range(int(input())): n = int(input()) f = [] for j in range(2, int(n**(1/2))): while n % j == 0: f.append(j) n = int(n/j) if n > 1: f.append(n) if len(f) >= 3: if len(f) == 3: if f[0] != f[1] and f[1] != f[2] and f[2] != f[0]: print('YES') print(f[0],f[1],f[2]) else: print('NO') else: f0 = f[0] f1 = 1 f2 = 1 if f[1] == f[0]: f1 = f[1] * f[2] for j in range(3, len(f)): f2 *= f[j] else: f1 = f[1] for j in range(2, len(f)): f2 *= f[j] if f0 != f1 and f1 != f2 and f2 != f0: print('YES') print(f0, int(f1), int(f2)) else: print('NO') else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; import java.io.*; public class Main { static final long M = 1000000007; static FastReader in = new FastReader(); static PrintWriter out = new PrintWriter(System.out); // static Scanner in = new Scanner(System.in); // File file = new File("input.txt"); // Scanner in = new Scanner(file); // PrintWriter out = new PrintWriter(new FileWriter("output.txt")); public static void main(String[] args) { int t = in.nextInt(); while(t-- > 0) { long n = in.nextLong(); int a = -1, b = -1; for(int i = 2; i*i<=n; i++) { if(n%i == 0) { a = i; n/=i; break; } } for(int i = 2; i*i<=n; i++) { if(n%i==0 && i!=a) { b = i; n/=i; break; } } if(n==a || n==b || n<2 || b==-1 || a==-1) { System.out.println("NO"); }else { System.out.println("YES"); System.out.println(a+" "+b+" "+n); } } out.close(); } private static int gcd(int a, int b) { if(b==0) return a; return gcd(b, a%b); } 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; } } }
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() { ios_base::sync_with_stdio(0); cin.tie(0); int cases; cin >> cases; for (int tt = 0; tt < cases; tt++) { long long n; cin >> n; int ok = 0; long long ax, ay, az; for (long long i = 2; i * i <= n && !ok; i++) { if (n % i == 0) { for (long long j = 2; j * j <= i && !ok; j++) { if (i % j == 0) { long long x = i / j; long long y = j; long long z = n / i; if (x != y && y != z && x != z && x > 1 && y > 1 && z > 1) { ok = 1; ax = x; ay = y; az = z; } } } for (long long j = 2; j * j <= n / i && !ok; j++) { if ((n / i) % j == 0) { long long x = i; long long y = j; long long z = n / i / j; if (x != y && y != z && x != z && x > 1 && y > 1 && z > 1) { ok = 1; ax = x; ay = y; az = z; } } } } } if (ok) { cout << "YES" << endl; cout << ax << " " << ay << " " << az << 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
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); long t = sc.nextLong(); while(t>0){ long n = sc.nextLong(); long a[] = new long[3]; int cnt = 0; for(long i=2;i*i<n;i++){ if(n%i==0){ a[0] = i; cnt++; n /= i; break; } } for(long i=a[0]+1;i*i<n;i++){ if(n%i==0){ a[1] = i; cnt++; n /= i; break; } } if((n<a[1] && a[1]>0)|| (n<a[0] && a[0]>0) || cnt<2){ System.out.println("NO"); } else{ System.out.println("YES\n"+a[0]+" "+a[1]+" "+n); } t--; } } }
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 i in range(int(input())): a=int(input()) r=0 b=1 while(1): p=0 for j in range(b+1,a+1): if a//j<=j: p=1 break else: if a%j==0: if r==1: c=j d=a//j p=1 r+=2 break else: b=j a=a//b r+=1 if p==1: break if r==3: print('yes'.upper()) print(b,c,d) else: print('no'.upper())
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def product(n): for i in range(2,int(n**(1/3))+1): if n%i==0: for j in range(i+1,int((n)**(1/2))): if (n//i)%j==0 and j!=i and (n//i)/j!=i and j!=(n//i)**(1/2): print("YES") print(i,j,(n//i)//j) return print("NO") return t=int(input()) a=[] for i in range(t): a.append(int(input())) for x in a: product(x)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# -*- coding: utf-8 -*- """ Created on Fri Apr 3 10:55:17 2020 @author: Krishna """ import math t=int(input()) for _ in range(t): n=int(input()) m=n d={} while n%2==0: if 2 not in d: d[2]=1 else: d[2] += 1 n=n/2 for i in range(3,int(math.sqrt(n))+1,2): while n %i == 0: if i not in d: d[i]=1 else: d[i]+=1 n=n/i if n>2: d[int(n)]=1 l=len(d) f=0 if l==1: for key in d.keys(): if d[key]>=6: f=1 a=key b=key**2 c=int(m/(a*b)) elif l==2: i=0 k=0 for key in d.keys(): k=k+d[key] if i==0: a=key else: b=key i=i+1 if k>=4: f=1 c=int(m/(a*b)) else: f=1 i=0 for key in d.keys(): if i==0: a=key elif i==1: b=key else: break; i=i+1 c=int(m/(a*b)) if f==0: print('NO') else: print('YES') print(a,b,c)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t=int(input()) for _ in range(t): n=int(input()) ad=False for i in range(2,10001): if (n%i==0): ln1=n//i n1=i #print("n1 = ",n1) for j in range(i+1,10001): #print("ln1(rem)j = ",ln1%j) if (ln1%j==0 and j*j!=ln1 and ln1//j!=i and ln1//j!=1): ln2=ln1//j n2=j n3=ln2 print("YES") print(n1,n2,n3) ad=True break if (ad==True): break if (ad==True): #print("NO") break if (ad==True): break if (ad==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
import math if __name__ == "__main__": t = int(input()) for _ in range(t): n, a, b = int(input()), 0, 0 i = 1 for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0 and i != n // i: n, a = n // i, i break for j in range(i, int(math.sqrt(n)) + 1): if n % j == 0: if a != j and a != n // j and j != n // j: n, b = n // j, j break if a != 0 and b != 0: print("YES") print(a, b, n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def p(n) : l=[] i = 1 while i <= math.sqrt(n): if (n % i == 0) : if (n / i == i) : if(i!=1): l.append(i) else : if(i!=1): l.append(i) if(n//i!=1): l.append(n//i) i = i + 1 return l for _ in range(int(input())): n=int(input()) a=p(n) #l.extend(l) a.sort() z=-1 d={} d[a[0]]=1 l=[] c=0 for i in range(1,len(a)): for j in range(i+1,len(a)): if n%(a[i]*a[j])==0: if (n//(a[i]*a[j])) in d and (a[i]>=2 and a[j]>=2 and (n//(a[i]*a[j]))>=2): print("YES") z=0 l.append(a[i]) l.append(a[j]) l.append((n//(a[i]*a[j]))) l.sort() print(*l) if z==0: c=1 break if c==1: break d[a[i]]=1 if z==-1: 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 factorization(n): arr = [] temp = n for i in range(2, int(-(-n ** 0.5 // 1)) + 1): if temp % i == 0: cnt = 0 while temp % i == 0: cnt += 1 temp //= i for j in range(cnt): arr.append(i) if temp != 1: arr.append(temp) if arr == []: arr.append(n) return arr n = int(input()) for _ in range(n): x = int(input()) dat = factorization(x) datlen = len(dat) #print("--") #print(x) #print(l) if len(dat) <= 2: print("NO") else: f = False a = 1 for i in range(datlen): a *= dat[i] b = 1 for j in range(i+1, datlen): b *= dat[j] c = 1 for k in range(j+1, datlen): c *= dat[k] if a != b and b != c and a != c and a != 1 and b != 1 and c != 1: f = True break if f: break if f: print("YES") print("{0} {1} {2}".format(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 import collections def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_list(): return list(map(int, sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() for t in range(int(input())): n=int(input()) p=0 for i in range(2,math.ceil(math.sqrt(n))): count=0 ans=[] if n%i==0: count+=1 no=n//i ans.append(i) for j in range(2,math.ceil(math.sqrt(no))): if i==j: continue if no%j==0: val=no//j if val!=i and val!=j: ans.append(val) ans.append(j) if len(ans)==3: print("YES") print(*ans) p+=1 count=3 break if count==3: break if p==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
//package codeforces; import java.util.Scanner; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.StringTokenizer; import java.util.HashMap; import java.util.TreeMap; import java.math.BigInteger; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Stack; public class q_1 { static Scanner scn = new Scanner(System.in); static long cunt = 0; 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; } } static FastReader s=new FastReader(); public static void main(String[] args) { // TODO Auto-generated method stub // System.out.format("%.10f", ans);char c = sc.next().charAt(0); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); int a=0,b=0,c=1,d=0; for(int i=2;i<Math.sqrt(n);i++) { if(n%i==0&&d==0) { a=i; n=n/i; d=1; } else if(n%i==0&&d==1) { b=i; c=n/i; d=10; break; } } if(d==10) { System.out.println("YES"); System.out.println(a+" "+b+" "+c); } else System.out.println("NO"); } } public static String factorial(int n) { BigInteger fact = new BigInteger("1"); for (int i = 1; i <= n; i++) { fact = fact.multiply(new BigInteger(i + "")); } return fact.toString(); } public static int bs(int arr[], int k) { int high = 0, low = Integer.MIN_VALUE, ans = 0; for (int i = 0; i < arr.length; i++) { high += arr[i]; if (arr[i] > low) low = arr[i]; } while (low <= high) { int mid = (high + low) / 2; if (valid(arr, mid, k)) { ans = mid; high = mid - 1; } else low = mid + 1; } return ans; } public static boolean valid(int arr[], int mid, int k) { int sum = 0, cs = 1; for (int i = 0; i < arr.length; i++) { if (sum + arr[i] > mid) { cs++; if (cs > k) return false; sum = arr[i]; } else sum += arr[i]; } return true; } public static long gcd(long a, long n) { if (a == 0) return n; return gcd(n % a, a); } }
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()) x=int(n) v=2 k=0 t=[] while n>v*v and k<2: if n%v==0: t.append(v) k+=1 n=n//v v+=1 if len(t)<2: print("NO") else: k=x//(t[0]*t[1]) if k==t[0] or k==t[1]: print("NO") else: print("YES") print(t[0],t[1],x//(t[0]*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 t=int(input()) while t: n=int(input()) nn=n nnn=n num=[] n=int(sqrt(n))+1 cou=0 if(nn%2==0): cou+=1 num.append(2) while nn%2==0: nn=nn//2 for i in range(3,n,2): if(cou==3): break if(nn%i==0): cou+=1 num.append(i) while nn%i==0: nn=nn//i if(nn!=1): cou+=1 num.append(nn) if(cou>=3): print("YES") print(num[0],num[1],nnn//(num[0]*num[1])) else: if(cou==1): a=num[0] b=num[0]*num[0] c=nnn//(a*b) if(a!=b and a!=c and c>b): print("YES") print(a,b,c) else: print("NO") else: a=num[0] b=num[1] c=nnn//(num[0]*num[1]) if(c!=a and c!=b and c>1): print("YES") print(num[0],num[1],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
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; void add(long long int& a, long long int b) { a += b; while (a >= mod) a -= mod; while (a < 0) a += mod; } void mul(long long int& a, long long int b) { a *= b; while (a >= mod) a -= mod; while (a < 0) a += mod; } long long int binexpomodulo(long long int x, long long int y) { long long int res = 1; x %= mod; if (!x) return 0; while (y) { if (y & 1) { mul(res, x); } mul(x, x); y >>= 1; } return res; } long long int nCrInOr(long long int n, long long int r) { long long int res = 1; if (r > n - r) r = n - r; long long int rin = 1; for (long long int i = 1; i <= r; i++) rin = (rin * i) % mod; rin = binexpomodulo(rin, mod - 2); for (long long int i = 1; i <= r; i++) res = (res * (n - i + 1)) % mod; res = (res * rin) % mod; return res; } int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<pair<int, int>> fac; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { int c = 0; while (n % i == 0) { c++; n /= i; } fac.push_back({i, c}); } } if (n >= 2) fac.push_back({n, 1}); if (fac.size() == 1) { if (fac[0].second >= 6) { int f = fac[0].first; int p = fac[0].second; cout << "YES" << endl; cout << f << " " << f * f << " " << (int)(pow(f, p - 3) + 0.5) << endl; } else cout << "NO" << endl; } else if (fac.size() == 2) { if (fac[0].second > 2 || fac[1].second > 2) { cout << "YES" << endl; if (fac[0].second > 2) { int f = fac[0].first; int p = fac[0].second; cout << f << " " << (int)(pow(f, p - 1) + 0.5) << " "; cout << (int)(pow(fac[1].first, fac[1].second) + 0.5) << endl; } else { int f = fac[1].first; int p = fac[1].second; cout << f << " " << (int)(pow(f, p - 1) + 0.5) << " "; cout << (int)(pow(fac[0].first, fac[0].second) + 0.5) << endl; } } else if (fac[0].second == 2 && fac[1].second == 2) { cout << "YES" << endl; cout << fac[0].first << " " << fac[1].first << " " << fac[0].first * fac[1].first << endl; } else { cout << "NO" << endl; } } else { cout << "YES" << endl; cout << (int)(pow(fac[0].first, fac[0].second) + 0.5) << " " << (int)(pow(fac[1].first, fac[1].second) + 0.5) << " "; int final = 1; for (int i = 2; i < fac.size(); i++) final *= (int)(pow(fac[i].first, fac[i].second) + 0.5); cout << final << 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 math t=int(input()) for i in range(t): n=int(input()) flag=0 a=[] count=0 for j in range(2,31623): if(n%j==0): count+=1 a.append(j) n=n//j if(count==2): if(a[0]!=n and a[1]!=n and n!=1): flag=1 a.append(n) break if(flag==0): print("NO") else: print("YES") for j in range(3): print(a[j],end=" ") print()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; inline int read() { char c = getchar(); int x = 0, f = 1; while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); } while (c >= '0' && c <= '9') { x = x * 10 + c - '0'; c = getchar(); } return x * f; } const int maxn = 1e6 + 10; const int inf = 2147483647; int main() { vector<int> v, prim; vector<bool> isprim; int lim = sqrt(1.0 * 1000000000) + 10; isprim.resize(lim); isprim[0] = isprim[1] = 1; for (int i = 2; i <= lim; ++i) { if (isprim[i] == false) { for (int j = i + i; j <= lim; j = j + i) isprim[j] = true; } } for (int i = 2; i <= lim; ++i) { if (isprim[i] == false) prim.push_back(i); } int sz = prim.size(); set<int> se; set<int>::iterator it; int T; scanf("%d", &T); while (T--) { int n = read(); bool flag = false; se.clear(); for (int i = 2; i * i <= n; ++i) { if (n % i == 0 && isprim[i] == false) { se.insert(i); n /= i; flag = true; break; } } if (!flag) { puts("NO"); continue; } flag = false; for (int i = sqrt(n); i >= 2; i--) { if (n % i == 0 && se.count(i) == 0 && se.count(n / i) == 0 && i != n / i) { flag = true; se.insert(i); se.insert(n / i); break; } } if (!flag) { puts("NO"); continue; } puts("YES"); for (it = se.begin(); it != se.end(); ++it) { printf("%d ", *it); } puts(""); } 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 bisect import * from collections import * def factorize(n): # o(sqr(n)) c, ans = 2, [] while (c * c < n): if n % c == 0: ans.append(c) ans.append(n // c) c += 1 if c * c == n: ans.append(c) return sorted(ans) for i in range(int(input())): n = int(input()) a = factorize(n) c, l, ans = defaultdict(int, Counter(a)), len(a), 'NO' for i in range(l): for j in range(i+1, l): num = n / (a[i] * a[j]) if c[num] and num not in [a[i], a[j]]: print('YES') print(*[a[i], a[j], int(num)]) ans = 'YES' break if ans == 'YES': break if ans == 'NO': 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.lang.*; import java.io.*; import java.util.*; import java.math.*; public class Template implements Runnable{ public static void main(String args[] ) throws Exception { new Thread(null, new Template(),"Main",1<<27).start(); } public void run() { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int t=in.nextInt(); while(t--!=0){ int n=in.nextInt(),a=0,b=0,j=2,t1=0; for(;j<Math.sqrt(n);j++) { if(n%j==0) { n=n/j; if(a==0) { a=j; t1++; } else if(b==0) { b=j; t1++; break; } } } out.print(t1==2?("YES\n"+a+" "+b+" "+n+"\n"):"NO"+"\n"); } out.close(); } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; private BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars==-1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if(numChars <= 0) return -1; } return buf[curChar++]; } public String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } public int nextInt() { int c = read(); while(isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if(c<'0'||c>'9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public double nextDouble() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } double res = 0; while (!isSpaceChar(c) && c != '.') { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } if (c == '.') { c = read(); double m = 1; while (!isSpaceChar(c)) { if (c == 'e' || c == 'E') return res * Math.pow(10, nextInt()); if (c < '0' || c > '9') throw new InputMismatchException(); m /= 10; res += (c - '0') * m; c = read(); } } return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin,stdout from collections import Counter from math import ceil from bisect import bisect_left from bisect import bisect_right import math ai = lambda: list(map(int, stdin.readline().split())) ei = lambda: map(int, stdin.readline().split()) ip = lambda: int(stdin.readline().strip()) def primeFactors(N,li): while N % 2 == 0: li.append(2) N//=2 for i in range(3,int(math.sqrt(N))+1,2): while N%i == 0: li.append(i) N //= i if N > 2: li.append(N) return li #2 2 2 2 2 2 n = ip() for i in range(n): pf = primeFactors(ip(),[]) #print(pf) if len(set(pf)) == 3 and len(pf) == 3: print('YES') print(*pf) elif len(pf) < 3: print('NO') else: # a,b,c= pf[0],pf[1]*pf[2],1 # for i in range(3,len(pf)): # c *= pf[i] a,b,c = pf[0],1,1 for i in range(1,len(pf)): if b <= a: b *= pf[i] else: c *= pf[i] if c != b and c != a 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
'''for j in range(int(input())): n=int(input()) flag = False for i in range(2,int(n**(1/3))+1): if n%i==0: z=n//i for k in range(i+1,int(z**0.5)+1): if z%k==0 and k*k!=z: flag=True print("YES") print(i,k,z//k) if flag==True: break if flag==False: print("NO")''' for j in range(int(input())): n=int(input()) c=0 l=[] for i in range(2,int(n**0.5)+1): if n%i==0: l.append(i) n=n//i if len(l)==2: break if len(l)==2 and n>l[1]: print("YES") l.append(n) 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
from math import * for _ in range(int(input())): n = int(input()) ch1 = 1 ch2 = 1 a1 = 0 a2 = 0 a3 = 0 g = 0 for i in range(2,int(sqrt(n)+1)): if(n%i == 0): a1 = i g = n//i break else: ch1 = 0 if(ch1 == 1): for i in range(2,int(sqrt(g)+1)): if(g%i == 0 and i!=a1): a2 = i a3 = g//i if(a3 == a1 or a3 == a2): continue break else: ch2 = 0 if(ch1 ==0 or ch2 == 0): print("NO") else: print("YES") print(a1,a2,a3)
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 spf(long long n) { if (n % 2 == 0) { return 2; } while (n % 2 == 0) { n /= 2; } for (long long i = 3; i * i <= n; i++) { if (n % i == 0) { return i; } } return n; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; t = 1; cin >> t; while (t--) { long long n; cin >> n; long long no = 1; for (long long i = 2; i * i <= n && no; i++) { if (n % i == 0 && (n != i * i)) { long long next = n / i; for (long long j = i + 1; j * j <= next && no; j++) { if (next % j == 0 && (next / j) != j && (next / j) != i) { cout << "YES" << "\n"; cout << i << " " << j << " " << next / j << "\n"; no = 0; } } } } if (no) { 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 java.io.*; import java.util.*; public class Template { public static void main(String[] args) { FastScanner sc = new FastScanner(); PrintWriter pw = new PrintWriter(System.out); int yo = sc.nextInt(); while (yo-- > 0) { long n = sc.nextLong(); long a = 0, b = 0, c = 0; boolean ok = false; for(long a1 = 2; a1*a1*a1 <= n; a1++) { if(n%a1 == 0) { a = a1; long[] bc = find(n/a1,b,c,a); b = bc[0]; c = bc[1]; if(a != b && b != c && a != 1 && c != 1 && b != 1) { ok = true; break; } } } if(!ok) { pw.println("NO"); } else { pw.println("YES"); pw.println(a + " " + b + " " + c); } } pw.close(); } private static long[] find(long k, long b, long c, long a) { for(long i = 2; i <= k/i; i++) { if(k%i == 0) { b = i; c = k/i; if(b == a || c == a || b == c) { continue; } else { return new long[] {b,c}; } } } return new long[]{-1,-1}; } static class Pair { int x; int y; public Pair(int x, int y) { this.x = x; this.y = y; } } // Use this instead of Arrays.sort() on an array of ints. Arrays.sort() is n^2 // worst case since it uses a version of quicksort. Although this would never // actually show up in the real world, in codeforces, people can hack, so // this is needed. static void ruffleSort(int[] a) { //ruffle int n = a.length; Random r = new Random(); for (int i = 0; i < a.length; i++) { int oi = r.nextInt(n), temp = a[i]; a[i] = a[oi]; a[oi] = temp; } //then sort Arrays.sort(a); } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } 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 int mod = 1000000007; static long pow(int a, long 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 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
#include <bits/stdc++.h> using namespace std; const long double INF = 1e18 + 7; long long N = 1e6 * 5; long double EPS = 1 / 1e18; long long a[1005]; map<long long, long long> cnt; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; for (long long i = 0; i < t; i++) { long long k = 0, err = 0, n; cin >> n; for (long long j = 2; j <= round(sqrt(n)); j++) { if (!(n % j)) { a[k++] = j; cnt[j]++; a[k++] = n / j; cnt[n / j]++; } } for (long long i = 0; i < k; i++) { for (long long j = 0; j < k; j++) { if (!(a[i] % a[j]) && cnt[a[i] / a[j]] != 0 && a[j] != n / a[i] && a[j] != a[i] / a[j] && n / a[i] != a[i] / a[j]) { cout << "YES\n" << a[j] << ' ' << a[i] / a[j] << ' ' << n / a[i] << '\n'; err = 1; break; } } if (err) break; } if (!err) 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
from math import sqrt n=int(input()) s = 32000 lst=[2] for i in range(3, s+1, 2): if (i > 10) and (i%10==5): continue for j in lst: if j*j-1 > i: lst.append(i) break if (i % j == 0): break else: lst.append(i) for i in range(n): m=int(input()) m1=m p=[] k=0 c=lst[k] while len(p)<3 and c<=sqrt(m1): if m%c==0: m=m//c p.append(c) else: k=k+1 c=lst[k] if len(p)==3: if p[0]==p[1]: p[1]=p[1]*p[2] p[2]=m1//p[0]//p[1] if len(p)==2: p.append(m1//p[0]//p[1]) if len(p)==3 and p[2]>1 and p[0]!=p[2] and p[1]!=p[2] and p[0]!=p[1]: print ('YES') print (*p) else: print ('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t=int(input()) for i in range(t): n=int(input()) k1=int(pow(n,0.333)) k2=k1**2 a=0 b=0 s=n for j in range(2,k1+1): if(n%j==0): a=j n=n//j break if(a==0): print ('NO') continue else: k=int(pow(n,0.5)) for j in range(a+1,k+1): if(n%j==0): b=j n=n//j break if(b==0): print ('NO') continue else: c=s//(a*b) if(c==1 or c==a or c==b): print ('NO') else: print ('YES') print (a,end=" ") print (b,end=" ") print (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 math def calc(n: int): myStack: list = [n] for i in range(2, int(math.sqrt(myStack[-1])) + 1): x, rem = divmod(myStack[-1], i) if rem == 0: myStack.pop() myStack.append(i) myStack.append(x) break else: print('NO') return for i in range(2, int(math.sqrt(myStack[-1])) + 1): x, rem = divmod(myStack[-1], i) if rem == 0 and i not in myStack and x not in myStack: myStack.pop() myStack.append(i) myStack.append(x) break else: print('NO') return if len(set(myStack)) == 3: if (myStack[0] * myStack[1] * myStack[2]) == n: print('YES') print('{0} {1} {2}'.format(myStack[0], myStack[1], myStack[2])) else: print('NO') else: print('NO') def main(): for _ in range(int(input())): calc(int(input())) 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
import math def primeFactors(n): factors = [] while n % 2 == 0: factors.append(2) n = n // 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: factors.append(i) n = n // i if n > 2: factors.append(n) return factors t=int(input()) for q in range(t): n=int(input()) factor=primeFactors(n) #print(factor) if len(factor)<3: print('NO') continue a,b,c=0,0,0 a=factor[0] b=1 c=1 for i in range(1,len(factor)): b*=factor[i] if b!=a: cin=i break for i in range(cin+1,len(factor)): c *= factor[i] if len(set([a,b,c]))==3 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.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.*; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.InputStream; public class First { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); int t; t = in.nextInt(); //t = 1; while (t > 0) { solver.call(in,out); t--; } out.close(); } static class TaskA { public void call(InputReader in, PrintWriter out) { int n; n = in.nextInt(); Set<Integer> set = new HashSet<>(); for (int i = 2; i*i <= n; i++) { if(n%i==0){ if(set.add(i)) { n/=i; i=1; } } if(set.size()==2){ set.add(n); break; } } if(set.size()==3){ out.println("YES"); Iterator<Integer> iterator = set.iterator(); for (int i = 0; i < 3; i++) { out.print(iterator.next()+" "); } out.println(); } else{ out.println("NO"); } } } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } static final Random random=new Random(); static void shuffleSort(int[] arr) { int n=arr.length; for (int i=0; i<n; i++) { int a=random.nextInt(n), temp=arr[a]; arr[a]=arr[i]; arr[i]=temp; } Arrays.sort(arr); } 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()); } public long nextLong(){ return Long.parseLong(next()); } public double nextDouble() { return Double.parseDouble(next()); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def find(n): count=0 flag=0 ori=n for i in range(2,int(math.sqrt(n))+3): if(n%i==0): count+=1 n=n//i liste.append(i) if(count>=2): r=ori//(liste[0]*liste[1]) if(r!=liste[0] and r!=liste[1] and r!=1): liste.append(ori//(liste[0]*liste[1])) flag=1 break else: count=1 del liste[len(liste)-1] if(flag==1): return "YES" else: return "NO" t=int(input()) for i in range(t): n=int(input()) liste=[] y=find(n) if(y=="YES"): print(y) print(*liste) elif(y=="NO"): print(y)
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()) p=[] m=2 while m*m<=n: if n%m==0: n=n//m p.append(m) if len(p)==2:break m+=1 if len(p)<2: print("NO") elif p[0]!=p[1]!=n and n>2: print("YES") print(*p, n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.*; import java.util.*; import java.lang.*; public class Codechef { PrintWriter out; StringTokenizer st; BufferedReader br; class Pair implements Comparable<Pair> { int x; int y; Pair(int t, int r) { x = t; y = r; } public int compareTo(Pair p) { return this.x-p.x; } } String ns() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } String nextLine() throws Exception { String str = ""; try { str = br.readLine(); } catch (IOException e) { throw new Exception(e.toString()); } return str; } int nextInt() { return Integer.parseInt(ns()); } long nextLong() { return Long.parseLong(ns()); } double nextDouble() { return Double.parseDouble(ns()); } public static void main(String args[]) throws IOException { new Codechef().run(); } void run() throws IOException { br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); long s = System.currentTimeMillis(); solve(); out.flush(); out.close(); } void solve() throws IOException{ int t=nextInt(); while(t-->0) { int n = nextInt(); ArrayList<Integer> list = new ArrayList<>(); int a=1,b=1,c=1; int i=2,flag=0; for(i=2;i*i<n;i++) { if(n%i==0) { list.add(i); list.add(n/i); } } if(i*i==n) list.add(i); Collections.sort(list); int size=list.size(); for(int j=0;j<size/2;j++) { for(int k=j+1;k<size/2;k++) { int cn; if(n%(list.get(j)*list.get(k))==0) { cn=n/(list.get(j)*list.get(k)); if(cn!=list.get(j)&&cn!=list.get(k)&&cn>1) { a=cn; b=list.get(j); c=list.get(k); flag=1; break; } } } } if(flag==1) { out.println("YES"); out.println(a+" "+b+" "+c); } else 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
for _ in range(int(input())): n = int(input()) X = set() x = 1 for d in range(2, 1+int(n**.5)): while not n%d: x *= d n //= d if len(X)<2 and x not in X: X.add(x) x = 1 X.add(n*x) if len(X)<3 or 1 in X: print('NO') else: print('YES') print(*X)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys import math input=sys.stdin.readline # A function to print all prime factors of # a given number n def primeFactors(n): # Print the number of two's that divide n while n % 2 == 0: n = n / 2 return(2,n) # 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: n = n / i return(i,n) # Condition if n is a prime # number greater than 2 return(-1,-1) t=int(input()) for _ in range(t): n=int(input()) a,n=primeFactors(n) b=-1 c=-1 flag=0 if(a==-1): print("NO") else: i=2 while(i<=math.sqrt(n)): if(n%i==0): if(n//i>=2): if(i!=a and(n//i!=a and i!=n//i)): b=i c=n//i flag=1 i+=1 if(flag==1): print("YES") print(a,int(b),int(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
# Unmesh Kumar # IITR CSE '22 from math import * for _ in range(int(input())): n=int(input()) pos=False for a in range(2,int(pow(n,1/3))+1): if n%a==0: z=n//a for b in range(a+1,int(sqrt(z))+1): if z%b==0 and b*b!=z: pos=True print('YES') print(a,b,z//b) break if pos: break if not pos: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; import java.io.*; public class Main { static InputReader scn = new InputReader(System.in); static PrintWriter out = new PrintWriter(System.out); public static void main(String[] HastaLaVistaLa) { // Running Number Of TestCases (t) int t = scn.nextInt(); while(t-- > 0) solve(); out.close(); } public static void dummy(){ int n = scn.nextInt(); out.println(n); } static int max = 0; static int[] dp; static int MOD = 100; public static void solve() { // Main Solution (AC) int n = scn.nextInt(); int k = (int) Math.sqrt(n); for(int i = 2; i <= k; i++) { if(n % i == 0) { int fact1 = n / i; int[] factor23 = Factors(fact1); if(factor23[0] != -1 && factor23[0] != i && factor23[1] != i) { out.println("YES"); out.println(i + " " + factor23[0] + " " + factor23[1]); return; } } } out.println("NO"); } public static int[] Factors(int a) { int k = (int) Math.sqrt(a); int[] arr = new int[2]; Arrays.fill(arr, -1); for(int i = 2; i <= k; i++) { if(a % i == 0) { int fact1 = a / i; if(fact1 != i) { arr[0] = i; arr[1] = fact1; } } } return arr; } public static long binpow(long n, long m, long mod) { long res = 1; while (m > 0) { if (m % 2 == 1) { res *= n; res %= mod; m--; } n *= n; n %= mod; m /= 2; } return res; } public static HashMap<Integer, Integer> CountFrequencies(int[] arr) { HashMap<Integer, Integer> map = new HashMap<>(); for (int i : arr) { if (map.containsKey(i)) map.put(i, map.get(i) + 1); else map.put(i, 1); } return map; } public static long gcd(long a, long b) { if (a == 0) return b; return gcd(b % a, a); } public static long sum(int[] arr) { long sum = 0; for(int i : arr) sum += i; return sum; } // Number of Divisor for Range [l, r] public static int[] NumberOFDivisors(int l, int r) { int[] arr = new int[l - r + 1]; for(int i = l; i <= r; i++) { for(int j = i; j <= r; j += i) arr[j]++; } return arr; } public static int LowerBound(int a[], int x) { // x is the target value or key int l = -1,r = a.length; while(l + 1 < r) { int m = (l + r) >>> 1; if(a[m] >= x) r = m; else l = m; } return r; } static boolean[] prime; public static void sieveOfEratosthenes(int n) { prime = new boolean[n+1]; for(int i=0;i<n;i++) prime[i] = true; for(int p = 2; p*p <=n; p++) { if(prime[p] == true) { for(int i = p*p; i <= n; i += p) prime[i] = false; } } } public static int UpperBound(long a[], long x) {// x is the key or target value int l = -1,r = a.length; while(l + 1 < r) { int m = (l + r) >>> 1; if(a[m] <= x) l = m; else r = m; } return l + 1; } public static long lcm(long a, long b) { return (a * b) / gcd(a, b); } public static void sort(int[] arr) { Random rand = new Random(); int n = arr.length; for(int i = 0; i<n; i++) { swap(arr, i, rand.nextInt(n)); } Arrays.sort(arr); } public static void swap(int[] arr, int i, int j) { if(i!=j) { arr[i] ^= arr[j]; arr[j] ^= arr[i]; arr[i] ^= arr[j]; } } public static void sortbyColumn(int[][] arr, int col) { Arrays.sort(arr, new Comparator<int[]>() { public int compare(final int[] entry1, final int[] entry2) { if (entry1[col] > entry2[col]) return 1; else return -1; } }); } public static void ArraySort2D(double[][] arr, int xy) { // xy == 0, for sorting wrt X-Axis // xy == 1, for sorting wrt Y-Axis Arrays.sort(arr, Comparator.comparingDouble(o -> o[xy])); } public static int binarySearch(int arr[], int l, int r, int x) { if (r >= l) { int mid = l + (r - l) / 2; if (arr[mid] == x) return mid; if (arr[mid] > x) return binarySearch(arr, l, mid - 1, x); return binarySearch(arr, mid + 1, r, x); } return -1; } static class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int[] readIntArray(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = scn.nextInt(); } return a; } public long[] readLongArray(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) { a[i] = scn.nextLong(); } return a; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int nextInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nextLong() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return nextLine(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } }
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()) def f(a): b=2 a=int(a) fac=[] c=math.sqrt(a) while b<=c and a>1: if a%b==0: while a%b==0: fac.append(b) a/=b b+=1 else: b+=1 if a!=1: fac.append(a) return fac for i in range(t): n=int(input()) list=f(n) list2=[] list2.clear() while list: i=list[0] b=list.count(i) list2.append([i,b]) for j in range(b): list.remove(i) c=len(list2) if c>=3: print("YES") print(list2[0][0],list2[1][0],int(n/list2[0][0]/list2[1][0])) elif c==1: if(list2[0][1]>=6): print("YES") print(list2[0][0],list2[0][0]*list2[0][0],int(n/list2[0][0]/list2[0][0]/list2[0][0])) else: print("NO") elif c==0: print("NO") else: if(list2[0][1]>=2 and list2[1][1]>=2): print("YES") print(list2[0][0],list2[1][0],int(n/list2[0][0]/list2[1][0])) elif list2[0][1]>=3: print("YES") print(list2[0][0],int(list2[1][0]),int(n/list2[0][0]/list2[1][0])) elif list2[1][1]>=3: print("YES") print(list2[0][0], list2[1][0],int(n/list2[0][0]/list2[1][0])) 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 functools import reduce reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ def factors(n): return list(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) def product(): for _ in range(t): n=int(input()) yn=factors(n) yn.sort() #print(yn) if len(yn)>=4: a,b=yn[1],yn[3] c=n//yn[1]//yn[3] d=n//yn[1]%yn[3] a1,b1=yn[1],yn[2] e=n//yn[1]//yn[2] f=n//yn[1]%yn[2] if c>1 and c!=a and c!=b and d==0: yield 'YES' yield str(a)+' '+str(b)+' '+str(c) elif e>1 and e!=a1 and e!=b1 and f==0: yield 'YES' yield str(a1)+' '+str(b1)+' '+str(e) else: yield'NO' else: yield 'NO' if __name__ == '__main__': t= int(input()) ans = product() print(*ans,sep='\n')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t = int(input()) while t>0: # print("t: ",t) t-=1 n = int(input()) num_factors=0 first_factor = -1 second_factor = -1 if n==1 or n==2: print("NO") continue n_copy=n s = int(math.sqrt(n)) for i in range(2,s): if n_copy%i==0: if first_factor==-1: first_factor=i elif second_factor==-1: second_factor=i else: break n_copy= n_copy//i if first_factor==-1 or second_factor==-1 or first_factor==n_copy or second_factor==n_copy or n_copy==1: print("NO") else: print("YES") print(first_factor,second_factor,n_copy)
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> #pragma GCC optimize(2) #pragma GCC optimize(3) using namespace std; const int N = 1e5 + 7; const int M = 1e6 + 7; const int INF = 1e9 + 8; int p[N]; int c[N]; int m; void divide(int n) { m = 0; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { p[++m] = i, c[m] = 0; while (n % i == 0) { n /= i; c[m]++; } } } if (n > 1) { p[++m] = n; c[m] = 1; } return; } int main() { int t; cin >> t; while (t--) { int n; cin >> n; divide(n); int a = 1; int b = 1; int cc = 1; int tt = 1; for (int i = 1; i <= m; i++) { int g = c[i]; for (int j = 1; j <= g; j++) { if (tt <= 1) { a *= p[i]; tt++; } else { if (b == 1 || b == a) b *= p[i]; else cc *= p[i]; } } } if (cc == 1 || b == 1 || a == 1) { cout << "NO" << endl; continue; } if (cc != a && a != b && b != cc) { cout << "YES" << endl; cout << a << " " << b << " " << cc << endl; } else cout << "NO" << endl; } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int a[N]; void solve() { int n; cin >> n; set<int> s; for (long long i = 2; i * i <= n; i++) { if (n % i == 0 && s.find(i) == s.end()) { n /= i; s.insert(i); break; } } for (long long i = 2; i * i <= n; i++) { if (n % i == 0 && s.find(i) == s.end()) { n /= i; s.insert(i); break; } } if ((int)s.size() < 2 || n == 1 || s.find(n) != s.end()) cout << "NO\n"; else { cout << "YES\n"; s.insert(n); for (auto it : s) cout << it << " "; cout << "\n"; } } int main() { ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 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=math.sqrt(n) a=int(a) c=[] f=0 d=0 b=int(a) for j in range(2,a+1,1): if(n%j==0): f=1 x=j y=n//j break if(f==0): print("NO") else: f=0 for j in range(2,int(y**(1/2))+1): if(y%j==0): if(x!=j and y//j!=x and y//j!=j): z=j y=y//j f=1 break if(f==0): print("NO") else: print("YES") print(x,y,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.*; public class Main { public static void main(String args[]){ Scanner sc = new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n = sc.nextInt(); int[] arr = new int[3]; int index=0, divisor=2; while(n%divisor==0 && index<2) { arr[index++]=divisor; n/=divisor; divisor*=divisor; } for (int i = 3; i <= Math.sqrt(n) && index<2; i+= 2) { divisor=i; while(n%divisor==0 && index<2) { arr[index++]=divisor; n/=divisor; divisor*=divisor; } } if(n==1 || n==0 || n==arr[0] || n==arr[1] || arr[0]==0 || arr[1]==0) System.out.println("NO"); else { System.out.println("YES"); System.out.println(arr[0]+" "+arr[1]+" "+n); } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> #pragma 03 using namespace std; vector<pair<long long, long long> > pfac; long long binpow(long long x, long long y) { if (x == 0) return 0; if (y == 0) return 1; long long res = binpow(x, y / 2); if (y % 2 == 0) return res * res; else return res * res * x; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; long long n, x, num; while (t--) { cin >> n; pfac.clear(); if (n < 24) { cout << "NO\n"; continue; } x = n; for (long long i = 2; i < sqrt(n); i++) { if (x % i == 0) { num = 0; while (x % i == 0) { num++; x /= i; } pfac.push_back(pair<long long, long long>(i, num)); } if (x == 1) break; } if (x != 1) pfac.push_back(pair<long long, long long>(x, 1)); if (pfac.empty()) { cout << "NO\n"; continue; } else if (pfac.size() == 1) { if (pfac[0].second >= 6) { cout << "YES\n"; cout << pfac[0].first << " " << pfac[0].first * pfac[0].first << " " << binpow(pfac[0].first, pfac[0].second - 3) << "\n"; } else { cout << "NO\n"; } } else if (pfac.size() == 2) { if (pfac[0].second <= 2 && pfac[1].second <= 2) { if (pfac[0].second < 2 or pfac[1].second < 2) { cout << "NO\n"; } else { cout << "YES\n"; cout << pfac[0].first << " " << pfac[1].first << " " << pfac[0].first * pfac[1].first << "\n"; } } else { cout << "YES\n"; cout << pfac[0].first << " " << pfac[1].first << " " << binpow(pfac[0].first, pfac[0].second - 1) * binpow(pfac[1].first, pfac[1].second - 1) << "\n"; } } else { long long neu = 1; for (long long i = 2; i < pfac.size(); i++) { neu *= binpow(pfac[i].first, pfac[i].second); } cout << "YES\n"; cout << binpow(pfac[0].first, pfac[0].second) << " " << binpow(pfac[1].first, pfac[1].second) << " " << neu << "\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 math t = int(input()) for i in range(t): n = int(input()) f = 1 for a in range(2, int(math.sqrt(n)) + 1): if f and n % a == 0: curn = n // a for b in range(2, int(math.sqrt(curn)) + 1): if f and b != a and curn % b == 0: c = curn // b if c != b and c != a: print('YES') print(a, b, c) f = 0 if f: 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 facts(n): l=[] for i in range(2,int(pow(n,0.5))+1): if n%i==0: l.append(i) l.append(n//i) return list(set(l)) for _ in range(int(input())): n=int(input()) l=facts(n) l.sort() d={} for i in l: d[i]=0 flag = 0 for i in range(len(l)): for j in range(i+1,len(l)): a,b=l[i],l[j] c=n//(a*b) try: if d[c]==0 and a!=c and b!=c: print("YES") print(a,b,c) flag = 1 except: continue if flag: break if flag: break if not flag: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# cook your dish here import math for t in range(int(input())): n=int(input()) flag=False for i in range(2,int(math.sqrt(n))+1): if n%i==0: x=i yy=n//i for j in range(i+1,int(math.sqrt(yy))+1): if yy%j==0: y=j z=yy//j if z>=2 and z!=y and z!=x: flag=True l=[x,y,z] print("YES") print(*l) break if flag: break if flag==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
import math t=int(input()) for i in range(t): n=int(input()) k=n l=[] for j in range(2,int(math.sqrt(n))+1): if n%j==0: l.append(j) break if len(l)!=0: n=n//l[0] for j in range(2,int(math.sqrt(n))+1): if n%j==0: if j not in l: l.append(j) break if len(l)==2: if k%(l[0]*l[1])==0: c=k//(l[0]*l[1]) if c not in l: print("YES") print(l[0],l[1],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> int n, a[105], m; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", &a[i]); for (int i = 1; i <= n; i++) { int s1 = 0, s2 = 0, s3 = 0; m = a[i]; for (int j = 2; j * j <= m; j++) { if (m % j == 0) { if (s1 == 0) s1 = j; else s2 = j; m /= j; } if (s2 != 0 && m != 1) { s3 = a[i] / (s1 * s2); if (s2 == s3) s3 = 0; break; } } if (s1 * s2 * s3 != 0) printf("YES\n%d %d %d", s1, s2, s3); else printf("NO"); if (i != n) printf("\n"); } scanf("\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 * from operator import * def isPrime(x): if(x in [1,4]): return False elif(x in [2,3,5]): return True else: for i in range(2,int(sqrt(x))+1): if(x%i == 0): return False return True def Sieve(x): checkPrime = [1 for i in range(x+1)] zz = 2 L = [] while(zz**2 <= x): if(checkPrime[zz] == 1): for i in range(zz*2,x+1,zz): checkPrime[i] = 0 zz += 1 for i in range(2,x): if(checkPrime[i] == 1): L.append(i) return checkPrime checkPrime = Sieve(100001) def primeFactors(x): d = {} i = 0 X = x while(x%2 == 0): x //= 2 i += 1 if(i > 0): d[2] = i for i in range(3,int(sqrt(x))+1,2): zz = 0 while(x%i == 0): x //= i zz += 1 if(zz > 0): d[i] = zz if(x > 2): d[x] = 1 return d T = int(input()) for tt in range(T): x = int(input()) if(x%2 != 0 and x%3 != 0 and isPrime(x)): print('NO') elif(isPrime(x)): print('NO') else: d = primeFactors(x) # print('d:',d) ans = [0,0,0] if(len(d) > 2): print('YES') for i in d: if(ans[0] == 0): ans[0] = i elif(ans[1] == 0): ans[1] = i else: break ans[2] = x//(ans[0]*ans[1]) print(*ans) elif(len(d) == 1): for i in d: if(d[i] < 6): print('NO') else: print('YES') print(i,i**2,x//(i*i**2)) else: ans = [0]*3 d = sorted(d.items(), key=itemgetter(1)) if(d[0][1] >= 6): print('YES') i = d[0][0] print(i,i**2,x//(i*i**2)) elif(d[0][1] + d[1][1] >= 4): print('YES') print(d[0][0],d[1][0],x//(d[0][0]*d[1][0])) 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 P(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 t=int(input()) for i in range(t): x=int(input()) p=P(x) if len(p)>2: a=p[0] b=p[1] c=1 for i in range(2,len(p)): if a==b: b=b*p[i] else: c*=p[i] if c!=1 and a!=b and b!=c and c!=a: 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; void solve() { long long int n; cin >> n; long long int ans[3]; long long int count = 0; for (long long int i = 2; i * i <= n; i++) { if (n % i == 0) { n = n / i; ans[count] = i; count++; } if (count == 3) { break; } } if (count == 3 && n > 2) { ans[2] = ans[2] * n; } else if (count < 3 && n > 2) { ans[count] = n; count++; } if (count == 3 && ans[0] != ans[1] && ans[1] != ans[2] && ans[2] != ans[0]) { cout << "YES" << endl; cout << ans[0] << " " << ans[1] << " " << ans[2] << endl; } else cout << "NO" << endl; } int main() { int t; cin >> t; while (t--) { solve(); } }
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 main() { long long int t, n, a, b, i, ra, rb, rc; cin >> t; while (t--) { ra = rb = rc = 1; cin >> a; b = sqrt(a); for (i = 2; i <= b + 1; i++) { if (a % i == 0) { a = a / i; ra = i; break; } } b = sqrt(a); for (i = 2; i <= b + 1 && ra != 1; i++) { if (a % i == 0 && i != ra) { a = a / i; rb = i; break; } } if (a != ra && a != rb) rc = a; if (ra == 1 || rb == 1 || rc == 1) cout << "NO\n"; else { cout << "YES\n"; cout << ra << " " << rb << " " << rc << 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 math def isPrime(n) : if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True t=int(input()) for i in range(t): n=int(input()) x=isPrime(n) if x==True: print("NO") else: c=[] count=0 vv=math.sqrt(n) vv=int(vv) i=2 while i*i<n: if n%i==0: count+=1 n=n//i c.append(i) if count==2: c.append(n) break i+=1 if len(c)<3 or c[0]==c[1] or c[1]==c[2]: print("NO") else: print("YES") print(*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
# your code goes here import math t=int(input()) while(t>0): n=int(input()) l=[] c=0 s=int(math.sqrt(n)) for i in range(2,s+1): if(n%i==0): l.append(i) c+=1 n=n//i break for i in range(2,s+1): if(i not in l and n%i==0): l.append(i) c+=1 n=n//i break if(c<2 or n==1 or n in l): print("NO") else : print("YES") for i in l: print(i,end=' ') print(n) 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
for _ in range(int(input())): n=int(input()) a=0 b=0 c=0 for i in range(2,int(n**0.5)+1): if n%i==0: a=i t=n//i for j in range(a+1,int(t**0.5)+1): if t%j==0: b=j c=t//j if b==c: b=0 c=0 continue break break if a and b and 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.math.BigInteger; import java.util.Arrays; import java.util.HashMap; import java.util.Scanner; public class T { public static void main(String args[]) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int c=0; int c1=0; int c2=0; int c3=0; boolean t ; for(int i =0 ; i<x;i++){ int k = sc.nextInt(); t=false; int v=k; c=0; for(int j =2 ; j<Math.sqrt(v);j++){ if(k%j==0 && c==0){ c++; k/=j; c1=j; continue; } if(k%j==0 && c==1){ c++; k/=j; c2=j; if(k<v &&k>c2){ c3=k; t=true; c++; break; } } } if(t){ System.out.println("YES"); System.out.println(c1+" "+c2+" "+c3+" "); }else{ System.out.println("NO"); } c1=0; c2=0; c3=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
def miller_rabin_primalitytest(n,a): z=n-1 d=z while(d%2==0): d=d//2 if(pow(a,d,n)!=1): x=d while(x<n): r=pow(a,x,n) if(r==n-1): return "Probable Prime" else: x=2*x return "Composite" else: return "Probable Prime" def isprimeoptimized(n): if(n%2==0 and n>2): return False elif(n==2): return True elif(n==1): return False else: if(n<2047): L=[2] else: L=[2,3,5,7] i=0 while(i<len(L)): if(miller_rabin_primalitytest(n,L[i])=="Probable Prime"): #WORKS FOR ALL NUMBERS LESS THAN 2^64. i+=1 else: return False return True t=int(input()) for i in range(0,t): n=int(input()) if(isprimeoptimized(n)): print("NO") elif(n<24): print("NO") else: L=[] for i in range(2,int(n**0.5)+1): if(n%i==0): L.append(i) n=n//i break for i in range(2,int(n**0.5)+1): if(n%i==0 and L[0]!=i and L[0]!=n//i and i*i!=n): L.append(i) L.append(n//i) break 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
q = int(input()) def div_by_primes(n): p = [] s = [] for d in range(2, int(n**(1/2))+1): if n%d == 0: p.append(d) s.append(0) while n%d == 0: s[-1] += 1 n //= d if n > 1: p.append(n) s.append(1) return p, s def s_mult(s, p): ans = 1 for i in range(len(s)): ans *= p[i]**s[i] return ans for _ in range(q): n = int(input()) p, s = div_by_primes(n) if len(p) == 1: if s[0] < 6: print("NO") else: print("YES\n", p[0], p[0]**2, p[0]**(s[0]-3)) elif len(p) == 2: if s[0]+s[1] < 4: print("NO") elif s[0] == 1: print("YES\n", p[0], p[1], p[1]**(s[1]-1)) elif s[1] == 1: print("YES\n", p[0], p[1], p[0]**(s[0]-1)) else: print("YES\n", p[0], p[1], p[0]**(s[0]-1)*p[1]**(s[1]-1)) else: print("YES\n", p[0]**s[0], p[1]**s[1], s_mult(s[2:], p[2:]))
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 C { public static boolean[] isPrime; public static void main(String[] args) { FastScanner sc=new FastScanner(); int t = sc.nextInt(); isPrime = new boolean[1000007]; fillPrime(); while(t-->0) { int n = sc.nextInt(); if(n< 1000007 && isPrime[n]) { System.out.println("NO"); }else { int ar[] = new int[3]; int i = 0; int cur = 2; while(i<2 && cur*cur <= n) { if(n%cur == 0) { //System.out.println(ar[i]); ar[i++] = cur; n/=cur; //System.out.println(n+" "+ar[i-1]); } cur++; } if(i==2) { ar[2] = n; } //System.out.println(); if(i==2 && ar[2] > 1 && ar[2] != ar[1] && ar[2] !=ar[0]) { System.out.println("YES"); for(int val : ar) { System.out.print(val + " "); } System.out.println(); }else { System.out.println("NO"); } } } } public static void fillPrime() { int n = 1000007; Arrays.fill(isPrime, true); isPrime[0] = isPrime[1] = false; for(int i = 2; i*i<n; i++) { if(isPrime[i]) { for(int j = i*i; j<n; j+=i) { isPrime[j] = false; } } } } static final Random random = new Random(); static void sort(int[] a) { int n = a.length; for(int i =0; i<n; i++) { int val = random.nextInt(n); int cur = a[i]; a[i] = a[val]; a[val] = cur; } Arrays.sort(a); } static void sortl(long[] a) { int n = a.length; for(int i =0; i<n; i++) { int val = random.nextInt(n); long cur = a[i]; a[i] = a[val]; a[val] = cur; } Arrays.sort(a); } static class FastScanner { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st=new StringTokenizer(""); String next() { while (st == null || !st.hasMoreTokens()) { try { st=new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } 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()); } double nextDouble() { return Double.parseDouble(next()); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math class Read: @staticmethod def int(): return int(input()) @staticmethod def list(sep=' '): return input().split(sep) @staticmethod def list_int(sep=' '): return list(map(int, input().split(sep))) def main(): n = Read.int() status = False for a in range(2, int(math.sqrt(n) + 1)): if n % a == 0: k = n / a for b in range(a+1, int(math.sqrt(k) +1)): if k % b == 0: c = int(k / b) if b != c and c > 2: print('YES') print('{} {} {}'.format(a, b, c)) status = True break; if status: break; if status == False: print('NO') query_count = Read.int() while query_count: query_count -= 1 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()) for i in range(t): n = int(input()) Ans = [] d = 2 while d * d <= n: if n % d == 0: Ans.append(d) break else: d += 1 if len(Ans) == 0: Ans.append(n) n //= Ans[-1] while d * d <= n: if n % d == 0 and Ans[-1] != d: Ans.append(d) break else: d += 1 if len(Ans) == 1: Ans.append(1) if len(Ans) >= 2: c = n // Ans[-1] if c >= 2 and Ans[0] >= 2 and Ans[1] >= 2 and c != Ans[-1] != Ans[-2]: Ans.append(c) print('YES') print(*Ans) 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 math ts = int(input( )) while ts > 0: ts = ts - 1 n = int(input( )) flag = 0 a, b, c = 0, 0, 0 for i in range( 2, int(math.sqrt(n) + 1 ) ): if n % i == 0: a = i n = int( n / a ) break for i in range( 2, int(math.sqrt(n) + 1 ) ): if n % i == 0 and i != a: b = i n = int( n / b ) break if a != 0 and b != 0: c = n if c != a and c != b and c != 1 and c != 0: print("YES") print(a,b,c) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int T; int main(int argc, char const *argv[]) { cin >> T; for (int kase = 1; kase <= T; kase++) { int n; cin >> n; map<int, int> mp; int tmp = n; int cnt = 3; while (cnt) { if (cnt == 1) { mp[tmp] = 1; break; } for (int i = 2; i <= sqrt(tmp); i++) { if (tmp % i == 0 && mp[i] == 0) { mp[i] = 1; tmp /= i; break; } } cnt--; } int ans[5]; int tot = 0; for (map<int, int>::iterator it = mp.begin(); it != mp.end(); it++) { if ((*it).second == 1 && (*it).first >= 2) { ans[++tot] = (*it).first; } } if (tot != 3) { cout << "NO" << endl; } else { cout << "YES" << endl; cout << ans[1] << " " << ans[2] << " " << ans[3] << 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
for _ in " "*int(input()): n=int(input());a=[];i=2 while(len(a)<2 and i*i<n): if n%i==0:n=n//i;a.append(i) i+=1 if len(a)==2 and n not in a:print("YES");print(n,*a) else:print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def factors(x): result = [] i = 1 while i*i <= x: if x % i == 0: result.append(i) if x//i != i: # result.append(x//i) i += 1 return(result) for _ in range(int(input())): n = int(input()) lst = sorted(factors(n)) a = lst[1] x = n//a lst2 = sorted(factors(x)) if len(lst2) <= 2: b = -1 elif lst2[1] != a: b = lst2[1] elif lst2[1] == a and len(lst2) > 2: b = lst2[2] yo = a*b res = n//yo if res != a and res!= b and res != 1 and b > 1: print("YES") print(a,b,res) else: print("NO") #print(lst2)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def div(n, m): i = m+1 while i*i < n: if(n%i == 0): return(i, n // i) i += 1 return(-1, -1) t = int(input()) for _ in range(t): n = int(input()) a = 0 i = 2 while i * i < n: if (n % i == 0): a = i break i += 1 if(a == 0): print("NO") else: b, c = div(n//a, a) if(b == -1): print("NO") else: print("YES\n",a," ",b," ",c)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int gcd(int r, int p) { if (p == 0) return r; return gcd(p, r % p); } struct Test { int x, y, z; }; long long int fact(long long int x) { long long int p = (fact(x - 1) * x) % 1000000007; return p; } void sieveOfEratosthenes(long long int N, long long int s[]) { vector<bool> prime(N + 1, false); for (long long int i = 2; i <= N; i += 2) s[i] = 2; for (long long int i = 3; i <= N; i += 2) { if (prime[i] == false) { s[i] = i; for (long long int j = i; j * i <= N; j += 2) { if (prime[i * j] == false) { prime[i * j] = true; s[i * j] = i; } } } } } map<long long int, long long int> poww; vector<long long int> vec; void generatePrimeFactors(long long int N) { long long int s[N + 1]; sieveOfEratosthenes(N, s); long long int curr = s[N]; int cnt = 1; while (N > 1) { N /= s[N]; if (curr == s[N]) { cnt++; continue; } poww[curr] = cnt; vec.push_back(curr); if (vec.size() > 2) { return; } curr = s[N]; cnt = 1; } } int main() { cin.tie(NULL); int t; cin >> t; while (t--) { long long int n; int f = 0; cin >> n; long long int t, tt, ttt; for (int i = 2; i < sqrt(n); i++) { if (n % i == 0) { for (int j = 2; j < sqrt(n); j++) { if (n / i % j == 0 && i != j && n / (i * j) != j && n / (i * j) != i) { f = 1; t = i; tt = j; ttt = n / (i * j); break; } } } } if (f == 1) { cout << "YES" << endl; cout << t << " " << tt << " " << ttt << endl; } else { cout << "NO" << endl; } } }
CPP