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 solution(n): for first_dis in range(2, int(n**0.5) + 1): if n % first_dis == 0: next_value = n // first_dis for second_dis in range(first_dis + 1, int(next_value**0.5) + 1): if next_value % second_dis == 0: third = next_value // second_dis if third != second_dis: return ("YES", f"{first_dis} {second_dis} {third}") return ("NO",) def read(): cnt = int(input()) for _ in range(cnt): value = int(input()) for item in solution(value): print(item) read()
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 def solve(n): if isprime(n,2)==-1:return 'NO' i=2 while i<=sqrt(n): if n%i==0: p=isprime(n//i,i+1) if p!=-1:return i,p i+=1 return 'NO' def isprime(n,b): i=b while i<=sqrt(n): if n%i==0 and i!=n//i:return i,n//i i+=1 return -1 for _ in range(int(input())): n=int(input());s=solve(n) if s=='NO':print(s) else:print('YES');print(s[0],*s[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
t = int(input()) for _ in range(t): n = int(input()) sqn = int(n**(1/2))+10 ans = [] flag = False for i in range(2,sqn): if n%i==0: ans.append(i) n//=i if len(ans)==2: if n==ans[1] or n==ans[0] or n==1: print("NO") else: print("YES") print(*ans,n) flag = True 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
import java.io.*; import java.util.*; import java.lang.*; // A U T H O R : s a n 1 d h y a public class cf1294C { static long Mod1 = 1000000007; 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 ni() { return Integer.parseInt(next()); } long nl() { return Long.parseLong(next()); } double nd() { return Double.parseDouble(next()); } String nln() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } /* * public static void sortbyColumn(int arr[][], int col) { // Using built-in * sort function Arrays.sort Arrays.sort(arr, new Comparator<int[]>() { * * @Override // Compare values according to columns public int compare(final * int[] entry1, final int[] entry2) { * * // To sort in descending order revert // the '>' Operator if (entry1[col] > * entry2[col]) return 1; else return -1; } }); // End of function call sort(). * } */ /* public static long modex(long x, long y) { x = x % Mod1; long ret = 1; while (y > 0) { if (y % 2 != 0) { ret = ret * x % Mod1; } x = x * x % Mod1; y >>= 1; } return ret; } */ /* public static long mplr(long x, long y) { long ret = 0; while (y != 0) { if (y % 2 != 0) { ret = (ret + x) % Mod1; } x = (x + x) % Mod1; y >>= 1; } return ret; } */ public static void main(String[] args) { FastReader sc = new FastReader(); int t=sc.ni(); while(t-->0) { long n=sc.nl(); long q=n; // long sq=(long)Math.ceil(Math.sqrt((double)n)); long a[]=new long[2]; int c=0; int f=0; for(long i=2;i<(long)Math.sqrt(q);i++) { if(n%i==0) { a[c++]=i; n=n/i; } if(c==2) { f=1; break; } } if(f==0) System.out.println("NO"); else { if(q%n==0&&(n!=a[0]&&n!=a[1])) { System.out.println("YES"); System.out.println(a[0]+" "+a[1]+" "+n); } else System.out.println("NO"); } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def d(i,n): if(i==2 and n%2==0): return 2; while(i**2<=n): if(n%i == 0): return i i+=1 return n; t=int(input()) for _ in range(t): n=int(input()) a = d(2,n); b= d(a+1,n/a); c = n//(a*b) if(c>=2 and c!=a and c!=b): 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
# _1294c ########## def productOfThreeNumbers(n, answer=(1, )): lengthOfAnswer = len(answer) if lengthOfAnswer == 3: if n > answer[-1]: return f'YES\n{answer[1]} {answer[2]} {int(n)}' return 'NO' for i in range(answer[-1]+1, int(n**(1/(4-lengthOfAnswer)))+1): if not n%i: return productOfThreeNumbers(n/i, answer+(i, )) return 'NO' nTestCases = int(input()) testCases = [int(input()) for x in range(nTestCases)] [print(productOfThreeNumbers(testCase)) for testCase in testCases]
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 nt in range(int(input())): n = int(input()) if n<24: print ("NO") continue p = [] curr = 2 while curr*curr<n: if n%curr==0: n=n//curr p.append(curr) if len(p)==2: break curr+=1 if len(p)<=1: print ("NO") continue if n not in p: print ("YES") print (p[0],p[1],n) else: print ("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def primeFactors(n): prime = [] while n % 2 == 0: prime.append(2) n = n // 2 i = 3 while i <= math.sqrt(n): while n % i == 0: prime.append(i) n = n//i i += 2 if n > 2: prime.append(n) return prime te = int(input()) while te > 0: te -= 1 n = int(input()) factors = primeFactors(n) # print(factors) if len(factors) < 3: print('NO') else: if len(factors) == 3: x, y, z = factors else: x = factors[0] j = 3 if factors[0] != factors[1]: y = factors[1] j = 2 else: y = factors[1]*factors[2] z = 1 while j < len(factors): z = z*factors[j] j += 1 if x == y or y == z or x == z: 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
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; long long copy = n; vector<pair<long long, long long>> v; long long count = 0; while (!(n % 2)) { n >>= 1; count++; } if (count) v.push_back({2, count}); for (long long i = 3; i <= sqrt(n); i += 2) { count = 0; while (n % i == 0) { count++; n = n / i; } if (count) v.push_back({i, count}); } if (n > 2) v.push_back({n, 1}); if (v.size() < 3) { if (v.size() == 2) { long long f1 = v[0].first; long long f2 = v[1].first; long long f3 = copy / (v[0].first * v[1].first); if (f1 != f2 && f1 != f3 && f2 != f3 && f1 >= 2 && f2 >= 2 && f3 >= 2) { cout << "YES\n"; cout << f1 << " " << f2 << " " << f3 << '\n'; } else cout << "NO\n"; } else { if (v[0].second <= 5) cout << "NO\n"; else { cout << "YES\n"; cout << v[0].first << " " << v[0].first * v[0].first << " " << copy / (v[0].first * v[0].first * v[0].first) << "\n"; } } } else { cout << "YES\n"; cout << v[0].first << " " << v[1].first << " "; cout << copy / (v[0].first * v[1].first) << '\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()) flag=0 for j in range(2,int(pow(n,0.5)+1)): if n%j==0: n1=n//j for k in range(j+1,int(pow(n1,0.5)+1)): n2=n1//k if n1%k==0 and n2!=k: flag=1 n2=n1//k print("YES") print(j,end=" ") print(k,end=" ") print(n2,end=" ") break break if flag==0: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from __future__ import division import sys input = sys.stdin.readline import math from math import sqrt, floor, ceil from collections import Counter, defaultdict from copy import deepcopy as dc ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) def insr2(): s = input() return(s.split(" ")) def prime_factorization(n): if n == 1: return [1] ans=[] i = 2 cap = sqrt(n) while i <= cap: if n % i == 0: ans.append(i) n = n//i cap=sqrt(n) else: i += 1 if n > 1: ans.append(n) return ans def binomial(n, k): if n == 1 or n == k: return 1 if k > n: return 0 else: a = math.factorial(n) b = math.factorial(k) c = math.factorial(n-k) div = a // (b * c) return div def computeGCD(x, y): if x > y: small = y else: small = x for i in range(1, small+1): if((x % i == 0) and (y % i == 0)): gcd = i return gcd # r = raw_input() for _ in range(inp()): n = inp() z = prime_factorization(n) ans = set() temp = 1 for i, a in enumerate(z): if len(ans) >= 2: temp *= a else: if a not in ans: ans.add(a) else: temp *= a if temp not in ans: ans.add(temp) temp = 1 if temp != 1 and temp not in ans and len(ans) == 2: ans.add(temp) print 'YES' print ' '.join(str(a) for a in list(ans)) else: print 'NO'
PYTHON
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# Problem C T = int(input()) for _ in range(T): n = int(input()) a = 0 b = 0 c = 0 for i in range(2, int(n**0.5)): if n % i == 0: a = i break else: continue if a != 0: for i in range(a+1, int(n**0.5)): if n/a % i == 0: b = i c = int(n/(a*b)) break else: continue if c > 1 and b != c and a!= c: print("YES") print(a,b,c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for i in range(int(input())): n=int(input()) l=[] count=0 for i in range(2,int(math.sqrt(n))+1): if n%i==0: l.append(i) n=n//i break for i in range(2,int(math.sqrt(n))+1): if n%i==0 and len(l)==1 and l[0]!=i: l.append(i) n=n//i count=1 break flag=0 if count==1: if n!=l[0] and n!=l[1]: l.append(n) else: flag=1 if len(l)==3 and flag==0: print("YES") print(*l) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; import java.io.*; public class Aman { public static void main(String args[]) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int i = 0; i < t; i++) { int n = in.nextInt(); int ans[] = new int[3]; int m = 0; int temp = (int) Math.sqrt(n); for(int j = 2; j < temp && m < 2; j++) { if(n%j == 0) { ans[m++] = j; n = n/j; } } if(m == 2) { ans[m] = n; if(ans[1] != ans[2] && ans[0] != ans[2] && n != 1) { System.out.println("YES"); System.out.print(ans[0] + " " + ans[1] + " " + ans[2] + "\n"); } else System.out.println("NO"); } else { System.out.println("NO"); } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t = 1; cin >> t; while (t--) { long long int i, j, k = 0, n, m, s, s1, l, r, x, y, a = 1, b = 1; cin >> n; for (i = 2; i * i <= n; i++) { if (n % i == 0) { a = i; n = n / i; break; } } for (i = 2; i * i <= n; i++) { if (n % i == 0 && i != a) { b = i; n = n / i; break; } } if (a > 1 && b > 1 && n > 1 && a != b && b != n && a != n) { cout << "YES" << endl; cout << a << " " << b << " " << n << 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
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, ans = 0, i; cin >> n; vector<int> v; for (i = 2; i < pow(n, 0.5); i++) { if (ans == 2) break; if (n % i == 0) { ans++; n = n / i; v.push_back(i); } } if (v.size() == 2) { v.push_back(n); cout << "YES" << "\n"; for (i = 0; i < 3; i++) { cout << v[i] << " "; } cout << "\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
prime = [] l = [] for i in range(40000): prime.append(True) for i in range(2,40000): if prime[i] == True: l.append(i) tmp = 2*i while tmp < 40000: prime[tmp] = False tmp += i t = int(input()) for i in range(t): n = int(input()) flag = False for j in l: if j**2 > n: break if n%j == 0: q = n//j for k in range(j+1, q): if k**2 > q: break if k != j and q%k == 0: if q//k != k: flag = True print("YES") print(j, k, q//k, sep = " ") break 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
from math import sqrt t = int(input()) for i in range(t): n = int(input()) l = [] temp = n for j in range(2,int(sqrt(n))+1): if temp%j == 0: l.append(j) temp = temp//j if len(l) == 2: break if len(l) < 2: print("NO") continue l.append(n//(l[0]*l[1])) # print(l) l.sort() a,b,c = l[0],l[1],l[2] if a*b*c != n or a == b or b == c or c == a or a == 1 or b == 1 or c == 1: 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
from math import sqrt def primes(n): y, count, result = n, 0, list() for i in range(2, int(sqrt(n)) + 1): if y % i == 0: count += 1 y = y // i result.append(i) if count >= 2: break print("YES" if count >= 2 and y not in result else "NO") if count >= 2 and y not in result: print(*(result + [y])) for _ in range(int(input())): primes(int(input()))
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 i in range(int(input())): n=int(input()) r=[] q=2 i=0 while i<2 and q<=math.sqrt(n): if n%q==0: r.append(q) i+=1 n=n//q q+=1 if n!=1: r+=[n] if len(r)<3 or r[1]==r[2] or r[0]==r[2] or r[0]==r[1]: print('NO') else: print('YES') print(*r)
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 int j, pri[100005], i; vector<long long int> prime; int main() { long long int t; cin >> t; while (t--) { long long int n, tmp, cnt = 0, prod = 1; cin >> n; tmp = n; unordered_set<long long int> st; for (i = 2; i <= ceil(sqrt(tmp)); i++) { if (n % i == 0) { st.insert(i); n /= i; cnt++; prod *= i; if (cnt == 2) break; } } if (cnt < 2) { cout << "NO\n"; continue; } long long int lst = tmp / (prod); if (lst != 1) { st.insert(lst); if (st.size() == 3) { cout << "YES\n"; for (auto it = st.begin(); it != st.end(); it++) cout << *it << " "; cout << "\n"; } else cout << "NO\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
''' * Author : Ayushman Chahar # * About : II Year, IT Undergrad # * Insti : VIT, Vellore # ''' import os import sys import math from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") def pf(n): ans = [] while(n % 2 == 0): ans.append(2) n //= 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while(n % i == 0): ans.append(i) n //= i if(n > 2): ans.append(n) return ans def main(): for _ in range(int(input())): n = int(input()) res = pf(n) # print(res) if(len(res) <= 2): print("NO") else: if(len(res) == 3): if(len(set(res)) == 3): print("YES") print(*res) else: print("NO") else: a1 = res[0] a2 = 1 idx = -69 for i in range(1, len(res)): if a2 != a1 and a2 != 1: idx = i break else: a2 *= res[i] a3 = 1 for i in range(idx, len(res)): a3 *= res[i] if(a3 != a2 and a3 != a1): print("YES") print(a1, a2, a3) else: print("NO") 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
#Ashish Sagar import math q=int(input()) for _ in range(q): n=int(input()) l=[] for i in range(2,int(math.sqrt(n))): if n%i==0: n=n//i l.append(i) break for i in range(2,int(math.sqrt(n))+1): if n%i==0 and len(l)==1 and i!=l[0]: n=n//i l.append(i) break if n!=1 and len(l)==2 and n!=l[0] and n!=l[1]: l.append(n) print("YES") print(*l) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys # sys.setrecursionlimit(10**6) from sys import stdin, stdout import bisect #c++ upperbound import math import heapq def modinv(n,p): return pow(n,p-2,p) def cin(): return map(int,sin().split()) def ain(): #takes array as input return list(map(int,sin().split())) def sin(): return input() def inin(): return int(input()) import math def Divisors(n) : l = [] for i in range(1, int(math.sqrt(n) + 1)) : if (n % i == 0) : if (n // i == i) : l.append(i) else : l.append(i) l.append(n//i) return l """*******************************************************""" def main(): t=inin() for _ in range(t): n=inin() a=[] c=0 for i in range(2,int(math.sqrt(n))+5): if(c==2): break if(n%i==0): a.append(i) n=n//i c+=1 if(n>1): a.append(n) a=list(set(a)) if(len(a)==3): print("YES") print(*a) else: print("NO") ######## Python 2 and 3 footer by Pajenegod and c1729 # Note because cf runs old PyPy3 version which doesn't have the sped up # unicode strings, PyPy3 strings will many times be slower than pypy2. # There is a way to get around this by using binary strings in PyPy3 # but its syntax is different which makes it kind of a mess to use. # So on cf, use PyPy2 for best string performance. py2 = round(0.5) if py2: from future_builtins import ascii, filter, hex, map, oct, zip range = xrange import os, sys from io import IOBase, BytesIO BUFSIZE = 8192 class FastIO(BytesIO): newlines = 0 def __init__(self, file): self._file = file self._fd = file.fileno() self.writable = "x" in file.mode or "w" in file.mode self.write = super(FastIO, self).write if self.writable else None def _fill(self): s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0]) return s def read(self): while self._fill(): pass return super(FastIO,self).read() def readline(self): while self.newlines == 0: s = self._fill(); self.newlines = s.count(b"\n") + (not s) self.newlines -= 1 return super(FastIO, self).readline() def flush(self): if self.writable: os.write(self._fd, self.getvalue()) self.truncate(0), self.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable if py2: self.write = self.buffer.write self.read = self.buffer.read self.readline = self.buffer.readline else: self.write = lambda s:self.buffer.write(s.encode('ascii')) self.read = lambda:self.buffer.read().decode('ascii') self.readline = lambda:self.buffer.readline().decode('ascii') sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip('\r\n') # Cout implemented in Python import sys class ostream: def __lshift__(self,a): sys.stdout.write(str(a)) return self cout = ostream() endl = '\n' # Read all remaining integers in stdin, type is given by optional argument, this is fast def readnumbers(zero = 0): conv = ord if py2 else lambda x:x A = []; numb = zero; sign = 1; i = 0; s = sys.stdin.buffer.read() try: while True: if s[i] >= b'0' [0]: numb = 10 * numb + conv(s[i]) - 48 elif s[i] == b'-' [0]: sign = -1 elif s[i] != b'\r' [0]: A.append(sign*numb) numb = zero; sign = 1 i += 1 except:pass if s and s[-1] >= b'0' [0]: A.append(sign*numb) return A if __name__== "__main__": main()
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 double PI = acos(-1.0L); const long double EPS = 1e-12L; mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count()); namespace task { int t, n, k; vector<int> p; int main() { cin >> t; while (t--) { cin >> n; k = n; p = {}; for (int i = 2; i < min(n, 100000); ++i) { if (n % i == 0) { p.push_back(i); n /= i; } } if (p.size() < 2) { cout << "NO\n"; } else if (p.size() == 2) { if (n <= p.back()) { cout << "NO\n"; } else { cout << "YES\n" << p[0] << ' ' << p[1] << ' ' << n << '\n'; } } else { cout << "YES\n" << p[0] << ' ' << p[1] << ' ' << k / p[0] / p[1] << '\n'; } } return 0; } } // namespace task int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.precision(11); cout.setf(ios::fixed); return task::main(); }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; void find(vector<long long int>& v, long long int n) { for (long long int i = 2; i <= sqrt(n); i++) { while (n > 0 && n % i == 0) { v.push_back(i); n = n / i; } } } int main() { int t; cin >> t; while (t--) { long long int n, a, b, c; cin >> n; vector<long long int> v; find(v, n); if (v.size() < 2) { cout << "NO" << endl; continue; } a = v[0]; if (v.size() > 2 && v[1] == v[0]) { b = v[1] * v[2]; } else { b = v[1]; } if (n % (a * b) != 0) { cout << "NO" << endl; } else { c = n / (a * b); if (a > 1 && b > 1 && c > 1 && a != b && a != c && b != c) { cout << "YES" << endl; cout << a << " " << b << " " << c << 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
# -*- coding: utf-8 -*- """ Created on Wed Feb 12 15:07:02 2020 @author: MilΓ‘n """ import math t = int(input()) L = [] for i in range(t): L += [int(input())] def multiples(n): i = 2 while i <= math.floor(n ** (1./3.)): if n%i == 0: j = i + 1 k = n/i while j <= math.sqrt(k): if k%j == 0 and j != math.sqrt(k): return "\n" + "YES" + "\n" + str(i) + " " + str(j) + " " + str(int(k/j)) j += 1 i += 1 return "\n" + "NO" for l in L: print(multiples(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
#include <bits/stdc++.h> using namespace std; int n, a, b, c; bool solve() { cin >> n; int i = 2; for (i = 2; i * i < n; i++) { if (n % i == 0) { n /= i; a = i; break; } } for (int j = 2; j * j < n; j++) { if (j == i) continue; if (n % j == 0) { b = j; c = n / j; return 1; } } return 0; } int main() { int tc; cin >> tc; while (tc--) { if (solve()) { cout << "YES\n"; cout << a << ' ' << b << ' ' << c << endl; } 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
from math import sqrt test = int(input()) while test > 0: test -= 1 n = int(input()) first = [] sz = 0 for i in range (2, int(sqrt(n)+1)): if(n % i == 0): first.append(i) sz += 1 found = False for i in range (sz): for j in range (i+1, sz): if first[i] != first[j] and n % (first[i]*first[j]) == 0\ and n / (first[i]*first[j]) != first[i] and n / (first[i]*first[j]) != first[j]: print("YES") print(first[i], end = " ") print(first[j], end = " ") print(int(n / (first[i]*first[j]))) found = True break if(found): break if(found == 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 sys input = lambda:sys.stdin.readline() int_arr = lambda: list(map(int,input().split())) str_arr = lambda: list(map(str,input().split())) get_str = lambda: map(str,input().split()) get_int = lambda: map(int,input().split()) get_flo = lambda: map(float,input().split()) mod = 1000000007 def solve(n): ans = [] i = 2 while len(ans) < 2 and i*i < n: if n % i == 0: ans.append(i) n //= i i += 1 if len(ans) == 2: print("YES") print(ans[0],ans[1],n) else: print("NO") for _ in range(int(input())): n = int(input()) solve(n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> int main() { int x, i, j, k, n, c, m[3]; scanf("%d", &x); while (x--) { j = 0; c = 0; scanf("%d", &n); for (i = 2; i * i <= n; i++) { if (n % i == 0) { k = n / i; if (k > i) { for (j = 2; j * j <= k; j++) { if (k % j == 0 && j != i && j * j != k && k / j != i) { m[0] = i; m[1] = j; m[2] = k / j; c++; break; } } if (c > 0) break; } } } if (c == 0) printf("NO\n"); else { printf("YES\n"); for (i = 0; i < 3; i++) printf("%d ", m[i]); printf("\n"); } } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.Scanner; public class task_c { public String answer; public boolean correct; public task_c() { Scanner scanner = new Scanner(System.in); int number = scanner.nextInt(); for (int i = 0; i<number; i++) { int zahl = scanner.nextInt(); answer = ""; correct = false; recursion(zahl, 3, 2); if (correct) { System.out.println("YES"); System.out.println(answer); } else { System.out.println("NO"); } } scanner.close(); } public void recursion(int number, int amount, int last) { if (amount == 1) { if (number>=last) { answer = answer + number; correct = true; } } else if (last>Math.pow(number, 0.5)) { correct = false; } else { for (int j = last; j<(int)Math.pow(number, 0.5)+1; j++) { if (number%j==0) { answer = answer+ j + " "; recursion(number/j, amount-1, j+1); break; } } } } public static void main(String[] args) { new task_c(); } }
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; #pragma comment(linker, "/STACK:10240000000,10240000000") char ch; int bo; inline bool blank(char ch) { return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t'; } inline void rd(int &x) { x = bo = 0; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') bo = 1; for (; ch >= '0' && ch <= '9'; x = (x << 1) + (x << 3) + ch - '0', ch = getchar()) ; if (bo) x = -x; } inline void RD(long long &x) { x = bo = 0; for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') bo = 1; for (; ch >= '0' && ch <= '9'; x = (x << 1) + (x << 3) + ch - '0', ch = getchar()) ; if (bo) x = -x; } inline long long RD() { long long x; RD(x); return x; } inline int rd() { int x; rd(x); return x; } inline void RD(char *s) { for (ch = getchar(); blank(ch); ch = getchar()) ; for (; !blank(ch); ch = getchar()) *s++ = ch; *s = 0; } inline void RD(char &c) { for (ch = getchar(); blank(c); ch = getchar()) ; } template <class T> inline void OT(T x) { static char buf[20]; char *p1 = buf; if (!x) *p1++ = '0'; if (x < 0) putchar('-'), x = -x; while (x) *p1++ = x % 10 + '0', x /= 10; while (p1-- != buf) putchar(*p1); } const int maxn = 1e3 + 10; const int mod = 1e9 + 7; vector<int> v; int main() { for (int _ = rd(), Case = 1; Case <= _; Case++) { int n = rd(); int rn = n; int num = 0; v.clear(); for (int i = 2; i * i <= n; i++) { if (n % i == 0) { num++; n /= i; v.push_back(i); if (v.size() >= 3) break; } } if (v.size() < 3 && n != 1) v.push_back(n); if (v.size() < 3) puts("NO"); else { int fl = 0; for (int i = 0; i < v.size(); i++) for (int j = i + 1; j < v.size(); j++) if (v[i] == v[j]) fl = 1; if (fl) puts("NO"); else { puts("YES"); printf("%d %d %d\n", v[0], v[1], rn / v[0] / v[1]); } } } }
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.math.BigInteger; import java.util.*; public class Main { 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(); } } public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out)); public static long mod = (long) (1e9 + 7); public static int N = (int) 1e5; public static long[][] dp; public static List<Integer>[] edges ; public static void main(String[] args) throws IOException { // TODO Auto-generated method stub FastReader sc = new FastReader(); int t = sc.nextInt(); while ((t--) != 0) { int n = sc.nextInt(); Map<Integer,Integer> map = new HashMap<>(); find(map, n); } out.close(); } private static void find(Map<Integer, Integer> map, int n) { int t = n; while ((n % 2) == 0) { map.put(2,map.getOrDefault(2,0)+1); n /= 2; } int l = (int) Math.sqrt(n); for (int i = 3 ; i <= l ; i += 2) { while (n % i == 0) { map.put(i,map.getOrDefault(i,0)+1); n /= i; } } if (n > 1) { map.put(n,map.getOrDefault(n,0)+1); } List<Integer> list = new ArrayList<>(); for (int i : map.keySet()) { for (int j = 0 ; j < map.get(i) ; j++) { list.add(i); } } long a = list.get(0); long b = 1; long c = 1; for (int i = 1; i < list.size() ; i++) { b *= list.get(i); long x = (t / (a * b)); if (a == b || b == x || x == a) { continue; } else { c = x; break; } } if (c == 1) { out.println("NO"); return; } out.println("YES"); out.println(a+" "+b+" "+c); } }
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; void solve() { long long n; cin >> n; set<long long> s; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { n = n / i; s.insert(i); break; } } for (int i = 2; i * i <= n; i++) { if (n % i == 0 && !s.count(i)) { n = n / i; s.insert(i); break; } } if (s.size() < 2 || s.count(n) || n == 1) cout << "NO" << endl; else { s.insert(n); cout << "YES" << endl; for (auto e : s) cout << e << " "; cout << endl; } } int main() { 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
t = int(input()) for _ in range(t): n = int(input()) if n < 2*3*4: print("NO") else: r = [] i = 2 j = 3 while j > 1: l = len(r) for k in range(i, int(n**(1/j) + 2)): if n % k == 0: r.append(k) n //= k i = k + 1 j -= 1 break if len(r) == l or len(r) == 2: break if len(r) == 2 and n > int(r[-1]): r.append(n) print('YES') print(' '.join(map(str, r))) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t = int(input()) for i in range(t): n = int(input()) li = [] n_ = math.ceil(n** 0.5) for j in range(2,n_): if n % j == 0: li.append(j) n = n // j if n != 1: li.append(n) if len(li) <= 2: print("NO") else: w1 = li[0] w2 = li[1] w3 = 1 for k in range(2,len(li)): w3 = w3 * li[k] if w1 != w2 and w2 != w3 and w3 != w1: print("YES") print(str(w1) + " " + str(w2) + " " + str(int(w3))) 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 find_factors(n): l = [] while n % 2 == 0: l.append(2) n //= 2 for i in range(3,int(math.sqrt(n)+1),2): while n % i == 0: l.append(i) n //= i if n > 2: l.append(n) return l for _ in range(int(input())): n = int(input()) k0 = find_factors(n) k1 = list(dict.fromkeys(k0)) # print(k0) # print(k1) if len(k1) == 1: if len(k0) <= 5: print("NO") else: print('YES') pro = 1 for i in range(3,len(k0)): pro *= k0[i] print(k0[0],k0[1]*k0[2],pro) elif len(k1) == 2: if len(k0) <= 3: print("NO") else: pro = 1 print("YES") for i in range(1,len(k0)-1): pro *= k0[i] print(k0[0],k0[-1],pro) elif len(k1) == 3: b = [1,1,1] print("YES") for i in range(len(k0)): if k0[i] == k1[0]: b[0] *= k0[i] elif k0[i] == k1[1]: b[1] *= k0[i] else: b[2] *= k0[i] print(*b) else: m = k1[0] n = k1[1] k0.remove(m) k0.remove(n) pro = 1 print("YES") for i in range(len(k0)): pro *= k0[i] print(m,n,pro)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.* ; import java.math.*; import java.io.*; public class javaTemplate { // public static final int M = 1000000007 ; public static final int M = 1000003 ; static FastReader sc = new FastReader(); // static Scanner sc = new Scanner(System.in) ; public static void main(String[] args) { int t= sc.nextInt() ; while(t -- != 0) { int n = sc.nextInt() ; int a = n , b = n , c = n ; for(int i = 2 ; i*i <= n ; i++) { if(n % i == 0) { a = i ; break ; } } n = n/a ; for(int i = 2; i*i <= n ; i++) { if(n%i == 0) { if(i != a) { b = Math.min(b, i) ; break ; } else { if((n/i) != i && (n/i) != a) { b = Math.min(b,(n/i)) ; } } } } c = n/b ; if(a!= b && b!= c && c != a && c >= 2) { System.out.println("YES"); System.out.println(a + " " + b + " " + c); } else { System.out.println("NO"); } } } //_________________________//Template//_____________________________________________________________________ // FAST I/O static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader( new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } // Check Perfect Squre public static boolean checkPerfectSquare(double number) { double sqrt=Math.sqrt(number); return ((sqrt - Math.floor(sqrt)) == 0); } static boolean isPrime(int n) { if (n <= 1) return false; for (int i = 2; i < n; i++) { if (n % i == 0) return false; } return true; } // Modulo static int mod(int a) { return (a%M + M) % M; } // Palindrom or Not static boolean isPalindrome(StringBuilder str, int low, int high) { while (low < high) { if (str.charAt(low) != str.charAt(high)) return false; low++; high--; } return true; } // Euler Tortient fx static int Phi(int n) { int count = 0 ; for(int i = 1 ; i< n ; i++) { if(GCD(i,n) == 1) count ++ ; } return count ; } // Integer Sort static void sort(int[] a) { ArrayList<Integer> l=new ArrayList<>(); for (int i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } // Long Sort static void sort(long[] a) { ArrayList<Long> l=new ArrayList<>(); for (long i:a) l.add(i); Collections.sort(l); for (int i=0; i<a.length; i++) a[i]=l.get(i); } // boolean Value static void value(boolean val) { System.out.println(val ? "YES" : "NO"); System.out.flush(); } // GCD public static long GCD(long a , long b) { if(b == 0) return a ; return GCD(b, a%b) ; } // sieve public static boolean [] sieveofEratosthenes(int n) { boolean isPrime[] = new boolean[n+1] ; Arrays.fill(isPrime, true); isPrime[0] = false ; isPrime[1] = false ; for(int i = 2 ; i * i <= n ; i++) { for(int j = 2 * i ; j<= n ; j+= i) { isPrime[j] = false ; } } return isPrime ; } // fastPower public static long fastPowerModulo(long a, long b, long n) { long res = 1 ; while(b > 0) { if((b&1) != 0) { res = (res * a % n) % n ; } a = (a % n * a % n) % n ; b = b >> 1 ; } return res ; } // check if sorted or not public static boolean isSorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] > a[i + 1]) { return false; } } return true; } // Palindrom or Not static boolean isPalindrome(String str, int low, int high) { while (low < high) { if (str.charAt(low) != str.charAt(high)) return false; low++; high--; } return true; } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def sol(n): ans = [] i = 2 cnt = 0 while n > 0 and i*i <= n: if not(n%i): cnt += 1 n //= i ans.append(i) i += 1 if cnt >= 2: break tr = cnt >= 2 and n not in ans print("YES" if tr else "NO") if tr: print(*ans[:2], n) t = int(input()) for _ in range(t): n = int(input()) res = sol(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
def helper(n): upper = int(n**0.5) + 1 for i in range(2, upper): if n % i == 0: curr = n //i for j in range(i + 1, upper): if curr % j == 0: new_curr = curr //j if i < j < new_curr: return [i, j, new_curr] return [] count = int(input()) for _ in range(count): ans = helper(int(input())) if len(ans) != 3: print('NO') else: print('YES') for val in ans: print(val, end = ' ') print()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math T=int(input()) for _ in range(T): N=int(input()) n=N L=[] while(n%2==0): L.append(2) n=n//2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: L.append(i) n = n // i if(n>2): L.append(n) #print(L) a=L[0] b=1 c=1 ptr=0 for j in range(1,len(L)): b=b*L[j] if(b!=a): ptr=j+1 break for j in range(ptr,len(L)): c=c*L[j] if(a==b or b==c or a==c or a*b*c!=N or a<2 or b<2 or c<2): print('NO') else: """a=L[0] b=1 c=1 ptr=0 for j in range(1,len(L)): b=b*L[j] if(b!=a): ptr=j+1 break for j in range(ptr,len(L)): c=c*L[j] G=list(set(L)) a=G[0]**(L.count(G[0])) b=G[1]**(L.count(G[1])) c=1 for j in range(0,len(L)): if(L[j]!=G[0] and L[j]!=G[1]): c=c*L[j]""" print('YES') print(a,b,c)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import ceil t = int(input()) for i in range(t): n = int(input()) ans = [] if n < 24: print('NO') else: for i in range(2, ceil(n**(1/3))+1): if n % i == 0: ans.append(i) break if len(ans)==0: print('NO') else: n1 = n//ans[0] for j in range(ans[0]+1, ceil(n**(1/2))+1): if n1 % j == 0: ans.append(j) break if len(ans) != 2: print('NO') else: n2 = n1 //ans[1] if n2 <= ans[1]: print('NO') else: print('YES') print(f'{ans[0]} {ans[1]} {n2}')
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; template <typename T, typename TT> ostream& operator<<(ostream& os, const pair<T, TT>& t) { return os << t.first << " " << t.second; } template <typename T> ostream& operator<<(ostream& os, const vector<T>& t) { for (auto& i : t) os << i << " "; return os; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; scanf("%lld", &t); while (t--) { long long n; scanf("%lld", &n); vector<long long> v; long long tmp = n; for (int i = 2; i * i <= tmp; i++) { while (tmp % i == 0) { v.push_back(i); tmp /= i; } } if (tmp > 1) v.push_back(tmp); if (v.size() < 3) { cout << "NO" << '\n'; continue; } long long a = -1, b = -1, c = -1; a = v[0]; b = v[1]; if (b == a) b *= v[2]; c = n / (a * b); if (c == b or c == a or c <= 1) cout << "NO" << '\n'; else { cout << "YES" << '\n' << a << " " << b << " " << c << '\n'; } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def getFacts(n): facts = [] for i in range(2,int(n**0.5)+1): if n%i == 0: facts.append(i) if i != n//i: facts.append(n//i) return facts def solve(n): facts = getFacts(n) for i in range(len(facts)): a = facts[i] bc = n//a f = getFacts(bc) for k in f: b = k c = bc//k if a != b and b != c and a != c: print('YES') print(a,b,c) return print('NO') def main(): t = int(input()) for i in range(t): n = int(input()) solve(n) 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 printDivisors(n) : i = 2 x = [] while i <= math.sqrt(n): if (n % i == 0) : if (n / i == i) : x.append(i) else : x.append(i) x.append(n//i) i = i + 1 return x t = int(input()) for test in range(t): n = int(input()) x = printDivisors(n) y = {} for aa in x: y[aa] = y.get(aa,0)+1 nn = len(x) # print(y) f=0 a,b,c=0,0,0 for i in range(nn-1): for j in range(i+1,nn): if (x[i]*x[j])<=n and (x[i]*x[j])!=0 and (n%(x[i]*x[j])==0): check = n//(x[i]*x[j]) #print(check,x[i],x[j]) if check==x[i] or check==x[j]: continue elif check in y: #print("SS") f=1 a= x[i] b = x[j] c = check break if f==1: break if f==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 _ in range(int(input())): n=int(input()) l=[] i=2 while len(l)<2 and i*i<n: if n%i==0: l.append(i) n=n//i i+=1 if len(l)==2 and n not in l: print("YES") print(*l,n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for t in range(int(input())): n=int(input()) p,q=0,0 """ for i in range(2,int(n)): if c==1: break elif n%i==0: for j in range(2,int(pow(n,1/2))+1): if j==i: continue if c==1: break if n%(i*j)==0: r=n/(i*j) if r==1: continue if i!=j and r!=j and i!=r: if i*j*r==n: #print (i," ",j," ",int(n/(i*j))) p=i q=j r=int(n/(i*j)) c=1 break """ for i in range(2,int(pow(n,1/2)+1)): if n%i==0: p=i n=n/i break for i in range(2,int(pow(n,1/2)+1)): if n%i==0 and p!=i: q=i n=n/i break #print(p,q,n) n=int(n) if p!=0 and q!=0 and n!=1 and n!=p and n!=q: print("YES") print (p,q,int(n)) #print (p," ",q," ",r) 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.DataInputStream; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; public class ProductofThreeNumbers { static int mod = 1000000007; static class Reader { final private int BUFFER_SIZE = 1 << 16; private DataInputStream din; private byte[] buffer; private int bufferPointer, bytesRead; public Reader() { din = new DataInputStream(System.in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public Reader(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[10005]; // 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(); } } static class IntIntPair implements Comparable<IntIntPair> { public final int first; public final int second; public static IntIntPair makePair(int first, int second) { return new IntIntPair(first, second); } public IntIntPair(int first, int second) { this.first = first; this.second = second; } public boolean equals(Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } IntIntPair pair = (IntIntPair) o; return first == pair.first && second == pair.second; } public int hashCode() { int result = first; result = 31 * result + second; return result; } public String toString() { return "(" + first + "," + second + ")"; } public int compareTo(IntIntPair o) { int value = Integer.compare(first, o.first); if (value != 0) { return value; } return Integer.compare(second, o.second); } } public static void main(String[] args) throws IOException { Reader in = new Reader(); int i, t, n, x; t = in.nextInt(); StringBuilder ans = new StringBuilder(); while (t-- > 0) { n = in.nextInt(); List<IntIntPair> num = new ArrayList<>(); for (i = 2; i * i <= n; i++) { // System.out.println(i + " " + (Math.log(n * 1.0) / Math.log(i * 1.0))); if (n % i == 0) { x = (int) (Math.log10(n * 1.0) / Math.log10(i * 1.0)); int z = 1; for (int j = 1; j <= x + 1; j++) { if (n % (int) (Math.pow(i, j)) == 0) { z = j; } } num.add(IntIntPair.makePair(i, z)); n = n / (int) (Math.pow(i, z)); } } // System.out.println(n); if (n != 1) { num.add(IntIntPair.makePair(n, 1)); } // System.out.println(num); if (num.size() == 0) { ans.append("NO\n"); continue; } if (num.size() == 1) { if (num.get(0).second >= 6) { ans.append("YES\n"); x = num.get(0).first; int a = x, b = x * x, c = (int) Math.pow(x, num.get(0).second - 3); ans.append(a + " " + b + " " + c + "\n"); } else { ans.append("NO\n"); } continue; } if (num.size() == 2) { if (num.get(0).second >= 3) { ans.append("YES\n"); x = num.get(0).first; int a = x, b = (int) Math.pow(x, num.get(0).second - 1), c = (int) Math.pow(num.get(1).first, num.get(1).second); ans.append(a + " " + b + " " + c + "\n"); } else if (num.get(1).second >= 3) { ans.append("YES\n"); x = num.get(1).first; int a = x, b = (int) Math.pow(x, num.get(1).second - 1), c = (int) Math.pow(num.get(0).first, num.get(0).second); ans.append(a + " " + b + " " + c + "\n"); } else if (num.get(0).second == 2 && num.get(1).second == 2) { ans.append("YES\n"); x = num.get(1).first; int a = x, b = num.get(0).first, c = a * b; ans.append(a + " " + b + " " + c + "\n"); } else ans.append("NO\n"); continue; } int a, b, c; x = 1; for (i = 0; i < num.size() - 2; i++) { x = x * (int) Math.pow(num.get(i).first, num.get(i).second); } int y = num.size(); b = (int) Math.pow(num.get(y - 2).first, num.get(y - 2).second); c = (int) Math.pow(num.get(y - 1).first, num.get(y - 1).second); ans.append("YES\n" + x + " " + b + " " + c + "\n"); } System.out.println(ans); } }
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 compute_problem(n): if n < 24: print("NO") elif n % 10 == 0: a = 2 n_div_10 = int(n/10) b = min(5, n_div_10) c = max(5, n_div_10) if b != c: print("YES") print(a, b, c, sep=" ") else: print("NO") else: result_found = False max_a = int(n ** (1. / 3.)) + 1 for a in range(2, max_a): #print("a: ", a) if not n % a == 0: continue max_b = int((int(n/a) + 1)**(1./2.)) + 1 for b in range(a + 1, max_b): #print("b: ", b) prod_ab = a * b c = int(n/prod_ab) #print("c: ", c) #print(( (n % prod_ab == 0) , (prod_ab != n) , (c != a) , (c != b))) result_found = (n % prod_ab == 0) and (prod_ab != n) and (c != a) and (c != b) #print(result_found) if result_found: print("YES") print(a, b, c, sep=" ") break if result_found: break if not result_found: print("NO") num_tests = int(input()) for test_num in range(0, num_tests): test_case = input() if test_case: aim_num = int(test_case) compute_problem(aim_num)
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 = [] d = 2 while len(a) < 2 and d * d <= n: if 0 == n % d: a += d, n //= d d += 1 if a and n > a[-1]: a += n, if len(a) < 3: print('NO') else: print('YES') print(*a)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int arr[3]; int k = 0; for (int i = 2; i * i <= n && k < 2; i++) { if (n % i == 0) { n /= i; arr[k++] = i; } } if (k == 2 && arr[1] < n) { printf("YES\n%d %d %d\n", arr[0], arr[1], n); } else { printf("NO\n"); } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def Find(n): for i in range(2,int(n**0.5)+1): if (not n%i): p = int(n/i) if (p >= 2): for j in range(2,int(p**0.5)+1): if (i != j) and (not p%j): k = int(p/j) if (k>=2) and (i != k) and (j != k): return "YES\n"+str(i)+" "+str(j)+" "+str(k) return "NO" def main(): t = int(input()) outcome = [Find(int(input())) for _ in range(t)] print("\n".join(outcome)) 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()) while t: n = int(input()) i = 2 a = 0 while i*i<=n: if n%i==0: a=i n=n/i break i+=1 i =2 b =0 while i*i<=n: if n%i==0 and a!=i: b= i n=n/i c = n break i+=1 if(a>=2 and b>=2 and c>=2 and c!=b and c!=a): print("YES") print(int(a),int(b),int(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
import math from collections import Counter def primeFactors(n): a = [] c = 0 while n % 2 == 0: a.append(2) n = n // 2 c+=1 # n must be odd at this point # so a skip of 2 ( i = i + 2) can be used for i in range(3, int(math.sqrt(n)) + 1, 2): # while i divides n , print i ad divide n while n % i == 0: a.append(i) n = n // i c+=1 # Condition if n is a prime # number greater than 2 if n > 2: a.append(n) c+=1 return Counter(a),c cases = int(input()) for t in range(cases): n = int(input()) d,c = primeFactors(n) v = len(d) if v>2: v = list(d.keys()) print("YES") print(v[0],v[1],n//(v[0]*v[1])) elif v==2: if c>3: v = list(d.keys()) print("YES") print(v[0],v[1],n//(v[0]*v[1])) else: print("NO") else: if c>5: v = list(d.keys())[0] print("YES") print(v,v**2,n//(v**3)) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; template <typename T> void print(set<T> v) { for (auto x : v) cout << x << " "; cout << endl; } set<long long int> count_div(long long int m, long long int j) { set<long long int> s; for (long long int i = 1; i <= sqrtl(m); i++) { if (m % i == 0 && i > j) { if (i != m / i && (m / i != j)) { s.insert(i); s.insert(m / i); return s; } else continue; } } return s; } set<long long int> divisors(long long int n) { set<long long int> s; for (long long int i = 1; i <= sqrtl(n); i++) { if (n % i == 0 && i >= 2) { if (i != n / i) { s = count_div(n / i, i); if (s.size() == 2) { s.insert(i); return s; } } } } return s; } signed main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; set<long long int> s = divisors(n); if (s.size() == 3) { cout << "YES" << endl; print(s); } 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
for _ in range(int(input())): n=int(input()) ans=False for i in range(2,int(n**(0.5))+1): a=i if n%i==0: div=n//i for j in range(2,int(div**0.5)+1): if div%j==0 and j!=a: div2=div//j if div2!=1 and div2!=j and div2!=a: ans=True break if ans: break if ans: print("YES") print(a,div//div2,div2) 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 res=[1,1,1] def del1(a,k,d): sqrtlam=lambda x : math.sqrt(x) for i in range(d,math.ceil(sqrtlam(a))): if a%i==0: if(k)==1: if(int(a/i)!=res[0]): res[1]=int(i) res[2]=int(a/i) return 1 else: res[0]=i if(del1(a/i,k+1,i+1)): return 1 return 0 n=int(input()) for i in range(n): res=[1,1,1] b=int(input()) if(del1(b,0,2)==0 ): print("NO") else: print("YES") print (*res)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def wa(a): for i in range(2,int(math.sqrt(a)),1): if(a%i==0): return False return True def ans(a): count=0 f=0 l=[] s='' d=int(math.sqrt(a)) for i in range(2,d+1,1): if(a%i==0): l.append(i) count+=1 a=a//i if(count==2 and l[0]!=a and l[1]!=a): l.append(a) f=1 break if(f): print("YES") for i in l: print(i,end=' ') print() else: print("NO") t=int(input()) while(t>0): a=int(input()) if(wa(a)==True): print("NO") elif(a%10==0): x=a//10 y=2 z=5 if(x*z*y==a and x!=y and x!=z and z!=y and x>1 and y>1 and z>1): print("YES") if(z>x): print(y,x,z) else: print(y,z,x) else: print("NO") else: ans(a) t-=1
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def function(num): var = int(math.sqrt(num)) + 1 for i in range(2,var+1): if (num%i == 0) and (num//i != i): return list((i,num//i)) t = int(input()) for _ in range(t): count = 0 n = int(input()) num = int(math.sqrt(n)) + 1 for i in range(2,num): if n%i == 0: func = function(n//i) if func == None:pass else: if len(set([i,func[0],func[1]])) == 3: count = 1 print('YES') print('{} {} {}'.format(i,func[0],func[1])) break else:pass if count == 0: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; void solve() { set<int> s; int n, i, a, l, p = 1, pr = 1; cin >> n; l = n; for (i = 2; i * i <= l; i++) { if (n % i == 0 && p < 3) { s.insert(i); n = n / i; if (p == 2 && n != 1) { s.insert(n); } p++; } } for (set<int>::iterator i = s.begin(); i != s.end(); i++) { pr = pr * (*i); } if (s.size() > 2 && pr == l) { cout << "YES\n"; for (set<int>::iterator i = s.begin(); i != s.end(); i++) cout << *i << " "; cout << "\n"; } else cout << "NO\n"; } 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
t = int(input()) for i in range(t): n = int(input()) ans = 'NO' p = q = 1 for j in range(2, int(n ** (1 / 3)) + 2): if n % j == 0: p = j n = n // p ans = 'YES' break if ans == 'YES': ans = 'NO' for j in range(p + 1, int(n ** (1 / 2)) + 2): if n % j == 0: q = j n = n // q ans = 'YES' break if n <= q: ans = 'NO' print(ans) if ans == 'YES': print(p, q, 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 def divisorGenerator(n): large_divisors = [] for i in range(1, int(math.sqrt(n) + 1)): if n % i == 0: yield i if i*i != n: large_divisors.append(int(n / i)) for divisor in reversed(large_divisors): yield divisor n = int(input()) for x in range(n): a = int(input()) t = (list(divisorGenerator(a))) t.pop(-1) t.pop(0) b1 = False b2 = False if len(t)<=2: print('NO') continue for z in range(0, len(t)-2): for zz in range(z+1, len(t)-1): for zzz in range(zz+1, len(t)): if t[z]*t[zz]*t[zzz] == a: print('YES') print(t[z], t[zz], t[zzz]) b1 = True break if b1 == True: b2 = True break if b2 == True: break if b1 == False and b2 == 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
from sys import stdin input=stdin.readline #a=[] import math def com(p,q,r): if p==q or q==r or p==r: return -1 else: return 1 def pd(n) : t=[] i = 1 while i <= math.sqrt(n): if (n % i == 0 and i!=1) : if (n // i == i) : t.append([i,i]) else : t.append([i,n//i]) i+=1 return t for _ in range (int(input())): n=int(input()) a=pd(n) ans=-1 for i in range(len(a)): if ans==1: break x=a[i][0] y=a[i][1] b=pd(x) c=pd(y) for i in range(len(b)): ans = com(b[i][0],b[i][1],y) if ans==1: ans1=[b[i][0],b[i][1],y] break if ans==1: break for i in range(len(c)): ans = com(c[i][0],c[i][1],x) if ans==1: ans1=[c[i][0],c[i][1],x] break if ans==1: print('YES') print(*ans1) 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 f(n): d={} for i in range(2,int(pow(n,0.5))+1): if n%i==0: d[i]=0 while n%i==0: d[i]=d[i]+1 n=n//i if n!=1: d[n]=1 return(d) final=[] t=int(input()) for i in range(0,t): n=int(input()) d=f(n) values = list(d.values()) keys=list(d.keys()) if len(keys)>=3: ans='YES' x=n//(keys[0]*keys[1]) final=[x,keys[0],keys[1]] elif len(keys)==2: if values[0] ==2 and values[1]==2: ans='YES' final=[keys[0],keys[1],keys[0]*keys[1]] elif values[0]>=3 or values[1]>=3: ans='YES' if d[keys[0]]>=3: final=[keys[0],keys[0]**(d[keys[0]]-1),keys[1]**(d[keys[1]])] else: final=[keys[1],keys[1]**(d[keys[1]]-1),keys[0]**(d[keys[0]])] else: ans='NO' else: if len(keys)==0: ans='NO' else: if values[0]>=6: ans='YES' final=[keys[0],keys[0]**2,n//(keys[0]**3)] else: ans='NO' if ans=='NO': print(ans) else: print(ans) for i in range(0,len(final)): print(final[i],end=' ') print()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def sf(s,n): for i in range(s,int(math.sqrt(n)+1)): if n%i==0: n=n//i return i,n return 1,n t=int(input()) #t=1 for _ in range(t): a,b,c=1,1,1 n=int(input()) a,n=sf(2,n) b,n=sf(a+1,n) c=n #print(a,b,c) if a!=b and b!=c and c!=1 and a!=c and a!=1 and b!=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
t = int(input()) while t: t-=1 n = int(input()) factors = [] for i in range(2,int(n**0.5)+1): if n%i==0: factors.append(i) if n//i!=i: factors.append(n//i) if len(factors)<2: print("NO") continue factors.sort() done = False for i in range(len(factors)): for j in range(i+1,len(factors)): a = factors[i] b = factors[j] c = n//(a) if c%b!=0: continue c = c//b if c>=2 and a!=c and b!=c : done = True print("YES") print(a,b,c) break if done: break if not done: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for T in range(t): n = int(input()) ans = [] for i in range(2, int(n ** 0.5) + 1): if n % i == 0: ans.append(i) val = n // i for j in range(2, int(val ** 0.5) + 1): ans = [i] if val % j == 0: ans.append(j) ans.append(val // j) if len(set(ans)) == 3: break ## print(ans) if len(set(ans)) == 3: break ans.append(n // i) val = i for j in range(2, int(val ** 0.5) + 1): if val % j == 0: ans.append(j) ans.append(val // j) if len(set(ans)) == 3: break ans = [n // i] ## print(ans) if len(set(ans)) == 3: break ans = [] if len(ans) == 3: print("YES") print(*ans) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def factors(n): i = 2 f = [] s = n while i*i <= n: while s % i == 0: s //= i f.append(i) i += 1 else: if s > 1: f.append(s) return f def solve(): f = factors(n) s = set() i = 0 x = 1 for i in f: if i not in s: s.add(i) if len(s) == 2: break else: x *= i if x != 1 and x not in s: s.add(x) if len(s) == 2: break x = 1 ss = list(s) r = n // (ss[0]*ss[1]) if len(ss) == 2 else 1 if len(s) == 2 and r != 1 and r != ss[0] and r != ss[1]: s.add(r) if len(s) >= 3: print("YES") print(' '.join(map(str, list(s)[:3]))) else: print("NO") def main(): global n for _ in range(int(input())): n = int(input()) solve() main()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) def factorization(n): ind = [] 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 ind.append(cnt) arr.append(i) if temp!=1: ind.append(1) arr.append(temp) if arr==[]: ind.append(1) arr.append(n) return arr, ind for i in range(t): n = int(input()) arr, ind = factorization(n) if len(arr) == 1: if ind[0] >= 6: print('YES') print(arr[0], arr[0]**2, arr[0]**(ind[0]-3)) else: print('NO') elif len(arr) == 2: if ind[0] >= 3: print('YES') print(arr[0], arr[0]**2, (arr[0]**(ind[0]-3))*(arr[1]**ind[1])) elif ind[1] >= 3: print('YES') print(arr[1], arr[1]**2, (arr[1]**(ind[1]-3))*(arr[0]**ind[0])) elif ind[0] >= 2 and ind[1] >= 2: print('YES') print(arr[0], arr[1], (arr[0]**(ind[0]-1))*(arr[1]**(ind[1]-1))) else: print('NO') else: print('YES') print(arr[0], arr[1], (n//arr[0])//arr[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; int main() { long long t, n; cin >> t; while (t--) { cin >> n; int a[3] = {}, count = 0; for (long long i = 2; i * i < n; i++) { if (n % i == 0) { a[count] = i; count++; n /= i; } if (count >= 2) break; } if (count != 2) cout << "NO\n"; else { cout << "YES\n"; cout << a[0] << " " << a[1] << " " << n << endl; } } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# import sys # file = open('test1') # sys.stdin = file def ii(): a = int(input()) return a def ai(): a = list(map(int, input().split())) return a def mi(): a = map(int, input().split()) return a from math import sqrt def fact(n): lst = [] for i in range(2, int(sqrt(n))+1): if n%i==0: a = i # print(a,"a") b = n//i for j in range(2, int(sqrt(b))+1): # print(j,"j") if b%j == 0 and j!=a and (b//j)!=a and j!=(b//j): lst.append(a) lst.append(j) lst.append(b//j) return lst for _ in range(ii()): n = ii() lst = fact(n) if lst: print("YES") print(*lst) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def isPrime(n : int): if n == 1: return False if n == 2: return True else: for i in range(2, n // 2): if n % i == 0: return False return True t = int(input()) for i in range(t): n = int(input()) y = n res = [] k = 2 for k in range(2, int(y ** 0.5) + 1): if n % k == 0: res.append(k) n = n // k k += 1 if len(res) == 2: break if len(res) == 2 and res[-1] < n: print("YES") print(*res, 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 main(): n = int(input()) different = [0, 0, 0] k = 0 for i in range(2, int(math.sqrt(n)) + 1): if k == 2: break if n % i == 0 and k < 2: n = n // i different[k] = i k += 1 if n == 1 or n == different[0] or n == different[1] or different[1] == 0: print("NO") return different[2] = n print("YES") print(different[0], different[1], different[2]) if __name__ == "__main__": t = int(input()) for i in range(t): 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 t = int(input()) def primefactorize(n): prime_factors_list = [] while n%2 == 0: prime_factors_list.append(2) n = n/2 for i in range(3,int(math.sqrt(n))+1,2): while n%i == 0: prime_factors_list.append(i) n = n/i if n > 2: prime_factors_list.append(n) return prime_factors_list def generate_factors(prime_factors_list,n): a = 1 b = 1 c = 1 for i in range(len(prime_factors_list)): if a == 1 : a *= prime_factors_list[i] elif b == 1 or a == b: b *= prime_factors_list[i] else: c *= prime_factors_list[i] return a,b,c for tt in range(t): n = int(input()) prime_factors = primefactorize(n) # print(prime_factors) a,b,c = generate_factors(prime_factors,n) if (a!=1 and b!=1 and c!=1) and (a!=b and b!=c and a!=c): print("YES") print(str(int(a))+ " " + str(int(b)) + " " + str(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
import sys import math input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return(int(input())) def inlt(): return(list(map(int,input().split()))) def insr(): s = input() return(list(s[:len(s) - 1])) def invr(): return(map(int,input().split())) t = inp() for i in range(t): n = inp() i = 2 check = False while(i*i <= n): if(n % i == 0): check = True nn = n//i j = i + 1 check2 = False while(j *j <= nn): if(nn % j == 0): c = nn // j if(c != j): if(c != i): print("YES") print(str(i) + " " + str(j) + " " + str(c)) check2 = True break j = j + 1 if(check2 == False): check = False break i = i + 1 if(check == 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
from sys import stdin input=lambda:stdin.readline().strip() from collections import defaultdict def fun(n,dict1): if n%2==0 and (n//2)!=2 and dict1[2]==0: #print(dict1[2]) return [2,n//2] elif n%3==0 and (n//3)!=3 and dict1[n//3]==0 and dict1[3]==0: return [3,n//3] else: i=2 while i*i<n: if n%i==0 and (n//i)!=i and dict1[n//i]==0 and dict1[i]==0: #print(dict1[i],'i',i) return [i,n//i] i+=1 return -1 for _ in range(int(input())): n=int(input()) if n<8: print('NO') else: dict1=defaultdict(int) a=fun(n,dict1) if a==(-1): print('NO') else: a,b=a dict1[a]+=1 #print(dict1) c=fun(b,dict1) if c==(-1): print('NO') else: print('YES') print(a,c[0],c[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; void solve() { int n; cin >> n; vector<int> factors; for (int i = 2; 1LL * i * i <= (long long int)n; ++i) { if (n % i == 0) { factors.push_back(n / i); if (n / i != i) { factors.push_back(i); } } } if (factors.size() < 2) { cout << "NO\n"; } else { sort(factors.begin(), factors.end()); int poss = 0; for (int i = 0; i < factors.size() and !poss; ++i) { for (int j = i + 1; j < factors.size() and !poss; ++j) { int a = factors[i]; int b = factors[j]; int c = n / a; if (c % b != 0) { continue; } c /= b; if (c >= 2 and c != a and c != b) { poss = 1; cout << "YES\n"; cout << a << " " << b << " " << c << '\n'; break; } } } if (!poss) cout << "NO\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); 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 sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log2, ceil from collections import defaultdict from bisect import bisect_left as bl, bisect_right as br from collections import Counter from collections import deque ip = lambda : int(stdin.readline()) inp = lambda: map(int,stdin.readline().split()) ips = lambda: stdin.readline().rstrip() t = ip() for _ in range(t): n = ip() ch = [] for i in range(2,int(n**0.5)+1): if n%i == 0: ch.append(i) ch.append(n//i) break if len(ch) == 2: a = ch[0] b = ch[1] ch = [] for i in range(2,int(a**0.5)+1): if a%i == 0: if i != b and a//i != b and i != a//i: ch.append(i) ch.append(a//i) break if len(ch) == 2: print("YES") print(b,ch[0],ch[1]) else: ch = [] for i in range(2,int(b**0.5)+1): if b%i == 0: if i != a and b//i != a and i!= b//i: ch.append(i) ch.append(b//i) break if len(ch) == 2: print("YES") print(a,ch[0],ch[1]) else: print("NO") else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
/* _oo0oo_ o8888888o 88" . "88 (| -_- |) 0\ = /0 ___/`---'\___ .' \\| |// '. / \\||| : |||// \ / _||||| -:- |||||- \ | | \\\ - /// | | | \_| ''\---/'' |_/ | \ .-\__ '-' ___/-. / ___'. .' /--.--\ `. .'___ ."" '< `.___\_<|>_/___.' >' "". | | : `- \`.;`\ _ /`;.`/ - ` : | | \ \ `_. \_ __\ /__ _/ .-` / / =====`-.____`.___ \_____/___.-`___.-'===== `=---=' */ import java.util.function.Consumer; import java.util.*; import java.math.BigDecimal; import java.math.BigInteger; import java.math.RoundingMode; import java.text.DecimalFormat; import java.io.*; import java.lang.Math.*; public class KickStart2020{ 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());} float nextFloat() {return Float.parseFloat(next());} String nextLine() { String str = ""; try {str = br.readLine();} catch (IOException e) { e.printStackTrace();} return str; }} static boolean isBracketSequence(String s, int a, int b) { Stack<Character> ss = new Stack<>(); boolean hachu = true; for(int i = a; i <= b; i++) { if(s.charAt(i) == ')' && ss.isEmpty()) {hachu = false; break;} if(s.charAt(i) == '(') ss.add('('); else ss.pop(); } return ss.empty() && hachu; } static String reverseOfString(String a) { StringBuilder ssd = new StringBuilder(); for(int i = a.length() - 1; i >= 0; i--) { ssd.append(a.charAt(i)); } return ssd.toString(); } static char[] reverseOfChar(char a[]) { char b[] = new char[a.length]; int j = 0; for(int i = a.length - 1; i >= 0; i--) { b[i] = a[j]; j++; } return b; } static boolean isPalindrome(char a[]) { boolean hachu = true; for(int i = 0; i <= a.length / 2; i++) { if(a[i] != a[a.length - 1 - i]) { hachu = false; break; } } return hachu; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } static long power(long x, long y, long mod){ long ans = 1; x = x % mod; if (x == 0) return 0; int i = 1; while (y > 0){ if ((y & 1) != 0) ans = (ans * x) % mod; y = y >> 1; x = (x * x) % mod; } return ans; } static boolean check(String a) { boolean hachu = true; for(int i = 0; i < a.length(); i++) { if(a.charAt(0) != a.charAt(i)) {hachu = false; break;} } return hachu; } public static class Pair implements Comparable<Pair> { public final int index; public final int value; public Pair(int index, int value) { this.index = index; this.value = value; } @Override public int compareTo(Pair other) { //multiplied to -1 as the author need descending sort order return -1 * Integer.valueOf(this.value).compareTo(other.value); } } static boolean equalString(int i, int j, int arr[], String b) { int brr[] = new int[26]; for(int k = i; k <= j; k++) brr[b.charAt(k) - 'a']++; for(int k = 0; k < 26; k++) { if(arr[k] != brr[k]) return false; } return true; } static boolean cequalArray(int arr[], int brr[], int a, int b) { int count[] = new int[101]; int count1[] = new int[101]; for(int i = a; i <= b; i++) count[arr[i]]++; for(int i = a; i <= b; i++) count1[brr[i]]++; for(int i = 0; i < 101; i++) if(count[i] != count1[i]) return false; return true; } public static void main(String[] args) throws Exception{ FastReader sc = new FastReader(); PrintWriter out = new PrintWriter(System.out); int t =sc.nextInt(); while(t-- > 0) { int n = sc.nextInt(); ArrayList<Integer> ss = new ArrayList<>(); int i = 2; int z = (int)Math.sqrt(n); while(true) { if(n % i == 0) { ss.add(i); n /= i; } i++; if(i > z) break; if(ss.size() == 2) break; } if(ss.size() == 2 && n != 1 && n != (int)ss.get(0) && n != (int)ss.get(1)) { out.println("YES"); out.println(ss.get(0) + " " + ss.get(1) + " " + n); } else out.println("NO"); } 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 sys sys.setrecursionlimit(10**9) IA =lambda: map(int,input().split()) ans=[0,0,0,0] def solve(n): num=int(0) i=int(2) tmp=1 m=n while i*i<=n: if n%i==0: n=n//i tmp*=i if tmp not in ans: num+=1 ans[num]=tmp tmp=1 if num>=3: ans[num]*=n return 1 i+=1 if n>1: if tmp*n not in ans: num+=1 ans[num]=n*tmp if num>=3: return 1 else:return -1 T=int(input()) for t in range(0,T): ans=[0,0,0,0] n=int(input()) if solve(n)==1: print("YES") for i in range(1,4): print(ans[i],end=" ") print() else:print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> const long long int MOD = 1e9 + 7; const int cfnum = 1e5 + 5; using namespace std; long long int gcd(long long int a, long long int b) { if (a == 0) return b; return gcd(b % a, a); } int main() { int q; cin >> q; while (q--) { long long int n; cin >> n; vector<long long int> ans; for (int i = 2; i < sqrt(n); i++) { if (n % i == 0) { if (ans.size() == 0) { ans.push_back(i); n /= i; } else { ans.push_back(i); ans.push_back(n / i); break; } } } if (ans.size() == 3) { cout << "YES" << "\n"; cout << ans[0] << " " << ans[1] << " " << ans[2] << "\n"; } else { cout << "NO" << "\n"; } } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { long long n, t, a, b, c, var; cin >> t; vector<long long> fact1, fact2, fact3; while (t--) { cin >> n; var = n; a = b = c = 1; fact1.clear(); fact2.clear(); fact3.clear(); for (int i = 2; i * i <= n; i++) { if (n % i == 0) { fact1.push_back(i); fact1.push_back(n / i); } } sort(fact1.begin(), fact1.end()); if (fact1.size() == 0) { cout << "NO\n"; continue; } n = n / fact1[0]; a = fact1[0]; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { fact2.push_back(i); fact2.push_back(n / i); } } fact2.push_back(n); sort(fact2.begin(), fact2.end()); for (int i = 0; i < fact2.size(); i++) { if (fact2[i] != a) { b = fact2[i]; break; } } c = var / (a * b); if (a != b && b != c && c != a && c != 1) { cout << "YES\n"; cout << a << ' ' << b << ' ' << c << '\n'; } else { cout << "NO\n"; } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int q, n; cin >> q; while (q--) { cin >> n; set<int> A; for (int i = 2; i * i < n; i++) { if (n % i == 0) { A.insert(i); n /= i; break; } } for (int i = 2; i * i < n; i++) { if (n % i == 0) { if (A.count(i)) continue; A.insert(i); n /= i; break; } } if (A.count(n) || n == 1 || A.size() < 2) { cout << "NO\n"; } else { cout << "YES\n"; A.insert(n); for (int a : A) cout << a << " "; cout << "\n"; } } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ # β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–„β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–„β–‘β–‘β–‘β–‘β–‘β–‘ # β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–‘β–„β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–€β–„β–‘β–‘β–ˆβ–‘β–‘β–‘β–‘β–‘ # β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–ˆβ–‘β–‘β–€β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–€β–‘β–‘β–ˆβ–‘β–ˆβ–‘β–‘β–‘β–‘β–‘ # β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–ˆβ–‘β–‘β–‘β–€β–‘β–‘β–‘β–‘β–‘β–‘β–€β–‘β–‘β–‘β–ˆβ–‘β–ˆβ–‘β–‘β–‘β–‘β–‘ # β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–ˆβ–‘β–‘β–‘β–‘β–€β–‘β–‘β–‘β–‘β–€β–‘β–‘β–‘β–‘β–ˆβ–‘β–ˆβ–‘β–‘β–‘β–‘β–‘ # β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–ˆβ–„β–‘β–‘β–‘β–‘β–€β–‘β–‘β–€β–‘β–‘β–‘β–‘β–„β–ˆβ–‘β–ˆβ–‘β–‘β–‘β–‘β–‘ # β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–ˆβ–‘β–‘β–‘β–‘β–‘ # β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–€β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–€β–‘β–ˆβ–‘β–‘β–‘β–‘β–‘ # β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–‘β–‘β–‘β–‘ # β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–ˆβ–‘β–‘β–‘β–‘β–‘ # β–‘β–‘β–‘β–‘β–‘β–‘β–€β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–€β–‘β–‘β–‘β–‘β–‘ # β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘ import math for i in range(int(input())): n = int(input()) l = [] p =math.sqrt(n) p = int(p) i=2 while len(l)<2 and i<p: if n%i==0: l.append(i) n=n//i i+=1 if len(l)==2 and n not in l: print("YES") print(*l,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 sys input = sys.stdin.readline # sys.setrecursionlimit(400000) def I(): return input().strip() def II(): return int(input().strip()) def LI(): return [*map(int, input().strip().split())] import copy, string, math, time, functools, random, fractions from heapq import heappush, heappop, heapify from bisect import bisect_left, bisect_right from collections import deque, defaultdict, Counter, OrderedDict # from itertools import permutations, combinations, groupby from operator import itemgetter import itertools for _ in range(II()): n = II() l = [] while(n%2==0): l.append(2) n = n//2 for i in range(3,int(math.sqrt(n))+1,2): while n%i == 0: l.append(i) n = n//i if n>2: l.append(n) p = len(set(l)) z = len(l) if p == 1: if z >= 6: print("YES") print(l[0],end = ' ') print(l[1]*l[2],end = ' ') print(l[0]**(z-3)) else: print("NO") elif p == 2: if z>=4: l.sort() y = 1 m = list(set(l)) v = m[0] k = m[1] l.remove(v) l.remove(k) print("YES") print(v,end = ' ') print(k,end = ' ') for i in range(len(l)): y = y*l[i] print(y) else: print("NO") elif p>2: print("YES") x=1 if z == 3: print(*l) else: l.sort() for i in range(3, z): x = x * l[i] print(x, l[0], l[1] * l[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
t = int(input()) for x in range(t): n = int(input()) i = 2 rt = int(n**0.5) l = [] dp = [True]*(int(n**0.5)+1) while i <= rt and len(l) < 3: if n%i!=0: i+=1 else: if dp[i]: l.append(i) dp[i] = False if len(l) == 2: if l[0] != n//i and i != n//i: l.append(n//i) n = n//i rt = int(n**0.5) i = 2 else: i += 1 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
import math def mul3(n): original_n = n divisors = set() divisor = 2 sqrt_n = int(math.sqrt(n)) while divisor <= sqrt_n and len(divisors) < 2: if n % divisor == 0: divisors.add(divisor) n //= divisor divisor += 1 if len(divisors) < 2: return None list_divisors = list(divisors) multiplication = list_divisors[0] * list_divisors[1] third_number = original_n // multiplication if third_number in divisors: return None return divisors | set([third_number]) # 24 -> 2, 3, 4 # 8 -> None # 7 -> None # 6 -> None # 13 * 17 * 19 -> 13, 17, 19 number_of_tests = int(input()) for _ in range(number_of_tests): n = int(input()) result = mul3(n) if not result: print('NO') continue print('YES') print(' '.join(map(str, result)))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math import collections import sys import math def primeFactors(n): l = [] count = 0 while n % 2 == 0: count+=1 n = n // 2 if count > 0: l.append([2, count]) count = 0 for i in range(3, int(math.sqrt(n))+1, 2): while n % i == 0: count+=1 n = n // i if count > 0: l.append([i, count]) count = 0 if n > 2: l.append([n, 1]) return l input = sys.stdin.readline for _ in range(int(input())): n = int(input()) l = primeFactors(n) if len(l) >= 3: print("YES") m1, m2, m3 = 1, 1, 1 m1 = l[0][0]**l[0][1] m2 = l[1][0]**l[1][1] for i in range(2, len(l)): m3*=l[i][0]**l[i][1] print(m1, m2, m3) else: if len(l) == 1: if l[0][1] >= 6: print("YES") print(l[0][0]**1, l[0][0]**2, l[0][0]**(l[0][1]-3)) else: print("NO") else: if l[0][1] + l[1][1] >= 4: print("YES") print(l[0][0], l[1][0], (l[0][0]**(l[0][1]-1))*(l[1][0]**(l[1][1]-1))) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for _ in range(int(input())) : n=int(input()) s=[] try: for i in range(2,int(math.sqrt(n))+1): if n%i==0: g=(n//i) a=i+0 break for i in range(a+1,int(math.sqrt(g))+1): if g%i==0: b=i break for i in range(2,int(math.sqrt(n))+1): if n%i==0: s.append(i) except: print("NO") continue if len(s)>=3: print("YES") print(a,b,n//(a*b)) 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 for _ in range(input()): n=input() flag=0 for i in range(2,int(n**(0.5))+1): if n%i==0: a=i s=n/i b=0 c=0 for j in range(2,int(s**(0.5)+1)): if s%j==0 and a!=j: b=j c=s/j if a!=b and b!=c and a!=c and a>=2 and b>=2 and c>=2: print "YES" arr= [a,b,c] arr.sort() for i in arr: print i, print flag=1 break if flag: break else: print "NO"
PYTHON
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math from bisect import bisect_left, bisect_right from sys import stdin, stdout input = lambda: stdin.readline().strip() print = lambda s: stdout.write(s) primes = [] def SieveOfEratosthenes(n): prime = [True for i in range(n+1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * p, n+1, p): prime[i] = False p += 1 for p in range(2, n): if prime[p]: primes.append(p) SieveOfEratosthenes(10**6) t = int(input()) for _ in range(t): n = int(input()) ls = [] for i in primes: if n%i==0: ls.append(i) if len(ls)==2: break if len(ls)==0: print('NO\n') elif len(ls)>=2: if n//(ls[0]*ls[1]) in ls or n//(ls[0]*ls[1])==1: print('NO\n') else: print('YES\n') print(str(ls[0])+' '+str(ls[1])+' '+str(n//(ls[0]*ls[1]))+'\n') elif n==ls[0] or n==ls[0]**2 or n==ls[0]**3 or n==ls[0]**4 or n==ls[0]**5: print('NO\n') else: copy = n cnt = 0 while copy%ls[0]==0: copy//=ls[0] cnt+=1 if cnt>=3: print('YES\n') print(str(ls[0])+' '+str(ls[0]**2)+' '+str(n//(ls[0]**3))+'\n') else: print('NO\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
N = int(input()) from math import * for _ in range(N): n = int(input()) sn = int(sqrt(n))+1 cnt = 0 ans = [] for i in range(2, sn): if n % i == 0: ans.append(i) n //= i cnt += 1 if cnt == 2: cnt = i break if n not in ans and len(ans) == 2: print("YES") print(' '.join(map(str, ans)), n) else: print("NO") """ TEST 1: 5 64 32 97 2 12345 === YES 2 4 8 NO NO NO YES 3 5 823 /// TEST 2: 2 98 196 === 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()) d=dict() i=2 while(i*i<=n): if i not in d and n%i==0: d[i]=i n//=i break i+=1 j=2 while(j*j<=n): if j not in d and n%j==0: d[j]=j n//=j break j+=1 if len(d)<2 or n in d or 1 in d: print('NO') else: print('YES') d[n]=1 print(" ".join(str(a) for a in d))
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 #2 2 2 3| 2 2 3 def fac(x): i=2 a = [] while i*i<=x: if x%i==0: a.append(i) x//=i else: i+=1 if x>1: a.append(x) return a def res(x): f = fac(x) if len(f)<=2 or len(set(f))==1 and len(f)<6 or len(set(f))==2 and len(f)<=3: print("NO") return 0 a = f[0] l = 1 r = len(f)-1 s = 1 for i in f[l:r+1]: s*=i b = s h = 31 c = 1 while h>0: if c!=1 and c!=a and c!=b: break else: c=int(c*(f[r])) b= int(b/(f[r])) r-=1 if l == r: break h-=1 print("YES") b, c = min(b,c),max(b,c) print(a,b,c) n = int(input()) while n>0: x = int(input()) res(x) n-=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
def prime_divisors(n): res = [] d = 2 while d * d <= n: if n % d == 0: if len(res) > 0 and res[-1][0] == d: res[-1][1] = res[-1][1] + 1 else: res.append([d, 1]) n = n // d else: d = d + 1 if n > 1: if len(res) > 0 and res[-1][0] == n: res[-1][1] = res[-1][1] + 1 else: res.append([n, 1]) return res t = int(input()) for i in range(t): a = int(input()) pds = prime_divisors(a) first_divisor = pds[0][0] if len(pds) >= 3: second_divisor = pds[1][0] ans = [first_divisor, second_divisor, a // (first_divisor * second_divisor)] print("YES") print(*ans) elif len(pds) == 1: if pds[0][1] <= 5: print("NO") else: print("YES") print(first_divisor, first_divisor * first_divisor, a // (first_divisor * first_divisor * first_divisor)) else: if pds[0][1] + pds[1][1] >= 4: second_divisor = pds[1][0] print("YES") print(first_divisor, second_divisor, a // (first_divisor * second_divisor)) 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()) a = 0 i, arr= 2, [] for i in range(2, int(n**0.5)+1): if len(arr) == 2: break if n%i == 0: n //= i arr.append(i) if len(arr) == 2 and n not in arr and n != 1: print("YES") print(arr[0], arr[1], n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t = int(input()) for _ in range(t): n = int(input()) d = [] temp = n while n % 2 == 0: d.append(2) n //= 2 for i in range(3, (int(math.sqrt(n)) + 1), 2): while n % i == 0: d.append(i) n //= i if n > 2: d.append(n) if len(d) < 3: print('NO') elif len(d) == 3 and (d[0] == d[1] or d[1] == d[2]): print('NO') else: # print(d) a = d[0] if d[1] == d[0]: b = d[1] * d[2] c = int(temp / (a * b)) else: b = d[1] c = int(temp / (a * b)) if a == b or a == c or b == c: 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
import java.io.*; import java.util.*; public class MyClass { public static void main(String args[]) { FastReader sc = new FastReader(); //For Fast IO //func f = new func(); //Call func for swap , permute, upper bound and for sort. int t = sc.nextInt(); while(t-->0){ long n = sc.nextLong(); TreeSet<Long> ts = new TreeSet<>(); long num=n; long curr=1; for(int i=2;i*i<=num;i++){ if(n%i==0){ while(n%i==0){ curr *= i; n /= i; if(!ts.contains(curr)){ ts.add(curr); curr=1; } if(ts.size()==2){ break; } } if(ts.size()==2){ break; } } } if(n>1){ ts.add(n); } if(ts.size()==3){ System.out.println("YES"); for(Long n1 : ts){System.out.print(n1+" ");} System.out.println(); } else{ System.out.println("NO"); } } } } 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; } } class func{ static ArrayList<String> al = new ArrayList<>(); public static void sort(long[] arr) { int n = arr.length, mid, h, s, l, i, j, k; long[] res = new long[n]; for (s = 1; s < n; s <<= 1) { for (l = 0; l < n - 1; l += (s << 1)) { h = Math.min(l + (s << 1) - 1, n - 1); mid = Math.min(l + s - 1, n - 1); i = l; j = mid + 1; k = l; while (i <= mid && j <= h) res[k++] = (arr[i] <= arr[j] ? arr[i++] : arr[j++]); while (i <= mid) res[k++] = arr[i++]; while (j <= h) res[k++] = arr[j++]; for (k = l; k <= h; k++) arr[k] = res[k]; } } } public static void permute(char a[] , int i , int n){ if(i==n-1){ String s = new String(a); al.add(s); // al stores all permutations of string. return; } for(int j=i;j<n;j++){ swap(a,i,j); permute(a,i+1,n); swap(a,i,j); } } public static void swap(char a[],int i, int j){ char temp = a[i]; a[i] = a[j]; a[j] = temp; } public static void swap(int a[],int i, int j){ int temp = a[i]; a[i] = a[j]; a[j] = temp; } //-It returns index of first element which is strictly greater than searched value. public static int upperBound(long[] array, int length, long value) { int low = 0; int high = length; while (low < high) { final int mid = (low + high) / 2; if (value >= array[mid]) { low = mid + 1; } else { high = mid; } } return low; } /*If searched element doesn't exist function returns index of first element which is bigger than searched value.<br> * -If searched element is bigger than any array element function returns first index after last element.<br> * -If searched element is lower than any array element function returns index of first element.<br> * -If there are many values equals searched value function returns first occurrence.<br>*/ public static int lowerBound(long[] array, int length, long value) { int low = 0; int high = length; while (low < high) { final int mid = (low + high) / 2; if (value <= array[mid]) { high = mid; } else { low = mid + 1; } } return low; } }
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.math.*; import java.io.*; import java.util.*; import java.awt.*; public class CP { public static void main(String[] args) throws Exception { new Solver().solve(); } } class Solver { final Helper hp; final int MAXN = 1000_006; final long MOD = (long) 1e9 + 7; Solver() { hp = new Helper(MOD, MAXN); hp.initIO(System.in, System.out); } void solve() throws Exception { int i, j, k; for (int tc = hp.nextInt(); tc > 0; --tc) { long N = hp.nextLong(); hp.println(factorise(N)); } hp.flush(); } String factorise(final long N) { Random rnd = new Random(); for (int t = 47; t > 0; --t) { long[] prod = new long[] {1, 1, 1}; long i, n = N; for (i = 2; i * i <= n; ++i) if (n % i == 0) { while (n % i == 0) { prod[rnd.nextInt(3)] *= i; n /= i; } } if (n > 1) prod[rnd.nextInt(3)] *= n; Arrays.sort(prod); if (hp.min(prod) > 1 && prod[0] < prod[1] && prod[1] < prod[2]) { return "YES\n" + hp.joinElements(prod); } } return "NO"; } } class Helper { final long MOD; final int MAXN; final Random rnd; public Helper(long mod, int maxn) { MOD = mod; MAXN = maxn; rnd = new Random(); } public static int[] sieve; public static ArrayList<Integer> primes; public void setSieve() { primes = new ArrayList<>(); sieve = new int[MAXN]; int i, j; for (i = 2; i < MAXN; ++i) if (sieve[i] == 0) { primes.add(i); for (j = i; j < MAXN; j += i) { sieve[j] = i; } } } public static long[] factorial; public void setFactorial() { factorial = new long[MAXN]; factorial[0] = 1; for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD; } public long getFactorial(int n) { if (factorial == null) setFactorial(); return factorial[n]; } public long ncr(int n, int r) { if (r > n) return 0; if (factorial == null) setFactorial(); long numerator = factorial[n]; long denominator = factorial[r] * factorial[n - r] % MOD; return numerator * pow(denominator, MOD - 2, MOD) % MOD; } public long[] getLongArray(int size) throws Exception { long[] ar = new long[size]; for (int i = 0; i < size; ++i) ar[i] = nextLong(); return ar; } public int[] getIntArray(int size) throws Exception { int[] ar = new int[size]; for (int i = 0; i < size; ++i) ar[i] = nextInt(); return ar; } public String[] getStringArray(int size) throws Exception { String[] ar = new String[size]; for (int i = 0; i < size; ++i) ar[i] = next(); return ar; } public String joinElements(long[] ar) { StringBuilder sb = new StringBuilder(); for (long itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public String joinElements(int[] ar) { StringBuilder sb = new StringBuilder(); for (int itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public String joinElements(String[] ar) { StringBuilder sb = new StringBuilder(); for (String itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public String joinElements(Object[] ar) { StringBuilder sb = new StringBuilder(); for (Object itr : ar) sb.append(itr).append(" "); return sb.toString().trim(); } public long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } public int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); } public long max(long[] ar) { long ret = ar[0]; for (long itr : ar) ret = Math.max(ret, itr); return ret; } public int max(int[] ar) { int ret = ar[0]; for (int itr : ar) ret = Math.max(ret, itr); return ret; } public long min(long[] ar) { long ret = ar[0]; for (long itr : ar) ret = Math.min(ret, itr); return ret; } public int min(int[] ar) { int ret = ar[0]; for (int itr : ar) ret = Math.min(ret, itr); return ret; } public long sum(long[] ar) { long sum = 0; for (long itr : ar) sum += itr; return sum; } public long sum(int[] ar) { long sum = 0; for (int itr : ar) sum += itr; return sum; } public void shuffle(int[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = rnd.nextInt(ar.length); if (r != i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public void shuffle(long[] ar) { int r; for (int i = 0; i < ar.length; ++i) { r = rnd.nextInt(ar.length); if (r != i) { ar[i] ^= ar[r]; ar[r] ^= ar[i]; ar[i] ^= ar[r]; } } } public long pow(long base, long exp, long MOD) { base %= MOD; long ret = 1; while (exp > 0) { if ((exp & 1) == 1) ret = ret * base % MOD; base = base * base % MOD; exp >>= 1; } return ret; } static byte[] buf = new byte[2048]; static int index, total; static InputStream in; static BufferedWriter bw; public void initIO(InputStream is, OutputStream os) { try { in = is; bw = new BufferedWriter(new OutputStreamWriter(os)); } catch (Exception e) { } } public void initIO(String inputFile, String outputFile) { try { in = new FileInputStream(inputFile); bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(outputFile))); } catch (Exception e) { } } private int scan() throws Exception { if (index >= total) { index = 0; total = in.read(buf); if (total <= 0) return -1; } return buf[index++]; } public String next() throws Exception { int c; for (c = scan(); c <= 32; c = scan()) ; StringBuilder sb = new StringBuilder(); for (; c > 32; c = scan()) sb.append((char) c); return sb.toString(); } public int nextInt() throws Exception { int c, val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') c = scan(); for (; c >= '0' && c <= '9'; c = scan()) val = (val << 3) + (val << 1) + (c & 15); return neg ? -val : val; } public long nextLong() throws Exception { int c; long val = 0; for (c = scan(); c <= 32; c = scan()) ; boolean neg = c == '-'; if (c == '-' || c == '+') c = scan(); for (; c >= '0' && c <= '9'; c = scan()) val = (val << 3) + (val << 1) + (c & 15); return neg ? -val : val; } public void print(Object a) throws Exception { bw.write(a.toString()); } public void printsp(Object a) throws Exception { print(a); print(" "); } public void println() throws Exception { bw.write("\n"); } public void println(Object a) throws Exception { print(a); println(); } public void flush() throws Exception { bw.flush(); } }
JAVA