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 | import java.util.ArrayList;
import java.util.Scanner;
public class C615
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Scanner obj=new Scanner(System.in);
int t=obj.nextInt();
while (t-->0)
{
int n=obj.nextInt();
int k=n;
int c=0;
ArrayList<Integer> arr=new ArrayList<>();
for(int i=2;i<=Math.sqrt(k);i++)
{
if(n%i==0)
{
n=n/i;
c++;
arr.add(i);
if(c==2)
{
break;
}
}
}
if(c>=2)
{
if(k%(arr.get(0)*arr.get(1))==0)
{
if(((k/(arr.get(0)*arr.get(1)))!=arr.get(0))&&(k/(arr.get(0)*arr.get(1)))!=arr.get(1))
{
System.out.println("YES");
System.out.println(arr.get(0)+" "+arr.get(1)+" "+(k/(arr.get(0)*arr.get(1))));
}
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 | # import sys
# sys.stdin=open("input1.in","r")
# sys.stdout=open("outpul.out","w")
for _ in range(int(input())):
N=int(input())
Factors=[]
FLAG=0
for i in range(2,int(pow(N,0.5))+1):
if N%i==0:
X=i
Z=N//i
for j in range(2,int(pow(Z,0.5))+1):
if Z%j==0:
X1=Z//j
if X1!=j and X1!=X and j!=X:
print("YES")
print(X1,j,X)
FLAG=1
break
if FLAG==1:
break
if FLAG==0:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | def prime(n):
if n<3:
return not n&1
res=True
i=2
while i*i<=n:
if n%i==0:
res=False
break
i+=1
return res
def sieve(n):
num=[ True ]*(n+1)
i=2
primes=[]
while i*i<n+1:
if num[i]:
j=i*i
while j<=n:
num[j]=False
j+=i
i+=1
for i in range(2,n+1):
if num[i]:
primes.append(i)
return primes
primes=sieve(10**6)
def factor(n,i=0):
if n==1:
return " "
if prime(n):
return str(n)+":"+"1"+" "
while primes[i]<=n:
if n%primes[i]==0:
l=0
while n%primes[i]==0:
n//=primes[i]
l+=1
return str(primes[i])+":"+str(l)+" "+factor(n,i+1)
i+=1
def main():
for _ in range(int(input())):
n=int(input())
s=factor(n)
s=s.split(" ")
s.pop(-1)
s.pop(-1)
s=[list(map(int,e.split(":"))) for e in s]
a=s[0][0]
s[0][1]-=1
if s[0][1]>=2:
b=s[0][0]**2
s[0][1]-=2
c=n//(a*b)
else:
try:
b=(s[0][0]**s[0][1])*s[1][0]
s[1][1]-=1
c=n//(a*b)
except:
b=s[0][0]**s[0][1]
c=1
res= a>1 and b>1 and c>1 and a!=b and b!=c and a!=c
if res:
print("YES")
print(a,b,c)
else:
print("NO")
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 | from functools import reduce
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value(): return tuple(map(int, input().split()))
def arr(): return [int(i) for i in input().split()]
def sarr(): return [int(i) for i in input()]
def starr(): return [str(x) for x in input().split()]
def inn(): return int(input())
def svalue(): return tuple(map(str, input().split()))
mo = 1000000007
# ----------------------------CODE------------------------------#
def factors(n): #return list
return list(set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
for _ in range(inn()):
n=inn()
res=factors(n)
res.sort()
res=res[1:len(res)-1]
#print(res)
if(len(res)>4):
flag=0
for i in range(len(res)-1):
for j in range(i+1,len(res)):
val=res[i]*res[j]
if(n%val==0):
flag=1
print("YES")
print(res[i],res[j],n//val)
break
if(flag==1):
break
if(flag==0):
print("NO")
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def solve(unique,arr):
if len(unique) >= 3 and len(arr) >= 3:
a,b = unique[0],unique[1]
c = n//(a*b)
return [a,b,c]
elif len(unique) == 1 and len(arr) >= 6:
a,b = unique[0],pow(unique[0], 2)
c = n // pow(a, 3)
return [a,b,c]
elif len(unique) == 2 and len(arr) >= 4:
a,b = unique[0],unique[1]
c = n // (a*b)
return [a,b,c]
else:
return "NO"
def sieve(n):
arr = []
while n%2 == 0:
arr.append(2)
n = n//2
for i in range(3, int(math.sqrt(n)) + 1, 2):
while (n%i == 0):
arr.append(i)
n = n//i
if n > 2:
arr.append(n)
return arr
for _ in range(int(input())):
n = int(input())
arr = sieve(n)
unique = list(set(arr))
f = solve(unique,arr)
if f=='NO':
print("NO")
else:
print("YES")
print(*f) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible 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 test in range(t):
n=int(input())
i=2
prev=n
fac=[]
while i*i <=n :
if n%i == 0:
n=n//i
fac.append(i)
prev=i
i+=1
if n > 1 :
fac.append(n)
while len(fac) > 3:
fac[2] = fac[2] * fac[3]
fac.pop(3)
#print(fac[1],fac[2])
if len(fac) < 3:
print('NO')
continue
if fac[1] == fac[2]:
print('NO')
else:
print('YES')
for j in range(len(fac)):
if j==len(fac)-1:
print(fac[j])
else:
print(fac[j],end=' ')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible 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 ProgEc {
public static void main(String[] args) throws Exception {
//FileInputStream inputStream = new FileInputStream("input.txt");
//FileOutputStream outputStream = new FileOutputStream("output.txt");
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Solver solver = new Solver();
solver.solve(1, in, out);
out.close();
}
static class Solver {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int t = in.nextInt();
for (int q = 0; q < t; q++) {
long n = in.nextLong();
int c = 0;
for (int i = 2; i <= 1000; i++) {
long m = n;
if (m % i != 0) continue; else m /= i;
for (int j = i+1; j <= 10000; j++) {
if (m % j == 0 && m/j != j && m/j != i && m/j != 1 && m/j != 0) {
out.println("YES");
out.println(i + " " + j + " " + (m/j));
c = 1;
break;
}
}
if (c == 1) break;
}
if (c == 0) out.println("NO");
}
}
/*class MyString implements Comparable<MyString> {
String str;
MyString(String other) {
str = other;
}
public int compareTo(MyString other) {
return str.length() - other.str.length();
}
}*/
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public float nextFloat() {
return Float.parseFloat(next());
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t=int(input())
for i in range(t):
a,b,c,j=1,1,1,0
flag=1
num = int(input())
for j in range(2,int((num)**0.5)):
if num%j==0:
a=j
#print(a)
break
num=num//a
for k in range(j+1,num+1):
if k >(num**0.5):
break
if num%k==0:
b=k
#print(b)
break
if(num%(b)==0 and b!=int(num/(b)) and a!=int(num/(b))):
c=int(num/(b))
#print(c)
flag=0
if a!=1 and b!=1 and c!=1:
print("YES")
print(("{0:} {1:} {2:}").format(a,b,c))
#print(a)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import sqrt
def calcul(x,message):
for j in range (2,int(sqrt(x))):
if x%j==0:
m=x/j
s=int(sqrt(m))
if j+1>s:
s=int(m/2)
for k in range (j+1,s+1):
if (m%k==0) and (int(m/k)!=k) and (int(m/k)!=j):
message="YES"
print(message)
print(j,' ',k,' ',int(m/k))
return -1
n = int(input())
for i in range (0,n):
x=(int(input()))
message="NO"
if calcul(x,message)!=-1:
print(message) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
int res = 0;
while (n && ++res) n -= n & (-n);
return res;
}
template <class T>
void chmax(T& a, const T& b) {
a = max(a, b);
}
template <class T>
void chmin(T& a, const T& b) {
a = min(a, b);
}
int main() {
long long t;
cin >> t;
while (t--) {
vector<long long> v;
long long n;
cin >> n;
long long a = 2;
int c = 0;
while (n >= 1 && a <= sqrt(n)) {
if (ceil(n / (a * 1.0)) == n / a) {
n = n / a;
v.push_back(a);
c++;
}
if (c == 2) {
break;
}
a++;
}
if (v.size() < 2) {
cout << "NO" << endl;
} else {
if (v[0] != n && v[1] != n) {
cout << "YES" << endl;
cout << v[0] << " " << v[1] << " " << n << endl;
} else {
cout << "NO" << endl;
}
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import floor, sqrt
try:
long
except NameError:
long = int
def fac(n):
step = lambda x: 1 + (x<<2) - ((x>>1)<<1)
maxq = long(floor(sqrt(n)))
d = 1
q = 2 if n % 2 == 0 else 3
while q <= maxq and n % q != 0:
q = step(d)
d += 1
return [q] + fac(n // q) if q <= maxq else [n]
for _ in range(int(input())):
n=int(input())
l=fac(n)
l.sort()
k=len(l)
if k>3:
if len(set([l[0],l[1]*l[2],n//(l[0]*l[1]*l[2])]))==3:
print("YES")
print(l[0],l[1]*l[2],n//(l[0]*l[1]*l[2]))
elif len(set([l[0],l[1]*l[-1],n//(l[0]*l[1]*l[-1])]))==3:
print("YES")
print(l[0],l[1]*l[-1],n//(l[0]*l[1]*l[-1]))
elif len(set([l[1],l[0]*l[2],n//(l[0]*l[1]*l[2])]))==3:
print("YES")
print(l[1],l[0]*l[2],n//(l[0]*l[1]*l[2]))
elif len(set([l[2],l[0]*l[1],n//(l[0]*l[1]*l[2])]))==3:
print("YES")
print(l[2],l[0]*l[1],n//(l[0]*l[1]*l[2]))
else:
print("NO")
elif k==3 and len(set(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 | for _ in range(int(input())):
n=int(input())
l=[]
if(n%2==0):
l.append(2)
for i in range(3,int(pow(n,0.5))+1):
if(n%i==0):
if(n//i==i):
l.append(i)
else:
l.append(i)
l.append(n//i)
flag=0
for i in range(0,len(l)):
for j in range(i+1,len(l)):
for k in range(j+1,len(l)):
if(l[i]*l[j]*l[k]==n):
flag=1
break
if(flag==1):
break
if(flag==1):
break
if(flag==1):
print("YES")
print(l[i],l[j],l[k])
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 | """
Author : Aman Thakur
mantra: chor kya hi kar sakte hai!!
"""
import math
class Solution:
def __init__(self):
self.c = 0
self.arr = []
# def solution(self):
# n = int(input())
#
# for i in range(2, int(math.sqrt(n)) + 1):
# if n % i == 0:
# self.arr.append(i)
# n //= i
# break
#
# for i in range(self.arr[0] + 1, int(math.sqrt(n)) + 1):
# if n % i == 0 and n // i not in self.arr and n // i > 1:
# self.arr.append(i)
# if i != n // i:
# self.arr.append(n // i)
# break
#
# if len(self.arr) == 3:
# print('YES')
# for i in self.arr:
# print(i, end=' ')
# print()
# else:
# print('NO')
def solution(self):
n = int(input())
for i in range(2, n):
if n % i == 0:
self.arr.append(i)
n //= i
if len(self.arr) == 2 or n < i*i:
break
if len(self.arr) == 2 and n != self.arr[0] and n != self.arr[1] and n > 1:
print('YES')
print(self.arr[0], self.arr[1], n)
else:
print('NO')
if __name__ == '__main__':
for _ in range(int(input())):
ob = Solution()
ob.solution()
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import sqrt, ceil
for _ in range(int(input())):
n = int(input())
ans = "YES"
out = [0, 0, 0]
for i in range(2, int(ceil(sqrt(n)))):
if n % i == 0:
n //= i
out[0] = i
break
else:
ans = "NO"
if ans == "YES":
for j in range(2, int(ceil(sqrt(n)))):
if j == out[0]: continue
if n % j == 0:
n //= j
if n == out[0]: continue
out[1], out[2] = j, n
break
else:
ans = "NO"
if ans == "NO":
print(ans)
else:
print(ans)
print(*out)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible 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.ArrayList;
import java.util.List;
import java.util.Scanner;
public class JavaApplication1 {
public static void main(String args[]) throws IOException {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
for (int i = 0; i < t; i++) {
int x = sc.nextInt();
List<Integer> list = new ArrayList();
int factor = 2;
for (int j = 2; j*j < x; j++) {
if (list.size()>=3) {
break;
}
if (x%factor ==0) {
if (!list.isEmpty()) {
list.add(x/factor);
}
list.add(factor);
x = x/ factor;
}
factor++;
}
if (list.size() < 3) {
System.out.println("NO");
}else
{
System.out.println("YES");
System.out.println(list.get(0)+" "+list.get(1)+" "+list.get(2));
}
}
}}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
tests = int(input())
prime = [1 for i in range(10**6)]
prime[0] = 0
prime[1] = 0
for i in range(2,10**6):
if(prime[i] == 1):
for j in range(i*i,10**6,i):
prime[j] = 0
#prime_list = []
for te in range(tests):
n = int(input())
count = 0
prime_list = []
for i in range(2,int(math.sqrt(n))+2):
if(prime[i] == 1):
while(n%i == 0):
n = n//i
prime_list.append(i)
count += 1
if(n>1):
count += 1
prime_list.append(n)
pro = [0 for i in range(len(prime_list))]
#print(len(prime_list))
#print(prime_list)
#print(len(pro))
pro[0] = prime_list[0]
flag = 0
for i in range(1,len(prime_list)):
pro[i] = pro[i-1]*prime_list[i]
#print(pro)
if(count > 2):
for i in range(len(prime_list)-2):
for j in range(i+1,len(prime_list)-1):
a = pro[i]
b = pro[j]//pro[i]
c = pro[len(prime_list)-1]//pro[j]
if(a!=b and b!=c and a!=c):
print('YES')
print(a,end = ' ')
print(b,end = ' ')
print(c,end = '\n')
flag = 1
break
if(flag == 1):
break
if(flag == 0):
print('NO')
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
map<string, long long int> m;
void solve() {
int n;
cin >> n;
int i;
set<int> s;
for (i = 2; i * i <= n; i++) {
if (n % i == 0 && !s.count(i)) {
s.insert(i);
n /= i;
break;
}
}
for (i = 2; i * i <= n; i++) {
if (n % i == 0 && !s.count(i)) {
s.insert(i);
n /= i;
break;
}
}
if (s.size() < 2 || n == 1 || s.count(n)) {
cout << "NO" << endl;
} else {
s.insert(n);
cout << "YES" << endl;
for (auto x : s) cout << x << " ";
cout << endl;
}
return;
}
int main() {
long long 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 io
import os
from collections import Counter, defaultdict, deque
def solve(N, ):
ans = []
while len(ans) < 2:
for i in range(ans[-1] + 1 if ans else 2, int(N**0.5) + 1):
if N % i == 0:
ans.append(i)
N //= i
break
else:
return 'NO'
if len(ans) != 2:
return 'NO'
if N <= ans[-1]:
return 'NO'
ans.append(N)
return 'YES\n' + ' '.join(map(str, ans))
if __name__ == "__main__":
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
N, = [int(x) for x in input().split()]
ans = solve(N, )
print(ans)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | def product(n):
a = int(min_divisor(2,n))
if a==n:
return False
else:
b = int(min_divisor(a+1,n/a))
if b==a or b==1:
return False
else:
c = int(n/(a*b))
if c==a or c == b or c==1:
return False
else:
return (a, b, c)
def min_divisor(s,n):
for i in range(s,int(n**0.5)+1):
if n % i == 0:
return i
else:
return n
t = int(input())
for i in range(t):
n = int(input())
ans = product(n)
if ans:
print("YES")
print(*list(ans))
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def sovle():
n = int(input())
a = []
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
a.append(i)
n //= i
if len(a) == 2:
break
if len(a) == 2 and n not in a:
print('YES')
print(a[0], a[1], n)
else:
print('NO')
def main():
for i in range(int(input())):
sovle()
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 | for _ in range(int(input())):
n=int(input())
nd=n
count2=0
ar=[]
flag=True
spcount=0
while(n%2==0):
spcount+=1
n//=2
if(spcount<3 and spcount>=1):
count2+=1
ar.append(2)
elif(spcount<6 and spcount>=1):
count2+=2
ar.append(2)
ar.append(4)
elif(spcount>=6 and spcount>=1):
print('YES')
flag=False
print(2,4,nd//8)
if(flag):
for i in range(3,int(nd**(1/2))+1,2):
if(n%i==0):
n//=i
count2+=1
ar.append(i)
if(count2>=2):
le=nd//(ar[0]*ar[1])
if(count2>=2 and le!=ar[0] and le!=ar[1]):
flag=False
print('YES')
print(ar[0],ar[1],nd//(ar[0]*ar[1]))
break
if(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 | #!/usr/bin/env python
from __future__ import division, print_function
import os
import sys
from collections import Counter
from io import BytesIO, IOBase
from math import gcd
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def memodict(f):
"""memoization decorator for a function taking a single argument"""
class memodict(dict):
def __missing__(self, key):
ret = self[key] = f(key)
return ret
return memodict().__getitem__
def pollard_rho(n):
"""returns a random factor of n"""
if n & 1 == 0:
return 2
if n % 3 == 0:
return 3
s = ((n - 1) & (1 - n)).bit_length() - 1
d = n >> s
for a in [2, 325, 9375, 28178, 450775, 9780504, 1795265022]:
p = pow(a, d, n)
if p == 1 or p == n - 1 or a % n == 0:
continue
for _ in range(s):
prev = p
p = (p * p) % n
if p == 1:
return gcd(prev - 1, n)
if p == n - 1:
break
else:
for i in range(2, n):
x, y = i, (i * i + 1) % n
f = gcd(abs(x - y), n)
while f == 1:
x, y = (x * x + 1) % n, (y * y + 1) % n
y = (y * y + 1) % n
f = gcd(abs(x - y), n)
if f != n:
return f
return n
@memodict
def prime_factors(n):
"""returns a Counter of the prime factorization of n"""
if n <= 1:
return Counter()
f = pollard_rho(n)
return Counter([n]) if f == n else prime_factors(f) + prime_factors(n // f)
def main():
t = int(input())
for _ in range(t):
n = int(input())
f = prime_factors(n)
s = [-1, -1, -1]
for v, c in f.items():
if s[1] != -1:
break
if c > 2 and s[0] == -1:
s[0] = v
s[1] = v * v
elif s[0] == -1:
s[0] = v
elif s[1] == -1:
s[1] = v
a, b, c = s[0], s[1], n // (s[0] * s[1])
if a > 1 and b > 1 and c > 1 and a != c and b != c:
print("YES")
print(a, b, c)
else:
print("NO")
# region fastio
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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
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 | for _ in range(int(input())):
n=int(input())
k,j=2,0
a=[]
while(j<2 and k*k<n):
if(n%k==0):
a.append(k)
n=n//k
j+=1
k+=1
if(j!=2):
print("NO")
elif(a[1]!=n):
print("YES")
a.append(n)
print(*a)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t = int(input())
def solve(n):
f = []
while (n % 2 == 0):
f.append(2)
n = n / 2
R = int(math.sqrt(n))
for e in range(3, R + 1, 2):
while (n % e == 0):
f.append(e)
n = n / e
if n != 1.0:
f.append(int(n))
return f
while t > 0:
t -= 1
n = int(input())
factors = solve(n)
# print(factors)
if len(factors) <= 2:
print("NO")
else:
factors.sort()
a = factors[0]
pos = 1
b = 1
while b <= a:
b = b * factors[pos]
pos += 1
# print(a, b, pos)
c = 1
if pos == (len(factors)):
print("NO")
continue
for e in range(pos, len(factors)):
c = c * factors[e]
if a != b and b != c and a != c:
print("YES")
print("{} {} {}".format(a, b, c))
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, k = 2, a[3], q, c = 0;
cin >> n;
for (long long i = 2; i * i < n && c < 2; i++) {
if (n % i == 0) {
a[c++] = i;
n = n / i;
}
}
if (c != 2)
cout << "NO" << endl;
else {
cout << "YES" << endl;
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 | from math import sqrt
t = int(input())
for j in range(t):
n = int(input())
m = 0
bul_1 = False
bul_2 = False
i = 2
while i <= int(sqrt(n)):
if n % i == 0:
if bul_1:
bul_2 = True
if i != n // i:
print("YES")
print(m, i, n // i)
else:
print("NO")
break
else:
m = i
bul_1 = True
n //= i
i += 1
if not bul_2:
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 functools import reduce
def factors(n):
return sorted(list(set(reduce(list.__add__,
([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))))
for _ in range(int(input())):
N = int(input())
r = factors(N)
len_r = len(r)
tmp = 0
if len_r - 2 < 3:
print("NO")
continue
for i in range(1, len_r - 1):
curr_sum = N // r[i]
for j in range(i + 1, len_r - 1):
if (curr_sum // r[j]) in r:
s = {r[i], r[j], curr_sum // r[j]}
if len(s) == 3 and 1 not in s:
print("YES")
print(r[i], r[j], curr_sum // r[j])
tmp = 1
break
if tmp:
break
if not tmp:
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())
original=n
a=set()
i=2
a2=0
b2=0
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
a.add(i)
n//=i
a2=i
break
for i in range(2,int(math.sqrt(n))+1):
if n%i==0 and i!=a2:
a.add(i)
n//=i
b2=i
break
if len(a)==2:
if n*a2*b2==original and n!=a2 and n!=b2:
print("YES")
print(n,a2,b2)
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 | def getSmallestFactor(n,d):
for i in range(2,int(n**0.5)+1):
if i not in d and n%i==0:
return i
return -1
t = int(input())
for _ in range(t):
n = int(input())
sm1 = getSmallestFactor(n,{})
if sm1!=-1:
sm2 = getSmallestFactor(n//sm1,{sm1})
sm3 = n//(sm1*sm2)
if sm2!=-1 and sm3 not in [sm1,sm2,1]:
print('YES')
print(sm1,sm2,sm3)
else:
print('NO')
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def countDivisors(n) :
cnt = 0
for i in range(1, (int)(math.sqrt(n)) + 1) :
if (n % i == 0) :
# If divisors are equal,
# count only one
if (n / i == i) :
cnt = cnt + 1
else : # Otherwise count both
cnt = cnt + 2
return cnt
t=int(input())
for i in range(t):
n=int(input())
x=0
w=1
for j in range(2,int(math.sqrt(n))+1):
if(n%j==0):
r=countDivisors(n//j)
if(r>3):
for k in range(2,int(math.sqrt(n//j))+1):
if((n//j)%k==0 and j!=k and k!=(n//j)//k and j!=(n//j)//k):
print("YES")
print(j,k,(n//j)//k)
w=0
if(w==0):
break
if(w==0):
break
if(w==1):
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Maij
{
public static void main(String[] args)
{
new Thread(null, new Runnable() {
public void run() {
solve();
}
}, "1", 1 << 26).start();
}
static void solve () {
FastReader fr =new FastReader(); PrintWriter op =new PrintWriter(System.out);
int t =fr.nextInt() ,n ,fct[][] ,i ,j ,k ;
while (t-- > 0) {
n =fr.nextInt() ; fct =new int[(int)1e5+5][2] ; j =-1 ;
if (n%2 == 0) {
fct[++j][0] =2 ; k =0 ;
while (n%2 ==0 ) { n/=2 ; ++k ; }
fct[j][1] =k ;
}
for (i =3 ; i*i<=n ; i+=2) {
if (n%i == 0) {
fct[++j][0] =i ; k =0 ;
while (n%i ==0 ) { n/=i ; ++k ; }
fct[j][1] =k ;
}
}
if (n>2) {
fct[++j][0] =n ; fct[j][1] =1 ;
}
if (j>=2) {
op.println("YES") ;
op.print((int)Math.pow(fct[0][0],fct[0][1])+" ") ;
op.print((int)Math.pow(fct[1][0],fct[1][1])+" ") ;
i =1 ;
for (k =2 ; k<=j ; ++k) i *= (int)Math.pow(fct[k][0],fct[k][1]) ;
op.print(i+" ") ; op.println() ;
}
else {
if (j==1) {
if (fct[1][1]>fct[0][1]) {
fct[1][1] ^= fct[0][1] ; fct[0][1] ^= fct[1][1] ; fct[1][1] ^= fct[0][1] ;
fct[1][0] ^= fct[0][0] ; fct[0][0] ^= fct[1][0] ; fct[1][0] ^= fct[0][0] ;
}
if (fct[1][1]+fct[0][1] > 3) {
op.println("YES") ;
i =(int)Math.pow(fct[0][0],1) ;
j =(int)Math.pow(fct[1][0],1) ;
k =(int)Math.pow(fct[0][0],--fct[0][1]) * (int)Math.pow(fct[1][0] , --fct[1][1]) ;
op.println(i+" "+j+" "+k) ;
}
else op.println("NO") ;
}
else {
if (fct[0][1]>5) {
op.println("YES") ;
i =(int)Math.pow(fct[0][0] , 1) ; --fct[0][1] ;
j =(int)Math.pow(fct[0][0] , 2) ; fct[0][1] -= 2 ;
k =(int)Math.pow(fct[0][0] , fct[0][1]) ;
op.println(i+" "+j+" "+k) ;
}
else op.println("NO") ;
}
}
}
op.flush(); op.close();
}
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();
}
String nextLine() {
String str ="";
try
{
str =br.readLine();
}
catch(IOException e)
{
e.printStackTrace();
}
return str;
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next()) ;
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t=int(input())
for q in range(t):
n=int(input())
i1=1
j1=1
k1=1
q=int(n**0.5)
for i in range(2,q):
if n%i==0:
i1=i
break
if i1!=1:
n=n//i1
for j in range(i1+1,q):
if n%j==0:
j1=j
break
if j1!=1:
n=n//j1
if n>j1 and n>i1 :
print("YES")
print(i1,j1,n)
else:
print("NO")
else:
print("NO")
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
int main() {
int t, n, m, s, s1, i, j, p;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
s = pow(n, 1.0 / 3);
p = 0;
for (i = 2; i <= s + 1; i++) {
if (n % i != 0) continue;
m = n / i;
s1 = sqrt(m);
for (j = i + 1; j <= s1; j++)
if (m % j == 0 && j != m / j) {
printf("YES\n");
printf("%d %d %d\n", i, j, m / j);
p = 1;
break;
}
if (p == 1) break;
}
if (p == 0) printf("NO\n");
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t = int(input())
for i in range(t):
n = int(input())
l = [0, 0, 0]
tmp = 0
m = n
i = 2
while i**2 <= m and tmp < 2:
if n % i == 0:
n //= i
l[tmp] = i
tmp += 1
i += 1
#print(l)
if tmp == 2 and n > l[1]:
print("YES")
l[2] = n
print(*l)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 |
import bisect
from itertools import accumulate
import os
import sys
import math
from decimal import *
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)
def input(): return sys.stdin.readline().rstrip("\r\n")
def factors(n):
fac=[]
while(n%2==0):
fac.append(2)
n=n//2
for i in range(3,int(math.sqrt(n))+2):
while(n%i==0):
fac.append(i)
n=n//i
if n>1:
fac.append(n)
return fac
# ------------------- fast io --------------------]]
for _ in range(int(input())):
n=int(input())
fac=factors(n)
if len(fac)<3:
print("NO")
else:
if len(fac)==3 and len(set(fac))==3:
print("YES")
print(*fac)
elif len(fac)==3 and len(set(fac))<3:
print("NO")
elif len(set(fac))>=3:
print("YES")
ans=[fac[0],fac[-1]]
c=1
for i in range(1,len(fac)-1):
c=c*fac[i]
ans.append(c)
print(*ans)
elif len(set(fac))==1:
if len(fac)>=6:
print("YES")
ans=[fac[0],fac[-1]*fac[-2]]
c=1
for i in range(1,len(fac)-2):
c=c*fac[i]
ans.append(c)
print(*ans)
else:
print("NO")
elif len(set(fac))==2:
print("YES")
ans=[fac[0],fac[-1]]
c=1
for i in range(1,len(fac)-1):
c=c*fac[i]
ans.append(c)
print(*ans)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | # cook your dish here
t = int(input())
while t>0:
t -= 1
n = int(input())
cuben = int(n**(1.0/3))
a,b,c = 0,0,0
ispossible = False
for i in range(2,cuben+1):
if n%i==0:
num = int(n/i)
sqn = int(num**(1.0/2))
for j in range(i+1,sqn+1):
if num%j==0:
k = int(num/j)
if not j==k:
a=i
b=j
c=k
ispossible = True
break
if ispossible:
break
if ispossible:
print("YES\n"+str(a)+" "+str(b)+" "+str(c))
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
import java.util.Collections;
public class S96{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while(t-->0){
int n=sc.nextInt();
if(isprime(n)==true){
System.out.println("NO");
}
else{
ArrayList<Integer> al=new ArrayList<>();
int ans=0;int ti=0;
for(int i=2;i*i<=n;i++){
if(n%i==0){
ans=i;
ti=n/ans;
al.add(ans);
break;
}
}
int an=0;
for(int i=2;i*i<=ti;i++){
if(ti%i==0 && i!=ans){
an=i;
al.add(an);
break;
}
}
if(an>1){
if(!al.contains(ti/an) && an>1){
al.add(ti/an);
}
}
if(al.size()==3){
System.out.println("YES");
System.out.println(ti/an+" "+ans+" "+an);
}
else{
System.out.println("NO");
}
}
}
}
static boolean isprime(int n){
for(int i=2;i*i<=n;i++){
if(n%i==0){
return false;
}
}
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 | import math as m
n = int(input())
for _ in range(n):
a = int(input())
v=[]
for i in range(2,int(m.sqrt(a))+1):
if a%i==0 and i!=a//i:
z = a//i
for j in range(i+1,int(m.sqrt(z))+1):
if z%j==0 and j!=z//j:
a = 0
v.append([i,j,z//j])
break
if a==0:
break
if a==0:
print("YES")
for i in v:
print(*i)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t=int(input())
for i in range(t):
n=int(input())
arr=[]
i=2
while len(arr)<2 and i*i<=n:
if n%i==0:
arr.append(i)
n=n//i
i+=1
if n not in arr and len(arr)==2:
print("YES")
print(*arr,end=" ")
print(n)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t = int(input())
def fd(n):
a = []
for i in range(2, 1+int(n**0.5)):
if n%i == 0:
a.append(i)
a.append(n//i)
return list(set(a))
for _ in range(t):
n = int(input())
found = False
d = fd(n)
for i in d:
tt = fd(n//i)
if len(tt) > 1 and tt[0] != tt[-1] and tt[0] != i and tt[-1] != i and tt[0]*tt[-1]*i == n:
print("YES")
print(tt[0],tt[-1],i)
found = True
break
if not found:
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 collections import deque
import sys
def inp():
return sys.stdin.readline().strip()
for _ in range(int(inp())):
n=int(inp())
i=2
fac=set()
while i*i<=n:
if n%i==0:
x=n//i
fac.add(i)
fac.add(x)
i+=1
fac=sorted(fac)
if len(fac)<3:
print('NO')
continue
f=False
for i in range(len(fac)):
for j in range(i+1,len(fac)):
x=fac[i]
y=fac[j]
z=n//(x*y)
if x!=y and y!=z and z>=2 and x!=z and x*y*z==n:
f=True
break
if f:
break
if f:
print('YES')
print(x,y,z)
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for _ in range(int(input())):
n=int(input())
a=[]
i=2
while i*i<=n:
if n%i==0:
a.append(i)
if n//i!=i:a.append(n//i)
i+=1
flag=0
for i in range(len(a)):
for j in range(i+1,len(a)):
for k in range(j+1,len(a)):
if a[i]*a[j]*a[k]==n and len(set([a[i],a[j],a[k]]))==3:
print("YES")
print(str(a[i])+" "+str(a[j])+" "+str(a[k]))
flag=1;break
if flag:break
if flag:break
if flag==0:print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import javax.print.attribute.standard.PrinterMessageFromOperator;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
new Main().run();}
static int groups = 0;
static int[] fa;
static int[] sz;
static void init1(int n) {
groups = n;
fa = new int[n];
for (int i = 1; i < n; ++i) {
fa[i] = i;
}
sz = new int[n];
Arrays.fill(sz, 1);
}
static int root(int p) {
while (p != fa[p]) {
fa[p] = fa[fa[p]];
p = fa[p];
}
return p;
}
static void combine(int p, int q) {
int i = root(p);
int j = root(q);
if (i == j) {
return;
}
if (sz[i] < sz[j]) {
fa[i] = j;
sz[j] += sz[i];
} else {
fa[j] = i;
sz[i] += sz[j];
}
groups--;
}
public static String roundS(double result, int scale){
String fmt = String.format("%%.%df", scale);
return String.format(fmt, result);
}
int[] unique(int a[]){
int p = 1;
for(int i=1;i<a.length;++i){
if(a[i]!=a[i-1]){
a[p++] = a[i];
}
}
return Arrays.copyOf(a,p);
}
public static int eq_bigger(int[] a, int key) {
return eq_bigger(a,0,a.length,key);
}
public static int eq_bigger(int[] a, int lo, int hi,
int key) {
while (lo < hi) {
int mid = (lo + hi) >>> 1;
if (a[mid] < key) {
lo = mid + 1;
}else {
hi = mid;
}
}
return lo;
}
public static int bigger(int[] a, int key) {
return bigger(a,0,a.length,key);
}
public static int bigger(int[] a, int lo, int hi,
int key) {
while (lo < hi) {
int mid = (lo + hi) >>> 1;
if (a[mid] > key) {
hi = mid;
}else {
lo = mid+1;
}
}
return lo;
}
void solve() {
//N , M , K , a , b , c , d . 其中N , M是矩阵的行列数;K 是上锁的房间数目,(a, b)是起始位置,(c, d)是出口位置
// int n = ni();
// int m = ni();
// int k = ni();
// int a = ni();
// int b = ni();
// int c = ni();
// int d = ni();
//
//
// char cc[][] = nm(n,m);
// char keys[][] = new char[n][m];
//
// char ky = 'a';
// for(int i=0;i<k;++i){
// int x = ni();
// int y = ni();
// keys[x][y] = ky;
// ky++;
// }
// int f1[] = {a,b,0};
//
// int dd[][] = {{0,1},{0,-1},{1,0},{-1,0}};
//
// Queue<int[]> q = new LinkedList<>();
// q.offer(f1);
// int ts = 1;
//
// boolean vis[][][] = new boolean[n][m][33];
//
// while(q.size()>0){
// int sz = q.size();
// while(sz-->0) {
// int cur[] = q.poll();
// vis[cur[0]][cur[1]][cur[2]] = true;
//
// int x = cur[0];
// int y = cur[1];
//
// for (int u[] : dd) {
// int lx = x + u[0];
// int ly = y + u[1];
// if (lx >= 0 && ly >= 0 && lx < n && ly < m && (cc[lx][ly] != '#')&&!vis[lx][ly][cur[2]]){
// char ck =cc[lx][ly];
// if(ck=='.'){
// if(lx==c&&ly==d){
// println(ts); return;
// }
// if(keys[lx][ly]>='a'&&keys[lx][ly]<='z') {
// int cao = cur[2] | (1 << (keys[lx][ly] - 'a'));
// q.offer(new int[]{lx, ly, cao});
// vis[lx][ly][cao] = true;
// }else {
//
// q.offer(new int[]{lx, ly, cur[2]});
// }
//
// }else if(ck>='A'&&ck<='Z'){
// int g = 1<<(ck-'A');
// if((g&cur[2])>0){
// if(lx==c&&ly==d){
// println(ts); return;
// }
// if(keys[lx][ly]>='a'&&keys[lx][ly]<='z') {
//
// int cao = cur[2] | (1 << (keys[lx][ly] - 'a'));
// q.offer(new int[]{lx, ly, cao});
// vis[lx][ly][cao] = true;;
// }else {
//
// q.offer(new int[]{lx, ly, cur[2]});
// }
// }
// }
// }
// }
//
// }
// ts++;
// }
// println(-1);
// int n = ni();
//
// HashSet<String> st = new HashSet<>();
// HashMap<String,Integer> mp = new HashMap<>();
//
//
// for(int i=0;i<n;++i){
// String s = ns();
// int id= 1;
// if(mp.containsKey(s)){
// int u = mp.get(s);
// id = u;
//
// }
//
// if(st.contains(s)) {
//
// while (true) {
// String ts = s + id;
// if (!st.contains(ts)) {
// s = ts;
// break;
// }
// id++;
// }
// mp.put(s,id+1);
// }else{
// mp.put(s,1);
// }
// println(s);
// st.add(s);
//
// }
// int t = ni();
//
// for(int i=0;i<t;++i){
// int n = ni();
// long w[] = nal(n);
//
// Map<Long,Long> mp = new HashMap<>();
// PriorityQueue<long[]> q =new PriorityQueue<>((xx,xy)->{return Long.compare(xx[0],xy[0]);});
//
// for(int j=0;j<n;++j){
// q.offer(new long[]{w[j],0});
// mp.put(w[j],mp.getOrDefault(w[j],0L)+1L);
// }
//
// while(q.size()>=2){
// long f[] = q.poll();
// long y1 = f[1];
// if(y1==0){
// y1 = mp.get(f[0]);
// if(y1==1){
// mp.remove(f[0]);
// }else{
// mp.put(f[0],y1-1);
// }
// }
// long g[] = q.poll();
// long y2 = g[1];
// if(y2==0){
// y2 = mp.get(g[0]);
// if(y2==1){
// mp.remove(g[0]);
// }else{
// mp.put(g[0],y2-1);
// }
// }
// q.offer(new long[]{f[0]+g[0],2L*y1*y2});
//
// }
// long r[] = q.poll();
// println(r[1]);
//
//
//
//
// }
// int o= 9*8*7*6;
// println(o);
// int t = ni();
// for(int i=0;i<t;++i){
// long a = nl();
// int k = ni();
// if(k==1){
// println(a);
// continue;
// }
//
// int f = (int)(a%10L);
// int s = 1;
// int j = 0;
// for(;j<30;j+=2){
// int u = f-j;
// if(u<0){
// u = 10+u;
// }
// s = u*s;
// s = s%10;
// if(s==k){
// break;
// }
// }
//
// if(s==k) {
// println(a - j - 2);
// }else{
// println(-1);
// }
//
//
//
//
// }
// int m = ni();
// h = new int[n];
// to = new int[2*(n-1)];
// ne = new int[2*(n-1)];
// wt = new int[2*(n-1)];
//
// for(int i=0;i<n-1;++i){
// int u = ni()-1;
// int v = ni()-1;
//
// }
// long a[] = nal(n);
// int n = ni();
// int k = ni();
// t1 = new long[200002];
//
// int p[][] = new int[n][3];
//
// for(int i=0;i<n;++i){
// p[i][0] = ni();
// p[i][1] = ni();
// p[i][2] = i+1;
// }
// Arrays.sort(p, new Comparator<int[]>() {
// @Override
// public int compare(int[] x, int[] y) {
// if(x[1]!=y[1]){
// return Integer.compare(x[1],y[1]);
// }
// return Integer.compare(y[0], x[0]);
// }
// });
//
// for(int i=0;i<n;++i){
// int ck = p[i][0];
//
// }
int t = ni();
ot: for(int i=0;i<t;++i){
int n = ni();
boolean ok = false;
for(int j=2;j*j<=n;++j){
if(n%j==0){
int bg = n/j;
for(int k=2;k*k<=j;++k){
if(j%k==0&&k!=j/k){
println("YES");
println(bg+" "+k+" "+j/k);continue ot;
}
}
for(int k=2;k<j&&k*k<=bg;++k){
if(bg%k==0&&k!=bg/k&&bg/k<j){
println("YES");
println(j+" "+k+" "+bg/k);continue ot;
}
}
}
}
println("NO");
}
}
int cnt[][];
long dp[][];
int h[];
int to[];
int ne[];
int ct = 0;
int x[][];
void dfs(int rt, int fa, int cur){
x[rt][cur] = fa;
cnt[rt][cur] = 1;
for(int i=h[cur];i!=-1;i=ne[i]){
int go = to[i];
if(go==fa) continue;
dfs(rt, cur, go);
cnt[rt][cur] += cnt[rt][go];
}
}
// int []h,to,ne,wt;
long t1[];
// long t2[];
void update(long[] t,int i,long v){
for(;i<t.length;i+=(i&-i)){
t[i] += v;
}
}
long get(long[] t,int i){
long s = 0;
for(;i>0;i-=(i&-i)){
s += t[i];
}
return s;
}
int equal_bigger(long t[],long v){
int s=0,p=0;
for(int i=Integer.numberOfTrailingZeros(Integer.highestOneBit(t.length));i>=0;--i) {
if(p+(1<<i)< t.length && s + t[p+(1<<i)] < v){
v -= t[p+(1<<i)];
p |= 1<<i;
}
}
return p+1;
}
static class S{
int l = 0;
int r = 0 ;
long le = 0;
long ri = 0;
long tot = 0;
long all = 0;
public S(int l,int r) {
this.l = l;
this.r = r;
}
}
static S a[];
static int[] o;
static void init(int[] f){
o = f;
int len = o.length;
a = new S[len*4];
build(1,0,len-1);
}
static void build(int num,int l,int r){
S cur = new S(l,r);
if(l==r){
a[num] = cur;
return;
}else{
int m = (l+r)>>1;
int le = num<<1;
int ri = le|1;
build(le, l,m);
build(ri, m+1,r);
a[num] = cur;
pushup(num, le, ri);
}
}
// static int query(int num,int l,int r){
//
// if(a[num].l>=l&&a[num].r<=r){
// return a[num].tot;
// }else{
// int m = (a[num].l+a[num].r)>>1;
// int le = num<<1;
// int ri = le|1;
// pushdown(num, le, ri);
// int ma = 1;
// int mi = 100000001;
// if(l<=m) {
// int r1 = query(le, l, r);
// ma = ma*r1;
//
// }
// if(r>m){
// int r2 = query(ri, l, r);
// ma = ma*r2;
// }
// return ma;
// }
// }
static long dd = 10007;
static void update(int num,int l,long v){
if(a[num].l==a[num].r){
a[num].le = v%dd;
a[num].ri = v%dd;
a[num].all = v%dd;
a[num].tot = v%dd;
}else{
int m = (a[num].l+a[num].r)>>1;
int le = num<<1;
int ri = le|1;
pushdown(num, le, ri);
if(l<=m){
update(le,l,v);
}
if(l>m){
update(ri,l,v);
}
pushup(num,le,ri);
}
}
static void pushup(int num,int le,int ri){
a[num].all = (a[le].all*a[ri].all)%dd;
a[num].le = (a[le].le + a[le].all*a[ri].le)%dd;
a[num].ri = (a[ri].ri + a[ri].all*a[le].ri)%dd;
a[num].tot = (a[le].tot + a[ri].tot + a[le].ri*a[ri].le)%dd;
//a[num].res[1] = Math.min(a[le].res[1],a[ri].res[1]);
}
static void pushdown(int num,int le,int ri){
}
int gcd(int a,int b){ return b==0?a: gcd(b,a%b);}
InputStream is;PrintWriter out;
void run() throws Exception {is = System.in;out = new PrintWriter(System.out);solve();out.flush();}
private byte[] inbuf = new byte[2];
public int lenbuf = 0, ptrbuf = 0;
private int readByte() {
if (lenbuf == -1) throw new InputMismatchException();
if (ptrbuf >= lenbuf) {
ptrbuf = 0;
try {lenbuf = is.read(inbuf);} catch (IOException e) {throw new InputMismatchException();}
if (lenbuf <= 0) return -1;
}
return inbuf[ptrbuf++];}
private boolean isSpaceChar(int c) {return !(c >= 33 && c <= 126);}
private int skip() {int b;while((b = readByte()) != -1 && isSpaceChar(b));return b;}
private double nd() {return Double.parseDouble(ns());}
private char nc() {return (char) skip();}
private char ncc() {int b;while((b = readByte()) != -1 && !(b >= 32 && b <= 126));return (char)b;}
private String ns() {int b = skip();StringBuilder sb = new StringBuilder();
while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);b = readByte(); }
return sb.toString();}
private char[] ns(int n) {char[] buf = new char[n];int b = skip(), p = 0;
while (p < n && !(isSpaceChar(b))) { buf[p++] = (char) b;b = readByte(); }
return n == p ? buf : Arrays.copyOf(buf, p);}
private String nline() {int b = skip();StringBuilder sb = new StringBuilder();
while (!isSpaceChar(b) || b == ' ') { sb.appendCodePoint(b);b = readByte(); }
return sb.toString();}
private char[][] nm(int n, int m) {char[][] a = new char[n][];for (int i = 0; i < n; i++) a[i] = ns(m);return a;}
private int[] na(int n) {int[] a = new int[n];for (int i = 0; i < n; i++) a[i] = ni();return a;}
private long[] nal(int n) { long[] a = new long[n];for (int i = 0; i < n; i++) a[i] = nl();return a;}
private int ni() { int num = 0, b; boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')){};
if (b == '-') { minus = true; b = readByte(); }
while (true) {
if (b >= '0' && b <= '9') num = (num << 3) + (num << 1) + (b - '0');
else return minus ? -num : num;
b = readByte();}}
private long nl() { long num = 0; int b;
boolean minus = false;
while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')){};
if (b == '-') { minus = true; b = readByte(); }
while (true) {
if (b >= '0' && b <= '9') num = num * 10 + (b - '0');
else return minus ? -num : num;
b = readByte();}}
void print(Object obj){out.print(obj);}
void println(Object obj){out.println(obj);}
void println(){out.println();}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for i in range(int(input())):
n=int(input())
d=2
a=[]
while len(a)<2 and d*d<n:
if n%d==0:
a.append(d)
n//=d
d+=1
if len(a)<2:
print("NO")
else:
print("YES")
print(n,*a)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t = int(input())
for i in range(t):
n = int(input())
a = n
for i in range(2, 35000):
if n % i == 0:
a = i
break
n //= a
b = n
for i in range(2, 35000):
if n % i == 0 and a != i:
b = i
break
n //= b
if n == 1 or n == a or n == b:
print("NO")
else:
print('YES')
print(a, b, 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 GetNumber(start, n, number, count):
if count == 1 and n >= start:
number += (str(n))
print("YES")
print(number)
return
for i in range(start, int(math.sqrt(n)) + 1):
if n % i == 0:
number += (str(i)+" ")
count -= 1
GetNumber(i+1, int(n / i), number, count)
return
print("No")
return
inputCount = int(input(""))
for i in range(0, inputCount):
n = int(input(""))
GetNumber(2, n, "", 3) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible 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 num_divisors(n):
div=[]
for i in range(2,int(math.sqrt(n))):
if n%i==0:
div.append(i)
for j in range(i+1,int(math.sqrt(n/i))+1):
if (n/i)%j==0:
if (n/i)!=j*j:
div.extend([j,n/(i*j)])
print("YES")
print(" ".join([str(round(d)) for d in div]))
return
div.remove(i)
print('NO')
t= int(input())
for i in range(t):
n= int(input())
num_divisors(n) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> vp;
for (int i = 2; i <= sqrt(n); i++) {
while (n % i == 0) {
vp.push_back(i);
n /= i;
}
}
if (n > 1) {
vp.push_back(n);
}
sort(vp.begin(), vp.end());
int a = 1, b = 1, c = 1;
int i = 0;
while (a < 2 && i < vp.size()) {
a *= vp[i++];
}
while (b < 2 && i < vp.size()) {
b *= vp[i++];
}
if (b == a && i < vp.size()) {
b *= vp[i++];
}
while (i < vp.size()) {
c *= vp[i++];
}
if (c == b && i < vp.size()) {
c *= vp[i++];
}
if (a > 1 && b > 1 && c > 1 && a != b && b != c && a != c) {
cout << "YES\n" << 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 | for _ in range(int(input())):
n=int(input())
ok=False
for i in range(2,int(n**0.5)+1):
if n%i==0:
p=n//i
if p==i:
continue
for j in range(2,int(p**0.5)+1):
if p%j==0:
if j==i or j==p//j or p//j==i:
continue
print("YES")
print(i,j,p//j)
ok=True
break
if ok:
break
if not ok:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 |
//package codeforce;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.Iterator;
public class product {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
while (t-- > 0) {
HashSet<Integer> set = new HashSet<Integer>();
int n = Integer.parseInt(br.readLine());
for (int i = 2; i * i <= n; i++) {
if (n % i == 0 && !set.contains(i)) {
n /= i;
set.add(i);
break;
}
}
for (int i = 2; i * i <= n; i++) {
if (n % i == 0 && !set.contains(i)) {
n /= i;
set.add(i);
break;
}
}
if (set.size() != 2 || set.contains(n) || n == 1) {
System.out.println("No");
} else {
System.out.println("Yes");
set.add(n);
Iterator<Integer> itr = set.iterator();
while (itr.hasNext()) {
System.out.print(itr.next() + " ");
}
System.out.println();
}
}
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.Scanner;
public class codeforces1294C
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
int t= s.nextInt();
while(t-->0)
{
int m = s.nextInt(),n=m,i,a=1,b=1;
for(i=2;i*i<=m;i++)
{
if(n%i==0)
{
n=n/i;
if(a==1)
a=i;
else
{
if(b==1)
b=i;
}
}
if(a!=1&&b!=1)
break;
}
n=m/(a*b);
if(a==1||b==1||n==1||a==n||n==b||a==b)
System.out.println("NO");
else
{
System.out.println("YES");
System.out.println(a+" "+b+" "+n);
}
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import floor,sqrt
for _ in range(int(input())):
n=int(input())
if n<=10:
print("NO")
else:
l=[]
c=0
for i in range(2,floor(sqrt(n))+1):
if c==2:
break
if n%i==0:
l.append(i)
n//=i
c+=1
l.append(n)
if len(set(l))<3:
print("NO")
else:
print("YES")
print(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 | for i in range(int(input())):
n = int(input())
d = []
cnt = 2
c = 1
a,b,c = 1,1,1
for i in range(2,int(n**0.5)+1):
if n%i==0:
d.append(i)
if len(d)<=2:
print("NO")
c=0
else:
a = d[0]
for j in range(len(d)):
b = d[j]
c = n//(a*b)
if a*b*c==n and a<b<c:
print("YES\n",a,b,c)
c = 0
break
if c:
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())
def get_fac(n, cr, ml):
for i in range(2, ml+1):
if not cr[i]: continue
if n % i == 0:
cr[i] = False
return i
else:
for j in range(1,ml//i):
cr[i*j] = False
for _ in range(t):
n = int(input())
ml = int(pow(n, 1/3)//1)
cr = [True for _ in range(ml+1)]
a = get_fac(n,cr,ml)
if not a:
print("NO"); continue
nml = int(pow(int(n/a), 1/2))
cr = [True for _ in range(nml+1)]
if a <= nml:
cr[a] = False
b = get_fac(int(n/a), cr, nml)
if not b:
print("NO"); continue
c = n//(a*b)
if c == a or c == b:
print("NO"); continue
print("YES")
print(a,b,c) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t = int(input())
while t:
n = int(input())
flag = 1
arr= []
i=2
while i*i<n:
if n%i==0 and i not in arr:
arr.append(i)
n//=i
break
i+=1
i=2
while i*i<n:
if n%i==0 and i not in arr:
arr.append(i)
n//=i
break
i+=1
if n not in arr:
arr.append(n)
if len(arr)<3:
print("NO")
else:
print("YES")
print(*arr)
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
x=int(input())
for _ in range(x):
n=int(input())
c=0
lol=set()
f=0
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
k=i
while n%k==0:
n//=k
lol.add(k)
c+=1
k*=i
#print(n,k,i)
if len(lol)==2:
f=1
break
if f:
break
if n>=2:
lol.add(n)
if f and len(lol)==3 :
print("YES")
print(*lol)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
vector<int> v;
int m = n;
for (int i = 2; i <= sqrt(m); i++) {
if (m % i == 0) {
v.push_back(i);
m /= i;
break;
}
}
for (int i = 2; i <= sqrt(m); i++) {
if (m % i == 0 && v[0] != i) {
v.push_back(i);
m /= i;
break;
}
}
if (v.size() < 2 || n == 1 || v[0] == m || v[1] == m)
cout << "NO" << endl;
else {
int x = v[0] * v[1];
int y = n / x;
cout << "YES" << endl;
cout << v[0] << " " << v[1] << " " << y << 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 | d = int(input())
ans = [[0]*3]*d
for i in range(d):
n = int(input())
k = int(n**(1/3))+1
f = True
j = 2
while j<k and f:
if n%j == 0:
l = n//j
x = j
while x<int(l**0.5)+1 and f:
x+=1
if l%x == 0 and x!=l//x and j!=l//x:
ans[i] = [j,x,l//x]
f = False
j+=1
if f == True:
ans[i][0] = -1
for i in range(d):
if ans[i][0]!=-1:
print('YES')
print(ans[i][0],ans[i][1],ans[i][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 | def affichage(L):
for i in range(len(L)):
L[i]=str(L[i])
return(' '.join(L))
t=int(input())
for i in range(t):
n=int(input())
n1=n
nb=0
x=int(n**0.5)
X=[]
for i in range(2,x+1):
if n%i==0:
n=n//i
X.append(i)
nb+=1
if nb==2:
break
if nb==2:
X.append(n1//(X[-1]*X[-2]))
if X[0]!=X[1] and X[1]!=X[2] and X[0]!=X[2]:
print("YES")
print(affichage(X))
else:
print("NO")
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
for _ in range(int(input())):
n = int(input())
facs = []
i = 2
x = n
while i <= int(math.sqrt(x)) and len(facs) < 2:
if n % i == 0:
facs.append(i)
n = n // i
i += 1
if n not in facs and n > 1:
facs.append(n)
if len(facs) == 3:
print("YES")
print(*facs)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
map<long long, long long> cn;
set<long long> fac;
while (t--) {
fac.clear();
cn.clear();
long long n;
cin >> n;
long long temp = n;
for (long long i = 2; i * i <= n; i++) {
while (n % i == 0) {
cn[i]++;
n /= i;
fac.insert(i);
}
}
if (n > 1) cn[n]++, fac.insert(n);
n = temp;
if (fac.size() >= 3) {
cout << "YES\n";
long long a = *fac.begin(), b = *(++fac.begin());
cout << a << " " << b << " " << n / (a * b) << "\n";
continue;
} else if (fac.size() == 1 && cn[*(fac.begin())] >= 6) {
cout << "YES\n";
cout << *(fac.begin()) << " " << (*(fac.begin())) * (*(fac.begin()))
<< " "
<< n / ((*(fac.begin())) * (*(fac.begin())) * (*(fac.begin())))
<< "\n";
continue;
}
if (fac.size() == 2) {
long long a, ac, b, bc;
a = *(fac.begin());
ac = cn[*(fac.begin())];
b = *(++fac.begin());
bc = cn[*(++fac.begin())];
if (ac + bc >= 4) {
cout << "YES\n";
cout << a << " " << b << " " << n / (a * b) << "\n";
continue;
}
}
cout << "NO\n";
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
from math import ceil, sqrt
t = int(sys.stdin.readline())
def factor(n):
pf = {}
maxp = min(n - 1, ceil(sqrt(n)))
nf = n
for p in range(2, maxp + 1):
if nf == 1:
break
while nf % p == 0:
nf //= p
if p in pf:
pf[p] += 1
else:
pf[p] = 1
if nf > 1:
if nf in pf:
pf[nf] += 1
else:
pf[nf] = 1
pf = list(pf.items())
# ~ print(n, pf)
if len(pf) == 1:
if pf[0][1] >= 6:
print("YES")
frac = n // pf[0][0]**3
print(pf[0][0], pf[0][0]**2, frac)
else:
print("NO")
elif len(pf) == 2:
if pf[0][1] >= 2 and pf[1][1] >= 2:
print("YES")
frac = n // (pf[0][0] * pf[1][0])
print(pf[0][0], pf[1][0], frac)
elif pf[0][1] == 1 and pf[1][1] >= 3 or pf[0][1] >= 3 and pf[1][1] == 1:
print("YES")
frac = n // (pf[0][0] * pf[1][0])
print(pf[0][0], pf[1][0], frac)
else:
print("NO")
else:
print("YES")
frac = n // (pf[0][0] * pf[1][0])
print(pf[0][0], pf[1][0], frac)
for i in range(t):
n = int(sys.stdin.readline())
factor(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 | t=int(input())
for q in range(t):
n=int(input())
c=[]
i=2
while len(c)<2 and i*i<n:
if n%i==0:
c.append(i)
n//=i
i+=1
if len(c)==2 and n not in c:
print('YES')
print(*c,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
I=sys.stdin.readline
ans=""
for _ in range(int(I())):
n=int(input())
fac=[]
for i in range(2,int(n**.5)):
if n%i==0:
fac.append((i,n//i))
break
if len(fac)!=0:
x=fac[0][1]
for i in range(2,int(x**.5)+1):
if x%i==0 and i!=fac[0][0] and i!=x//i:
ans+="YES\n"
ans+="{} {} {}\n".format(fac[0][0],i,x//i)
break
else:
ans+="NO\n"
else:
ans+="NO\n"
print(ans)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.*;
import java.util.*;
public class A {
public static void main(String[] args) throws IOException{
//0-1 Knapsack Problem
FastScanner fs = new FastScanner();
int test = fs.nextInt();
while(test-->0) {
int n = fs.nextInt();
ArrayList<Integer> f = new ArrayList<Integer>();
for(int i=2 ; i<=Math.sqrt(n) ; i++) {
if(n%i==0) {
f.add(i);
n/=i;
break;
}
}
if(f.size()==0) {
System.out.println("NO");
continue;
}else {
for(int i=f.get(0) + 1 ; i*i<=n ; i++) {
if(n%i==0) {
f.add(i);
n/=i;
break;
}
}
if(f.size()==1 || f.get(0)==f.get(1) || n==1 || n==f.get(0) || n==f.get(1)) {
System.out.println("NO");
}else {
System.out.println("YES");
System.out.println(f.get(0) + " " + f.get(1) + " "+ n);
}
}
}
}
static void sort(int[] a) {
ArrayList<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
static class FastScanner {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st=new StringTokenizer("");
String next() {
while (!st.hasMoreTokens())
try {
st=new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
int[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
String[] readStringArray(int n) {
String[] a=new String[n];
for (int i=0; i<n; i++) a[i]=next();
return a;
}
long nextLong() {
return Long.parseLong(next());
}
}
static class Pair implements Comparable<Pair> {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int hashCode() {
return this.x ^ this.y;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Pair other = (Pair) obj;
if (x != other.x)
return false;
if (y != other.y)
return false;
return true;
}
@Override
public int compareTo(Pair o) {
if(x!=o.x)return x-o.x;
return y-o.y;
}
}
} | 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 |
c = int(input())
def handleCase(n):
cap = int(n ** 0.40) + 1
for i in range(2, cap):
if n % i == 0:
q = n // i
for j in range(i + 1, int(q ** 0.5) + 1):
if q % j == 0 and not q == j * j:
return str(i) + ' ' + str(j) + ' ' + str(n // i // j)
for _ in range(c):
n = int(input())
ans = handleCase(n)
if ans:
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int test;
cin >> test;
while (test--) {
long long int n;
cin >> n;
long long int a = 0, b = 0;
for (long int i = 2; i * i <= n; i++) {
if (n % i == 0) {
a = i;
n = n / i;
break;
}
}
for (long int i = 2; i * i <= n; i++) {
if (n % i == 0 && i != a) {
b = i;
n = n / i;
break;
}
}
if (a != 0 && b != 0 && b != n)
cout << "YES" << endl << a << " " << b << " " << n << endl;
else
cout << "NO" << endl;
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t= int(input())
for m in range(t):
n= int(input())
flag= 0
u= int(pow(n,1/3))
i=2
while i<u+1:
if(n%i==0):
v= n/i
f= int(pow(v,1/2))
j= i+1
while j<f+1:
if(v%j==0):
v=v/j
flag=1
break
j+=1
if(flag==1):
break
i+=1
if(flag==1 and j!=v):
print('YES')
print("%d %d %d" %(i,j,v))
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int32_t main() {
long long t;
cin >> t;
while (t--) {
long long n, a, b, bit1 = 0, bit2 = 0;
cin >> n;
for (long long i = 2; i * i <= n; i++)
if (n % i == 0 && i != n / i) {
a = i;
b = n / i;
bit1++;
break;
}
long long x, y;
for (long long i = 2; i * i <= b; i++)
if (b % i == 0 && i != b / i && a != i && a != b / i) {
x = i;
y = b / i;
bit2++;
break;
}
if (bit1 != 0 && bit2 != 0) {
cout << "YES" << endl;
cout << a << " " << x << " " << y << 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 | def factorization(num):
pn = []
while num % 2 == 0:
pn.append(2)
num //= 2
while num % 3 == 0:
pn.append(3)
num //= 3
fg = False
for i in range(5, int(num ** 0.5) + 1, 6):
if fg:
if i > int(num ** 0.5):
break
fg = False
while num % i == 0:
pn.append(i)
num //= i
fg = True
i += 2
if fg:
if i > int(num ** 0.5):
break
fg = False
while num % i == 0:
pn.append(i)
num //= i
fg = True
if num > 1:
pn.append(num)
return pn
def calculation():
if len(ns) < 3:
return 0, 0, 0
n1 = ns[0]
n2 = ns[1]
n3 = 0
for i in range(2, len(ns)):
if n2 == n1:
n2 *= ns[i]
break
i -= 1
break
if len(ns) > i + 1:
n3 = ns[i + 1]
else:
return 0, 0, 0
for i in range(i + 2, len(ns)):
n3 *= ns[i]
if n1 != n2 and n2 != n3 and n1 != n3:
return n1, n2, n3
return 0, 0, 0
t = int(input())
for _ in range(t):
n = int(input())
if n > 23:
ns = factorization(n)
n1, n2, n3 = calculation()
if n1 > 0:
print('YES')
print(n1, n2, n3)
else:
print('NO')
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
input = sys.stdin.readline
def factors(n):
ret = set()
for i in range(2, int(n**.5) + 1):
if n%i == 0:
ret.add(i)
ret.add(n//i)
return ret
def solve(n):
for i in range(2, int(n**.5)+1):
if n%i == 0 and i != n//i:
a, b = i, n//i
fa, fb = factors(a), factors(b)
# option 1
if len(fa) > 0:
for fac in fa:
if len(set([fac, a//fac, b])) == 3:
return [fac, a//fac, b]
# option 2
if len(fb) > 0:
for fac in fb:
if len(set([fac, b//fac, a])) == 3:
return [fac, b//fac, a]
return 'NO'
for _ in range(int(input())):
n = int(input())
ans = solve(n)
if ans == 'NO':
print('NO')
else:
print('YES')
print(*sorted(ans)) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | def solve(n):
a, b, c = None, None, n
i = 2
while c >= 2 and i * i < c:
if c % i == 0:
c //= i
if a is None:
a = i
elif c >= 2:
return a, i, c
i += 1
raise ValueError()
for T in range(int(input())):
try:
a, b, c = solve(int(input()))
print('YES')
print(a, b, c)
except ValueError:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | R = lambda:map(int, input().split(" "))
from math import sqrt
def divs(n):
a, b, c = 2, 2, 2
while a <= sqrt(n):
if n % a == 0:
n //= a
break
a += 1
b = a + 1
while b <= sqrt(n):
if n % b == 0:
c = n // b
if c == a or c == b:
break
print("YES")
print(a, b, c)
n //= b
return
b += 1
print("NO")
t = int(input())
for i in range(t):
n = int(input())
divs(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 | t=int(input())
for x in range(t):
n=int(input())
i=2
a=[]
while(len(a)<2 and i*i<n):
if n%i==0:
n=n//i
a.append(i)
i=i+1
if len(a)==2 and n not in a:
print("YES")
print(n,*a)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def primeFactors(n):
d = {}
while n % 2 == 0:
try:
d[2]+=1
except:
d[2]=1
n = n // 2
for i in range(3, int(math.sqrt(n))+1, 2):
while n % i == 0:
try:
d[i]+=1
except:
d[i]=1
n = n // i
if n > 2:
try:
d[n]+=1
except:
d[n]=1
return d
t=int(input())
while t:
t-=1
n=int(input())
d=primeFactors(n)
# print(d)
flag=0
s=0
toprint=[]
if len(d)==1:
for i in d:
if d[i]>=6:
flag=1
toprint=[i,i**2,i**(d[i]-3)]
elif len(d)>=3:
flag=1
cnt=0
mul=1
for i in d:
if cnt==0:
toprint.append(i**d[i])
elif cnt==1:
toprint.append(i**d[i])
else:
mul*=(i**d[i])
cnt+=1
toprint.append(mul)
elif len(d)==2:
keys=list(d.keys())
if d[keys[0]]+d[keys[1]]>3:
flag=1
toprint=[keys[0],keys[1],(keys[0]**(d[keys[0]]-1))*(keys[1]**(d[keys[1]]-1))]
if len(set(toprint))<3:
flag=0
if flag:
print('YES')
for i in toprint:
print(i,end=' ')
print()
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for t in range(int(input())):
n = int(input())
try:
a = next(i for i in range(2, int(n**.5)+1) if n%i == 0)
n //= a
b = next(i for i in range(a+1, int(n**.5)+1) if n%i == 0)
c = n // b
if c <= b:
raise
print('YES')
print(a, b, n//b)
except:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | def read():
n = int(input())
return n
def first_factor(n, from_factor):
for i in range(from_factor, int(n ** 0.5) + 1):
if n % i == 0:
return i
return None
def solve(n):
result = [0] * 3
from_factor = 2
for i in range(2):
d = first_factor(n, from_factor)
if d is not None:
result[i] = d
from_factor = d + 1
n = n // d
else:
return None
if n == result[1]:
return None
else:
result[2] = n
return result
for t in range(int(input())):
result = solve(read())
if result:
print("YES")
print(*result)
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
range = xrange
input = raw_input
t = int(input())
for _ in range(t):
n = int(input())
fac = []
i = 2
while i * i <= n:
while n % i == 0:
fac.append(i)
n //= i
i += 1
if n > 1:
fac.append(n)
fac.reverse()
a = fac.pop()
b = 1
while b <= a and fac:
b *= fac.pop()
c = 1
while (c <= a or c == b) and fac:
c *= fac.pop()
if a > 1 and b > 1 and c > 1 and a != b and a != c and b != c:
a,b,c = sorted((a,b,c))
for f in fac:
c *= f
print 'YES'
print a,b,c
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 | T = int(input())
for _ in range(T):
n = int(input())
c = 0
x = []
_n = n
end = int(n ** 0.5) + 1
for i in range(2, end):
if _n % i == 0:
c += 1
_n //= i
x.append(i)
if c >= 2:
break
if c >= 2 and not _n in x:
print('YES')
print(*x[:2], _n)
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | def solution(s):
nums = []
i = 2
while len(nums) < 2 and i ** 2 <= s:
if s % i == 0 and i not in nums:
nums.append(i)
s //= i
i += 1
if s not in nums and len(nums) == 2:
print("YES")
print(*nums, s)
else:
print("NO")
t = int(input())
while t > 0:
t -= 1
s = int(input())
solution(s)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | z,zz=input,lambda:list(map(int,z().split()))
zzz=lambda:[int(i) for i in stdin.readline().split()]
szz,graph,mod,szzz=lambda:sorted(zz()),{},10**9+7,lambda:sorted(zzz())
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac
def lcd(xnum1,xnum2):return (xnum1*xnum2//gcd(xnum1,xnum2))
def prime(x):
p=ceil(x**.5)+1
for i in range(2,p):
if (x%i==0 and x!=2) or x==0:return 0
return 1
def dfs(u,visit,graph):
visit[u]=True
for i in graph[u]:
if not visit[i]:
dfs(i,visit,graph)
###########################---Test-Case---#################################
"""
"""
###########################---START-CODING---##############################
num=int(z())
for _ in range( num ):
n=int(z())
l=[]
s=int(n**.5)+1
for i in range(2,s):
if n%i==0:
l.append(i)
n//=i
if len(l)==2:
if l[1]!=n and l[0]!=n:
l.append(n)
break
if len(l)==3:
print('YES')
print(*l)
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import os
import math
def f(n):
result = []
now = 2
while len(result) < 2 and now < math.sqrt(n):
if n % now == 0:
result.append(now)
n //= now
now += 1
if len(result) == 2 and n not in result:
return f"YES\n{result[0]} {result[1]} {n}"
else:
return "NO"
if os.environ.get('DEBUG', False):
print(f"{f(64)} = 2 4 8 ")
print(f"{f(32)} = NO")
print(f"{f(97)} = NO")
print(f"{f(2)} = NO")
print(f"{f(12345)} = 3 5 823")
else:
for _ in range(int(input())):
print(f(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
def isprime(n):
if n==1:
return False
if n==2:
return True
for x in range(2,int(math.sqrt(n))):
if n%x==0:
return False
return True
def issquare(n):
if int(math.sqrt(n))*int(math.sqrt(n)) == n:
return True
else:
return False
def solve(n):
for i in range(2,int(math.sqrt(n))):
if n%i==0:
if not(isprime(i)):
x = i
y = int(n/i)
for j in range(2,int(math.sqrt(x))+1):
if x%j == 0 and j != y and x/j != y and j!=x/j:
print("YES")
print(str(j) + " " + str(int(x/j)) + " " + str(y))
return
elif not(isprime(n/i)):
x = n/i
y = i
for j in range(2,int(math.sqrt(x))+1):
if x%j == 0 and j != y and x/j != y and j!=x/j:
print("YES")
print(str(j) + " " + str(int(x/j)) + " " + str(y))
return
print("No")
t = int(input())
while t:
n = int(input())
solve(n)
t-=1 | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def divisors(n):
divs = list()
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
divs.extend([i, n // i])
return list(sorted(set(divs)))
def valid(first, second, third, result):
return third > 1 and third != first and third != second and first * second * third == result
n = int(input())
for _ in range(n):
value = int(input())
divs = divisors(value)
temp = value
if len(divs) == 0:
print("NO")
continue
if len(divs) == 1:
first = divs[0]
second = first * first
third = value // (first * second)
if valid(first, second, third, value):
print("YES")
print(first, second, third)
else:
print("NO")
continue
found = False
for i in range(len(divs)):
for j in range(i + 1, len(divs)):
first, second = divs[i], divs[j]
if valid(first, second, value // (first * second), value):
print("YES")
print(first, second, value // (first * second))
found = True
elif valid(first, first * first, value // (first ** 3), value):
print("YES")
print(first, first * first, value // (first ** 3))
found = True
if found:
break
if found:
break
if not found:
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())
from math import sqrt
for i in range(t):
number=int(input())
l=[]
for i in range(2,int(sqrt(number))+1):
if number%i==0:
for j in range(2,int(sqrt(number//i))+1):
if (number//i)%j==0 and j!=i and (number//i)//j not in[i,j]:
l.append(i)
l.append(j)
l.append((number//i)//j)
break
if len(l)%3==0 and len(l)!=0:
print('YES')
print(*l[0:3])
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t = int(input())
for i in range(t):
n = int(input())
arr = []
fact = 2
flag = 0
while fact < (n//fact):# and len(arr) < 3:
if n % fact == 0:
n = n//fact
arr.append(fact)
if len(arr) == 2:
arr.append(n)
flag = 1
break
fact += 1
if flag:
print("YES")
print(*arr)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for _ in range(int(input())):
n=int(input())
r=int(n**0.5)+1
ans=[]
for i in range(2,r):
if n%i==0:
n//=i
ans.append(i)
if len(ans)==2:break
if len(ans)==2:
if n in ans:print('NO')
else:
print('YES')
print(*ans, n)
else:print('NO') | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
vector<long long> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long a = 0, b = 0, c, d, e, f = 0, l, g, m, n, k, i, j, t, p, q;
cin >> t;
while (t--) {
cin >> n;
f = 0;
v.clear();
for (i = 2; f < 2 && i <= sqrt(n) + 1; i++) {
if (n % i == 0) {
v.push_back(i);
n /= i;
f++;
}
}
if (v.size() < 2 || n == 1 || n == v[0] || n == v[1]) {
cout << "NO\n";
} else {
cout << "YES\n" << v[0] << ' ' << v[1] << ' ' << n << '\n';
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
import math
import itertools
import functools
import collections
import operator
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(map(int, input().split()))
def lcm(a, b): return abs(a * b) // math.gcd(a, b)
def wr(arr): return ' '.join(map(str, arr))
def revn(n): return str(n)[::-1]
def dd(): return collections.defaultdict(int)
def ddl(): return collections.defaultdict(list)
def sieve(n):
if n < 2: return list()
prime = [True for _ in range(n + 1)]
p = 3
while p * p <= n:
if prime[p]:
for i in range(p * 2, n + 1, p):
prime[i] = False
p += 2
r = [2]
for p in range(3, n + 1, 2):
if prime[p]:
r.append(p)
return r
def divs(n, start=2):
r = []
for i in range(start, int(math.sqrt(n) + 1)):
if (n % i == 0):
if (n / i == i):
r.append(i)
else:
r.extend([i, n // i])
return r
def divn(n, primes):
divs_number = 1
for i in primes:
if n == 1:
return divs_number
t = 1
while n % i == 0:
t += 1
n //= i
divs_number *= t
def prime(n):
if n == 2: return True
if n % 2 == 0 or n <= 1: return False
sqr = int(math.sqrt(n)) + 1
for d in range(3, sqr, 2):
if n % d == 0: return False
return True
def convn(number, base):
newnumber = 0
while number > 0:
newnumber += number % base
number //= base
return newnumber
def cdiv(n, k): return n // k + (n % k != 0)
t = ii()
for _ in range(t):
n = ii()
d = divs(n)
if len(d) < 4:
print('NO')
else:
f = True
s = d[0]
for item in d[1:]:
t = n // (s * item)
if t in d and t != s and t != item:
print('YES')
print(s, t, item)
f = False
break
if f: print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
import java.lang.*;
public class Cf1294C {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t,n,i,j,k,p,q,r;
t=sc.nextInt();
while(t>0) {
p=0;
q=0;
r=0;
n=sc.nextInt();
for(i=2;i<(int)Math.sqrt(n);i++) {
if(n%i==0) {
p=i;
break;
}
}
for(j=i+1;j<(int)Math.sqrt(n);j++) {
if((n/p)%j==0) {
q=j;
break;
}
}
if(p!=0 && q!=0 && n/(p*q)!=p && n/(p*q)!=q && n/(p*q)!=1) {
System.out.println("YES");
System.out.println(p+" "+q+" "+n/(p*q));
}
else
System.out.println("NO");
t--;
}
sc.close();
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | def three_nums(n):
ret = []
i_max = int(n ** 0.5 + 0.5)
remainder = n
cnt = 0
for i in range(2, i_max + 1):
if remainder % i == 0:
ret.append(i)
remainder //= i
i_max = int(remainder ** 0.5 + 0.5)
cnt += 1
if cnt == 2:
ret.append(remainder)
break
if len(ret) != 3 or ret[1] >= ret[2]:
return None
return ret
if __name__ == "__main__":
t = int(input())
for _ in range(t):
n = int(input())
xs = three_nums(n)
if xs is not None:
print("YES")
print(*xs)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t=int(input())
while t > 0:
n=int(input())
s=set()
aqn=n
for i in range(2,int(math.sqrt(n))+1):
if(aqn%i ==0):
s.add(i)
aqn=int(aqn/i)
if(len(s)==2):
break
s.add(aqn)
if(len(s)==3):
print("YES")
for i in s:
print(i,end=" ")
print()
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 | for _ in range(int(input())):
t = n = int(input())
m = []
j = 2
while len(m)<2 and j*j<t:
if n%j == 0:
m.append(j)
n //= j
j += 1
if len(m)==2 and n>=j:
print("YES")
print(m[0], m[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 solve():
n = int(input())
a = 0
b = 0
for i in range(2, math.ceil(math.sqrt(n))):
if n % i == 0:
a = i
n //= a
break
for i in range(2, math.ceil(math.sqrt(n))):
if n % i == 0 and i != a:
b = i
n //= b
break
if a == 0 or b == 0 or n == 1:
print("NO")
else:
print("YES")
print(a, b, n)
t = int(input())
for _ in range(t):
solve() | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def main():
t = int(input())
out_lst = []
if t <=100 and t >= 1:
for i in range(t):
n = int(input())
div_n = n
lst = []
n_rang = int(math.sqrt(n))
for j in range(2,n_rang):
if div_n % j == 0:
div_n = div_n / j
lst.append(j)
if len(lst) == 2:
if(int(div_n) not in lst):
lst.append(int(div_n))
break
if len(lst) == 3 and 1 not in lst:
out_lst.append("YES")
out_lst.append("{} {} {}".format(lst[0], lst[1], lst[2]))
else:
out_lst.append("NO")
for k in out_lst:
print(k)
else:
return False
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())
for i in range(t):
n=int(input())
a=[]
for i in range(2,math.ceil(math.sqrt(n))+2):
if n%i==0:
n//=i
a.append(i)
if len(a)==2:
break
else:
print('NO')
continue
if n==1 or n==a[0] or n==a[1]:
print('NO')
else:
print('YES')
print(a[0],a[1],n)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for _ in " "*int(input()):
a=int(input());b=[];i=2
while(len(b)<2 and i*i<a):
if a%i==0 and i not in b:b+=[i];a//=i;i=2
else:i+=1
if len(b)==2 and a>1:
print("YES");print(*b,a)
else:print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for _ in range(int(input())):
n = int(input())
a = []
for i in range(2, int(n**(1/2) + 1)):
if(n%i==0):
n = n//i
a.append(i)
if(len(a)==2):
if(n not in a):
a.append(n)
break
else:
break
if(len(a) == 3):
print("YES")
for i in range(3):
a[i] = str(a[i])
print(" ".join(a))
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 ≤ t ≤ 100) — the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≤ n ≤ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a ⋅ b ⋅ c for some distinct integers a, b, c such that 2 ≤ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for _ in range(int(input())):
num = int(input())
list_of_nums = [1]
for i in range(2, int(pow(num, 1/3)+1)):
if num % i == 0:
num = num // i
list_of_nums.append(i)
break
# print(list_of_nums)
for i in range(2, int(pow(num, .5))+1):
if num % i == 0 and i not in list_of_nums:
num //= i
list_of_nums.append(i)
break
# print(list_of_nums)
if num not in list_of_nums and len(list_of_nums) > 2:
print("YES")
list_of_nums = [str(x) for x in list_of_nums]
print(num, ' '.join(list_of_nums[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())
m = n
ans = False
l = []
for i in range(2,int(math.sqrt(n))):
if m % i == 0:
l.append(i)
m = m // i
if len(l) == 2:
if l[1] != m and l[0] != m:
ans = True
break
if ans:
print('YES')
for i in range(2):
print(l[i], end=" ")
print(m)
else:
print('NO') | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.