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 | from math import ceil, sqrt
T = int(input())
answer = ""
for t in range(T):
n = int(input())
end = False
add = []
lim = ceil(sqrt(n)) + 1
for a in range(2, lim):
if n % a == 0:
for b in range(a+1, lim):
c = n / a / b
if int(c) == c and c != b and c != a and c != 1:
answer += "YES\n"
c = int(n / a / b)
answer += "{} {} {}\n".format(a, b, c)
end = True
break
if end:
break
if not end:
answer += "NO\n"
print(answer) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import sqrt
n = int(input())
for _ in range(n):
a = 0
b = 0
k = int(input())
for i in range(2,int(sqrt(k))+1):
if k%i == 0:
a = i
break
if a > 0:
temp = int(sqrt(k/a+1))
for i in range(a+1,temp+1):
if (k/a) % i == 0:
b = i
break
if a==0 or b==0:
print("NO")
elif(k/(a*b) > b):
print("YES")
print(a,b,int( k/(a*b) ) )
else:
print("NO")
#print(a,b,c,k) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible 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 check(count,n):
a = int(math.sqrt(n))
for i in range(count, a+1):
if n % i == 0:
return i
return 0
for i in range(int(input())):
n = int(input())
a,b,c = 0, 0 , 0
while(n != 0):
if (check(2,n) == 0):
c = n
n = 0
break
elif (check(2,n) != 0 ):
a = check(2,n)
b = check(a+1,n /a)
if (b == 0):
break
c = n / (a*b)
break
if (c <= 1 or a <=1 or b <=1 or a == b or b == c or c == a ) :
print("NO")
continue
print("YES")
print(a,' ',b,' ',int(c))
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(), cout.tie(NULL);
int t;
cin >> t;
while (t--) {
long long n, i, j, k, a = 1, b = 1, c = 1;
cin >> n;
bool ok = 1;
for (i = 2; i * i <= n; i++) {
if (n % i == 0) {
a = i;
break;
}
}
j = n / a;
for (i = 2; i * i <= j; i++) {
if (j % i == 0) {
if (i == a) continue;
b = i;
break;
}
}
if (b == 1 || a == 1 || (j / b) == 1) ok = 0;
c = n / (a * b);
if (a == b || b == c || c == a) ok = 0;
if (!ok) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
cout << a << ' ' << b << ' ' << c << endl;
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
for _ in range(int(input())):
n = int(input())
d = {}
x = int(math.sqrt(n))
ans = []
flag = 0
product = 1
for i in range(2,x+1):
if n%i==0:
product*=i
if n%product==0:
ans.append(i)
else:
product/=i
flag = 1
if len(ans)==2:
break
if flag == 1 and len(ans)>=2:
y = n//(ans[-1]*ans[-2])
if y in ans or n%y!=0:
print("NO")
else:
print("YES")
ans.append(y)
for i in ans:
print(i,end=" ")
print()
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | d=dict()
import math
def primeFactors(n):
c=0
while n % 2 == 0:
c+=1
n = n // 2
if c!=0:
d[2]=c
for i in range(3, int(math.sqrt(n)) + 1, 2):
c=0
while n % i == 0:
c+=1
n = n // i
if c!=0:
d[i]=c
if n > 2:
if n in d:
d[n]+=1
else:
d[n]=1
I=input
for _ in range(int(I())):
d.clear()
n=int(I())
primeFactors(n)
# print(d)
k=list(d.keys())
v=list(d.values())
if len(set(d))==1:
if v[0]>=6:
print('YES')
a=k[0]
b=k[0]**2
c=k[0]**(v[0]-3)
print(a,b,c)
else:
print('NO')
elif len(set(d))==2:
if sum(v)>=4:
print('YES')
a=k[0]
b=(k[0]**(v[0]-1))*(k[1]**(v[1]-1))
c=k[1]
print(a,b,c)
else:
print('NO')
else:
a=k[0]**v[0]
b=k[1]**v[1]
c=1
for i in range(2,len(k)):
c*=(k[i]**v[i])
print('YES')
print(a,b,c)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for j in range(int(input())):
n=int(input())
flag = False
for i in range(2,int(n**(1/3))+1):
if n%i==0:
z=n//i
for k in range(i+1,int(z**0.5)+1):
if z%k==0 and k*k!=z:
flag=True
print("YES")
print(i,k,z//k)
break
if flag==True:
break
if flag==False:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t=int(input())
if t<=100:
while t>0:
l=list()
n = int(input())
x = int(2)
y = int(2)
z = int(2)
for i in range(2,round(n**0.5)+1):
if n%i == 0 and not(i in l):
n=n//i
l.append(i)
break
for i in range(2, round(n ** 0.5)+1):
if n%i == 0 and not (i in l):
n = n // i
l.append(i)
break
if not(n in l) and n>1 and len(l)==2:
print('YES')
print(l[0],l[1],n)
else :
print('NO')
t -= 1
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def primeFactors(n):
a = []
while n % 2 == 0:
a.append(2)
n = n // 2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
a.append(i)
n = n//i
if n > 2:
a.append(n)
return a
t = int(input())
for _ in range(t):
n = int(input())
k = primeFactors(n)
l = len(k)
w = len(set(k))
if l>=6:
p=1
print("YES")
for i in range(3,l):
p*=k[i]
print(k[0],k[1]*k[2],p)
elif l<=2:
print("NO")
elif l==3:
if w==3:
print("YES")
print(k[0],k[1],k[2])
else:
print("NO")
else:
if w==1:
print("NO")
else:
print("YES")
k.sort()
if l==4:
print(k[0],k[1]*k[2],k[3])
else:
print(k[0],k[1]*k[2]*k[3],k[4])
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
from math import sqrt
def primeFactors(n):
a=[]
# Print the number of two's that divide n
while n % 2 == 0:
a.append(2)
n = n / 2
# n must be odd at this point
# so a skip of 2 ( i = i + 2) can be used
for i in range(3,int(math.sqrt(n))+1,2):
# while i divides n , print i ad divide n
while n % i== 0:
a.append(i)
n = n / i
# Condition if n is a prime
# number greater than 2
if n > 2:
a.append(n)
return a
t=int(input())
for _ in range(t):
n=int(input())
s=set([])
x=int(sqrt(n))+2
for i in range(2,x):
if n%i==0:
s.add(i)
n=n//i
break
x=int(sqrt(n))+2
for i in range(2,x):
if n%i==0 and i not in s:
s.add(i)
s.add(n//i)
break
a=list(s)
if len(a)==3:
print("YES")
print(*a)
else:
print("NO")
# a = primeFactors(n)
# a.sort()
# s=set([])
# if len(a)>3:
# s.add(a[0])
# if a[0]==a[1]:
# s.add(a[1]*a[2])
# k=1
# for i in range(3,len(a)):
# k*=a[i]
# if k in s:
# s=set([])
# s.add(a[0])
# s.add(a[1]*a[-1])
# k=1
# for i in range(2,len(a)-1):
# k*=a[i]
# if k in s:
# print("NO")
# continue
# else:
# s.add(k)
# a=list(s)
# print("YES")
# print(int(a[0]),int(a[1]),int(a[2]))
# continue
# else:
# s.add(k)
# a=list(s)
# print("YES")
# print(int(a[0]),int(a[1]),int(a[2]))
# continue
# else:
# s.add(a[1])
# for i in range(2,len(a)):
# k*=a[i]
# if k in s:
# print("NO")
# continue
# else:
# s.add(k)
# a=list(s)
# print("YES")
# print(int(a[0]),int(a[1]),int(a[2]))
# continue
# elif len(a)==3:
# temp=list(set(a))
# if len(temp)==3:
# print("YES")
# print(int(a[0]),int(a[1]),int(a[2]))
# else:
# print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def primefact(n):
c = 0
l=[]
while n % 2 == 0:
c = c + 1
l.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
c = c + 1
l.append(i)
n = n / i
if n > 2:
l.append(int(n))
c = c + 1
return l
t=int(input())
for i in range(t):
temp=[]
n=int(input())
temp=primefact(n)
dic={}
for j in temp:
if j in dic:
dic[j]=dic[j]+1
else:
dic[j]=1
if len(dic)==1:
for k in dic:
if dic[k]>=6:
print("YES")
print(k*1,k*2,int(math.pow(k,(dic[k]-3))))
else:
print("NO")
elif len(dic)==2:
k=list(dic.keys())
if dic[k[0]]>=2 and dic[k[1]]>=2:
print("YES")
print(k[0],int(math.pow(k[0],(dic[k[0]]-1))*math.pow(k[1],(dic[k[1]]-1))),k[1])
elif dic[k[0]]>=3:
print("YES")
print(k[0],int(math.pow(k[0],(dic[k[0]]-1))),k[1])
elif dic[k[1]] >= 3:
print("YES")
print(k[0],int(math.pow(k[1], (dic[k[1]] - 1))), k[1])
else:
print("NO")
elif len(dic)>=3:
print("YES")
k = list(dic.keys())
print(int(math.pow(k[0],(dic[k[0]]))),end=" ")
print(int(math.pow(k[1],(dic[k[1]]))),end=" ")
p = 1
for j in range(2, len(k)):
p = p * math.pow(k[j], (dic[k[j]]))
print(int(p))
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for _ in range(int(input())):
n=int(input())
n2=n
prime={}
z=int((n**(1/2)))
i=2
while(i<z+1):
if n%i==0:
prime[i]=prime.get(i,0)+1
n=n//i
z=int((n**(1/2)))
i=2
continue
else:
i+=1
else:
prime[int(n)]=prime.get(int(n),0)+1
n=n2
if len(prime)>=2:
output=[]
c=0
for i in prime:
if c>=2:
break
output.append(i)
c+=1
product=output[0]*output[1]
if n//product!=1 and n//product not in output:
print("YES")
print(output[0],output[1],n//product)
else:
print("NO")
if len(prime)==1:
for i in prime:
if prime[i]>=6:
print("YES")
print(i,i**i,i**(prime[i]-3))
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
from collections import Counter
def primeFactors(n):
ans = []
while n % 2 == 0:
ans.append(2)
n = n//2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
ans.append(i)
n = n // i
if n > 2:
ans.append(n)
return ans
def prod(a):
ans = 1
for i in a:
ans*=i
return ans
for _ in range(int(input())):
n = int(input())
a = primeFactors(n)
if len(a)<3:
print("NO")
else:
c = Counter(a)
if len(set(a))<3:
if len(c)==1:
if c[a[0]]>=6:
print("YES")
print(a[0],a[0]*a[0],a[0]**(c[a[0]]-3))
else:
print("NO")
else:
if len(a)>=4:
print("YES")
print(a[0],a[-1],prod(a[1:-1]))
else:
print("NO")
else:
w = list(set(a))
print("YES")
print(w[0],w[1],prod(a)//(w[0]*w[1])) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | n=int(input())
for i in range (n):
a=int(input())
A=[]
for i in range (2, int(a**(0.5))):
if a%i==0:
A.append(i)
a/=i
break
if (len(A) == 0):
print("NO")
continue
else:
for i in range (A[0] + 1, int(a**0.5)+1):
if a %i==0:
A.append(i)
a/=i
break
if len(A)==2:
if A[1]==a or A[0]==1:
print("NO")
else:
print("YES")
print(A[0], A[1], int(a))
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | # ------------------- fast io --------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------- fast io --------------------
import math
import bisect
primes=[2]
for j in range(3,10**5,2):
indy=min(bisect.bisect_left(primes,math.ceil(math.sqrt(j))),len(primes)-1)
broke=False
for s in range(indy+1):
if j%primes[s]==0:
broke=True
break
if broke==False:
primes.append(j)
minny=len(primes)
testcases=int(input())
for j in range(testcases):
#ok we will find its prime divisors
n=int(input())
indy=min(bisect.bisect_left(primes,math.ceil(math.sqrt(n))),minny-1)
facs=[]
for s in range(indy+1):
if n%primes[s]==0:
facs.append(primes[s])
exi=True
if len(facs)>=3:
a,b,c=facs[0],facs[1],n//(facs[0]*facs[1])
elif len(facs)==2:
a,b,c=facs[0],facs[1],n//(facs[0]*facs[1])
if c==0 or c==1 or c==a or c==b:
exi=False
elif len(facs)==1:
a,b,c=facs[0],facs[0]**2,n//(facs[0]**3)
if c==0 or c==1 or c==a or c==b:
exi=False
elif len(facs)==0:
a,b,c=0,0,0
exi=False
if a*b*c==n and exi==True:
print("YES")
print(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 numpy as np
#import pandas as pd
#import os
#import matplotlib
#import seaborn as sns
#import matplotlib.pyplot as plt
#from tqdm import tqdm_notebook
#%matplotlib inline
#import cv2 as cv
#import torch
#print(torch.__version__)
#torch.cuda.is_available()
#torch.version.cuda
def sqrt(p) :
lo = 0.0
hi = 1000000000.0
for i in range(1, 64):
mid = (lo + hi) / 2.0
if(mid * mid > p):
hi = mid
else:
lo = mid
return (lo);
test = int(input())
def solve():
n = int(input())
dp = []
lmt = int(sqrt(n) + 1);
for i in range(2, lmt):
if n % i == 0:
while n % i == 0:
dp.append(i)
n /= i
if n != 1:
dp.append(n)
#for i in dp:
# print(i)
if len(dp) < 3:
print("NO")
return
elif dp[0] == dp[len(dp) - 1]:
dp[0] = (dp[0] * dp[1])
last = 0
for i in range(2, len(dp)):
if i == len(dp) - 1:
break
if i == 2:
last = dp[i]
else:
last = last * dp[i]
if dp[0] == last or dp[len(dp) - 1] == last or last == 0:
print("NO")
else:
print("YES")
print(int(dp[0]), " ", int(dp[len(dp) - 1]), " ", int(last))
else:
last = 0
for i in range(1, len(dp)):
if i == len(dp) - 1:
break
if i == 1:
last = dp[i]
else:
last = last * dp[i]
if last == dp[0] or last == dp[len(dp) - 1] or last == 0:
print("NO")
else:
print("YES")
print(int(dp[0]), " " , int(last), " ", int(dp[len(dp) - 1]))
while test > 0:
solve()
test -= 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 | #-----------------
# cook your dish here
#############-----------------
######-----
import math
###########
#####
try:
#######
def func1(t2,io):#############
######
##########
if len(io) >= 3 and len(t2) >= 3:######
##########
y = t2[1]######
#######
x = t2[0]#######3
#####
z = n//(x*y)########
############
return [x,y,z]#########
######
elif len(io) >= 6 and len(t2) == 1:############33
#######
y = pow(t2[0], 2)##
######
x = t2[0]##########
#########
#######
######
##########
z = n // pow(x, 3)############
############
return [x,y,z]
elif len(io) >= 4 and len(t2) == 2:##########
#####
y = t2[1]##################
######
x = t2[0]######
######
z = n // (y*x)#########
##########
return [x,y,z]#######
else:
##########
return "NO"#######3
def func2(l):
############
io = []###########
###########
while l%2 == 0:########
########
io.append(2)######
#########
l = l//2###
########
for p in range(3, int(math.sqrt(l)) + 1, 2):##########
#############
while (l%p == 0):###########
###########
io.append(p)##########
########
l = l//p
##########
if l > 2:#########
######
io.append(l)########
return io########
#########
tyu = int(input())########
########
for tyc in range(tyu):#########
###########
n = int(input())#####
#############
io = func2(n)
t2 = list(set(io))#########
##############
f = func1(t2,io)######
#############
if f=='NO':#######
#####
print("NO")##########
else:
###########
print("YES")###3
print(*f)###
###########
#######
##########
continue #######
############
except:
pass
##########
################
#####
#############
##########################
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t = int(input())
def factor(n):
arr = set({})
for i in range(2, int(n**0.5)+1):
if n % i == 0:
arr.add(i)
arr.add(int(n/i))
return arr
def find(n, arr):
for a in arr:
for b in arr:
for c in arr:
if (a != b) and (b != c) and (a != c) and a*b*c == n:
print('YES')
return str(a) + ' ' + str(b) + ' ' + str(c)
return 'NO'
for _ in range(t):
n = int(input())
arr = factor(n)
print(find(n, arr)) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int main() {
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
vector<long long> v;
for (long long i = 2; i * i <= n; i++) {
if (v.size() == 2) {
break;
} else if (n % i == 0) {
n = n / i;
v.push_back(i);
}
}
if (v.size() == 2 && n > 1 && v[0] != n && v[1] != n) v.push_back(n);
if (v.size() == 3)
cout << "YES" << endl << v[0] << " " << v[1] << " " << v[2] << endl;
else
cout << "NO" << endl;
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.BufferedReader;
import java.util.ArrayList;
//import java.util.HashMap;
import java.io.InputStreamReader;
public class TEMP1
{
static boolean isp(int n)
{
for(int i=2;i<=(int)Math.sqrt(n);i++)
{
if(n%i==0)
return false;
}
return true;
}
public static void main(String args[])throws Exception
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(br.readLine());
for(int i=0;i<t;i++)
{
int n=Integer.parseInt(br.readLine());
int copy=n;
if(n<24)
{
System.out.println("NO");
continue;
}
String ans="";
int temp=(int)Math.sqrt(n);
int cou=0,ls=0;
int arr[]=new int[2];
for(int j=2;j<=temp;j++)
{
if(n%j==0)
{
ans=ans+(j+" ");
n/=j;
cou++;
arr[ls]=j;
ls++;
if(cou==2)
break;
}
}
if(n==1||arr[0]==n||arr[1]==n||cou<2)
System.out.println("NO");
else
System.out.println("YES\n"+ans+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 | t = int(input())
for _ in range(t):
n = int(input())
factors = []
i = 2
while i * i <= n:
while n % i == 0:
factors.append(i)
n //= i
i += 1
if n > 1:
factors.append(n)
# print(factors)
if len(factors) < 3:
print("NO")
else:
i = 0
a = factors[i]
i += 1
b = factors[i]
i += 1
while i < len(factors) and b == a:
b *= factors[i]
i += 1
if b != a:
break
if i == len(factors):
print("NO")
else:
c = factors[i]
i += 1
while i < len(factors):
c *= factors[i]
i += 1
if c != a and c != b:
print("YES")
print(a, b, c)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import collections
def findDistinctTree(n):
queue = collections.deque()
queue.append(2)
i = 2
while True:
if queue:
i = queue.popleft()
else:
i += 1
if i >= n // i:
print('NO')
return
if n % i != 0:
continue
m = n // i
for j in range(i + 1, m):
if n % j == 0:
queue.append(j)
if j >= m / j:
break
if m % j != 0:
continue
print('YES')
print('{} {} {}'.format(i, j, m//j))
return
print('NO')
return
if __name__ == '__main__':
N = int(input())
cases = []
for _ in range(N):
n = int(input())
cases.append(n)
for case in cases:
findDistinctTree(case) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
n=int(input())
for i in range(n):
l=[]
trigger=0
a=int(input())
d=0
original=a
c=int(math.sqrt(a))
for j in range(2,c+1):
if a%j==0:
l.append(j)
a=a//j
trigger+=1
if trigger==2:
if a<original and l[0]!=a and l[1]!=a and original%a==0:
l.append(a)
print("YES")
print(*l,sep=" ")
d+=1
break
if d==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 java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
/*
HashMap<> map=new HashMap<>();
TreeMap<> map=new TreeMap<>();
map.put(p,map.getOrDefault(p,0)+1);
for(Map.Entry<> mx:map.entrySet()){
int v=mx.getValue(),k=mx.getKey();
}for (int i = 1; i <= 1000; i++)
fac[i] = fac[i - 1] * i % mod;
ArrayList<Pair<Character,Integer>> l=new ArrayList<>();
ArrayList<> l=new ArrayList<>();
HashSet<> has=new HashSet<>();*/
PrintWriter out;
FastReader sc;
long mod=(long)(1e9+7);
int maxint= Integer.MAX_VALUE;
int minint= Integer.MIN_VALUE;
long maxlong=Long.MAX_VALUE;
long minlong=Long.MIN_VALUE;
public void sol(){
int testCase=ni();
while(testCase-->0){
int n=ni();
HashSet<Integer> h=new HashSet<>();
ArrayList<Integer> l=new ArrayList<>();
for(int i=2;i*i<=n;i++){
if(n%i==0){
l.add(i);
h.add(i);
n/=i;
}
}if(n>=2){
l.add(n);
h.add(n);
}if(h.size()>=3){
yes();
pr(l.get(0)+" "+l.get(1)+" ");
int p=1;
for(int i=2;i<l.size();i++){
p*=l.get(i);
}pl(p);
}else no();
}
}
public static void main(String[] args)
{
Main g=new Main();
g.out=new PrintWriter(System.out);
g.sc=new FastReader();
g.sol();
g.out.flush();
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
} public int ni(){
return sc.nextInt();
}public long nl(){
return sc.nextLong();
}public double nd(){
return sc.nextDouble();
}public char[] rl(){
return sc.nextLine().toCharArray();
}public String rl1(){
return sc.nextLine();
}
public void pl(Object s){
out.println(s);
}public void ex(){
out.println();
}
public void pr(Object s){
out.print(s);
}public String next(){
return sc.next();
}public long abs(long x){
return Math.abs(x);
}
public int abs(int x){
return Math.abs(x);
}
public double abs(double x){
return Math.abs(x);
}
public long pow(long x,long y){
return (long)Math.pow(x,y);
}
public int pow(int x,int y){
return (int)Math.pow(x,y);
}
public double pow(double x,double y){
return Math.pow(x,y);
}public long min(long x,long y){
return (long)Math.min(x,y);
}
public int min(int x,int y){
return (int)Math.min(x,y);
}
public double min(double x,double y){
return Math.min(x,y);
}public long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}public long lcm(long a, long b) {
return (a / gcd(a, b)) * b;
}
void sort1(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a) {
l.add(i);
}
Collections.sort(l,Collections.reverseOrder());
for (int i = 0; i < a.length; i++) {
a[i] = l.get(i);
}
}
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);
}
}void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long i : a) {
l.add(i);
}
Collections.sort(l);
for (int i = 0; i < a.length; i++) {
a[i] = l.get(i);
}
}void sort1(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long i : a) {
l.add(i);
}
Collections.sort(l,Collections.reverseOrder());
for (int i = 0; i < a.length; i++) {
a[i] = l.get(i);
}
}
void sort(double[] a) {
ArrayList<Double> l = new ArrayList<>();
for (double i : a) {
l.add(i);
}
Collections.sort(l);
for (int i = 0; i < a.length; i++) {
a[i] = l.get(i);
}
}int swap(int a,int b){
return a;
}long swap(long a,long b){
return a;
}double swap(double a,double b){
return a;
}
boolean isPowerOfTwo (int x)
{
return x!=0 && ((x&(x-1)) == 0);
}boolean isPowerOfTwo (long x)
{
return x!=0 && ((x&(x-1)) == 0);
}public long max(long x,long y){
return (long)Math.max(x,y);
}
public int max(int x,int y){
return (int)Math.max(x,y);
}
public double max(double x,double y){
return Math.max(x,y);
}long sqrt(long x){
return (long)Math.sqrt(x);
}int sqrt(int x){
return (int)Math.sqrt(x);
}void input(int[] ar,int n){
for(int i=0;i<n;i++)ar[i]=ni();
}void input(long[] ar,int n){
for(int i=0;i<n;i++)ar[i]=nl();
}void fill(int[] ar,int k){
Arrays.fill(ar,k);
}void yes(){
pl("YES");
}void no(){
pl("NO");
}
int[] sieve(int n)
{
boolean prime[] = new boolean[n+1];
int[] k=new int[n+1];
for(int i=0;i<=n;i++) {
prime[i] = true;
k[i]=i;
}
for(int p = 2; p <=n; p++)
{
if(prime[p] == true)
{
// sieve[p]=p;
for(int i = p*2; i <= n; i += p) {
prime[i] = false;
// sieve[i]=p;
while(k[i]%(p*p)==0){
k[i]/=(p*p);
}
}
}
}return k;
}
int strSmall(int[] arr, int target)
{
int start = 0, end = arr.length-1;
int ans = -1;
while (start <= end) {
int mid = (start + end) / 2;
if (arr[mid] >= target) {
end = mid - 1;
}
else {
ans = mid;
start = mid + 1;
}
}
return ans;
} int strSmall(ArrayList<Integer> arr, int target)
{
int start = 0, end = arr.size()-1;
int ans = -1;
while (start <= end) {
int mid = (start + end) / 2;
if (arr.get(mid) > target) {
start = mid + 1;
ans=start;
}
else {
end = mid - 1;
}
}
return ans;
}long mMultiplication(long a,long b)
{
long res = 0;
a %= mod;
while (b > 0)
{
if ((b & 1) > 0)
{
res = (res + a) % mod;
}
a = (2 * a) % mod;
b >>= 1;
}
return res;
}long nCr(int n, int r,
long p)
{
if (n<r)
return 0;
if (r == 0)
return 1;
long[] fac = new long[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return (fac[n] * modInverse(fac[r], p)
% p * modInverse(fac[n - r], p)
% p)
% p;
}long power(long x, long y, long p)
{
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}long modInverse(long n, long p)
{
return power(n, p - 2, p);
}
public static class Pair implements Comparable<Pair> {
int x;
int y;
public Pair(int x, int y) {
this.x = x;
this.y = y;
}
public String toString() {
return x + "," + y;
}
public boolean equals(Object o) {
if (o instanceof Pair) {
Pair p = (Pair) o;
return p.x == x && p.y == y;
}
return false;
}
public int hashCode() {
return new Double(x).hashCode() * 31 + new Double(y).hashCode();
}
public int compareTo(Pair other) {
if (this.x == other.x) {
return Long.compare(this.y, other.y);
}
return Long.compare(this.x, other.x);
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import sqrt
for i in range(int(input())):
n = int(input())
a , b , c = (None , None, None )
for i in range(2, int(sqrt(n)) + 2):
if n % i == 0:
a = i
n = n// i;
break;
if ( a != None):
for i in range(a+1, int(sqrt(n)) + 2):
if n % i == 0:
b = i
n //= i
break
c = n
if None in (a, b, c) or b == c or c < 2 or a == c:
print("NO")
else:
print("YES")
print(a, b, c)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 |
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase
from fractions import *
def vsInput():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def value():
return tuple(map(int,input().split()))
def array():
return [int(i) for i in input().split()]
def Int():
return int(input())
def Str():
return input()
def arrayS():
return [i for i in input().split()]
#-------------------------code---------------------------#
#vsInput()
def factors(n):
ans=[]
while n % 2 == 0:
ans.append(2)
n = n // 2
for i in range(3,int(sqrt(n))+1,2):
while n % i== 0:
ans.append(i)
n = n // i
if n > 2:
ans.append(n)
return ans
for _ in range(Int()):
n=Int()
f=factors(n)
#print(f)
if(len(f)<3):
print("NO")
continue
a=f[0]
b=f[1]
i=2
while(i<len(f) and b==a):
b*=f[i]
i+=1
c=n//(a*b)
if(c!=a and c!=b and a!=b and c>1):
print("YES")
print(a,b,c)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def primeFactors(n):
ans=[]
while n % 2 == 0:
ans.append(2)
n = n / 2
for i in range(3,int(math.sqrt(n))+1,2):
while n%i==0:
ans.append(i)
n = n / i
if n > 2:
ans.append(int(n))
return ans
t=int(input())
for g in range(0,t):
n=int(input())
a=primeFactors(n)
a.sort()
ans=1
i=1
x=y=z=0
x=a[0]
if(len(a)==1):
ans=0
if(ans==1):
if(a[1]!=a[0]):
y=a[1]
z=int(n/(x*y))
else:
if(len(a)>2):
y=a[1]*a[2]
z=int(n/(x*y))
else:
ans=0
if(ans==1 and z!=1 and x!=y and y!=z and x!=z):
print("YES")
print(x,y,z)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t = int(input())
for i in range(t):
n = int(input())
sq = int(math.sqrt(n))
l = []
f = 0
for j in range(2,sq):
if n%j==0:
n = n//j
l.append(j)
f = j
if len(l) == 2:
break
elif j>n:
break
else:
f = j
if len(l) == 2:
if n>j:
l.append(n)
print("YES")
for x in l:
print(x,end=" ")
print()
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 | ''' Ψ¨ΩΨ³ΩΩ
Ω Ψ§ΩΩΩΩΩΩ Ψ§ΩΨ±ΩΩΨΩΩ
ΩΩ°ΩΩ Ψ§ΩΨ±ΩΩΨΩΩΩ
Ω '''
#codeforces
gi = lambda : list(map(int,input().split()))
t, = gi()
for k in range(t):
n, = gi()
div = 1
sq = int(n ** .5)
for j in range(2, sq + 1):
if n % j == 0:
div = j
break
x = n // div
sq = int(x ** .5)
div2 = 1
for j in range(2, sq + 1):
if x % j == 0:
if len({div, j, x // j}) == 3:
div2 = j
break;
if div == 1 or div2 == 1:
print("NO")
else:
print("YES")
print(div, div2, x // div2) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible 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_multiply(n):
a, b, c = 0, 0, 0
for i in range(2, n // 2):
if i * i > n:
break
if n % i == 0:
a = i
n = n // i
break
for i in range(a + 1, n // 2):
if i * i > n:
break
if n % i == 0:
b = i
if n // i > b:
c = n // i
break
if a and b and c:
print("YES")
print(a, b, c)
else:
print("NO")
t = int(input())
X = []
x = [X.append(int(input())) for i in range(t)]
for x in X:
three_multiply(x) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
import java.io.*;
public class Main {
/**
*
* k = 1
*
* 2^17+1 2^17 0
* 1 2^17+1 1
*
* dp[2][2] = max(
*/
public static void main(String[] args) {
FastReader sc = new FastReader();
int t = sc.nextInt();
outer: while (t-->0) {
int n = sc.nextInt();
Set<Integer> set = new HashSet<>();
for (int i = 2; i*i<=n;i++) {
if (n % i == 0) {
set.add(i);
n /= i;
break;
}
}
for (int i = 2; i*i <= n; i++) {
if (n % i == 0 && !set.contains(i)) {
n /= i;
set.add(i);
break;
}
}
if (set.size() < 2 || set.contains(n)) {
System.out.println("NO");
} else {
System.out.println("YES");
for (int k : set) {
System.out.print(k+ " ");
}
System.out.println(n);
}
}
// 2 <= a * b * c = n
//
}
private static int[] isPrime(int num) {
for (int i = 2; i <= (int)Math.sqrt(num); i++) {
if (num % i == 0) return new int[]{i, num/i};
}
return null;
}
private static int sign(long num) {
if (num < 0) return -1;
return 1;
}
private static class Pair {
int x;
int y;
public Pair(int x, int y) {
this.x=x;
this.y=y;
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
}
/**
* 7 3
* 3 1 5
* 9 6 5
*
* i = 1: 1
* i = 2: 2
* i = 3: 3
*
*
* 1 2 3 3 3 3 3
*/
/**
*
* 1+1
**/ | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #------------------------------what is this I don't know....just makes my mess faster--------------------------------------
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
#----------------------------------Real game starts here--------------------------------------
#_______________________________________________________________#
def fact(x):
if x == 0:
return 1
else:
return x * fact(x-1)
def lower_bound(li, num): #return 0 if all are greater or equal to
answer = -1
start = 0
end = len(li)-1
while(start <= end):
middle = (end+start)//2
if li[middle] >= num:
answer = middle
end = middle - 1
else:
start = middle + 1
return answer #index where x is not less than num
def upper_bound(li, num): #return n-1 if all are small or equal
answer = -1
start = 0
end = len(li)-1
while(start <= end):
middle = (end+start)//2
if li[middle] <= num:
answer = middle
start = middle + 1
else:
end = middle - 1
return answer #index where x is not greater than num
def abs(x):
return x if x >=0 else -x
def binary_search(li, val, lb, ub):
ans = 0
while(lb <= ub):
mid = (lb+ub)//2
#print(mid, li[mid])
if li[mid] > val:
ub = mid-1
elif val > li[mid]:
lb = mid + 1
else:
ans = 1
break
return ans
def sieve_of_eratosthenes(n):
ans = []
arr = [1]*(n+1)
arr[0],arr[1], i = 0, 0, 2
while(i*i <= n):
if arr[i] == 1:
j = i+i
while(j <= n):
arr[j] = 0
j += i
i += 1
for k in range(n):
if arr[k] == 1:
ans.append(k)
return ans
def nc2(x):
if x == 1:
return 0
else:
return x*(x-1)//2
#_______________________________________________________________#
'''
ββββββββββββββββ
ββββββββββββββββββββββ
βββββββββAestroixβββββββββ
βββββββββββββββββββββββββββ
βββββββββKARMANYAβββββββββββ ________________
ββββββββββββββββββββββββββββ ? ? |ββββββββββββββββ|
ββββββββββββββββββββββββββββ ? |___CM ONE DAY___|
βββββββββββββββββββββββββββ ? ? |ββββββββββββββββ|
ββββββββββββββββββββββββββ ? ?
ββββββββββββββββββββββββββ ?
βββββββββββββββββββββββββ ? ?
ββββββββββββββββββββββββ ?
ββββββββββββββ ββββ=========βββββ
ββββββββββββββββββββββ
βββββββββββββββββββββ
βββββββββββββββββββββ
βββββββββββββββββββββ
'''
from math import *
def is_prime(n):
for i in range(2,int(sqrt(n))+1):
if n%i == 0:
return 0
return 1
for _ in range(int(input())):
n = int(input())
ans = set()
for j in range(2):
i = 2
while(i*i <= n):
if n%i == 0 and not (i in ans) :
ans.add(i)
n //= i
break
i += 1
if len(ans) < 2 or n == 1 or n in ans:
print("NO")
else:
print("YES")
ans = list(ans)
ans.append(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 | #include <bits/stdc++.h>
#pragma warning(disable : 4996)
#pragma warning(disable : 6031)
int main() {
int c;
scanf("%d", &c);
int ans[3];
while (c--) {
memset(ans, 0, sizeof(ans));
int n, now = -1;
scanf("%d", &n);
for (int t = 2; t <= sqrt(n); t++) {
if (n % t == 0) {
now++;
ans[now] = t;
if (now == 1) {
now++;
ans[now] = n / ans[0] / ans[1];
if (ans[0] != ans[1] && ans[1] != ans[2] && ans[0] != ans[2] &&
n == ans[0] * ans[1] * ans[2])
break;
else
now = 0;
}
}
}
if (now == 2 && ans[0] != ans[1] && ans[1] != ans[2] && ans[0] != ans[2] &&
n == ans[0] * ans[1] * ans[2])
printf("YES\n%d %d %d\n", ans[0], ans[1], ans[2]);
else
printf("NO\n");
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 21 18:49:02 2020
@author: dennis
"""
import atexit
import io
import sys
import math
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER
@atexit.register
def write():
sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
def find(n, x):
for c in range(x, int(math.sqrt(n))+1):
if n%c == 0:
return c
return 0
for _ in range(int(input())):
n = int(input())
a = find(n, 2)
if a:
b = find(n//a, a+1)
if b:
c = n//(a*b)
if (a and b and c) and (a != b != c != a) and (a*b*c == n):
print('YES')
print(a, b, c)
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for we in range(int(input())):
n = int(input())
c = 0
a = []
for i in range(2, int(n**0.5)+1):
if n % i == 0:
a.append(i)
n = n//i
if len(a) == 2:
break
if len(a) == 2 and n > a[1]:
print('YES')
print(a[0],a[1],n)
else:
print('NO') | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import ceil,sqrt
def kFactors(n, k=3):
a = []
for i in range(2, ceil(sqrt(n))):
if(n%i==0):
n = n / i
a.append(i)
if n > 2:
a.append(n)
a = list(set(a))
if len(a) < k:
return [-1]
return [a[0],a[1]]
for i in range(int(input())):
n = int(input())
a = kFactors(n)
if(a[0]==-1):
print('NO')
else:
print('YES')
print(int(a[0]),int(a[1]),int(n//(a[0]*a[1])))
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
long long int n, a, b, c;
cin >> n;
int flag = 0;
for (long long int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
a = i;
flag = 1;
break;
};
}
if (flag == 0) {
cout << "NO" << endl;
continue;
}
n = n / a;
for (long long int i = a + 1; i <= sqrt(n); i++) {
if (n % i == 0) {
b = i;
flag = 0;
break;
}
}
if (flag == 1) {
cout << "NO" << endl;
continue;
}
n = n / b;
if (n <= b)
cout << "NO" << endl;
else {
cout << "YES" << endl;
cout << a << " " << b << " " << n << endl;
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int MAX = 1000005;
const double PI = acos(-1.0);
int SetBit(int n, int X) { return n | (1 << X); }
int ClearBit(int n, int X) { return n & ~(1 << X); }
int ToggleBit(int n, int X) { return n ^ (1 << X); }
bool CheckBit(int n, int X) { return (bool)(n & (1 << X)); }
void doTheTask(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
int d = n / i;
for (int j = i + 1; j * j < d; j++) {
if (d % j == 0) {
printf("YES\n%d %d %d\n", i, j, d / j);
return;
}
}
}
}
printf("NO\n");
}
int main(void) {
int tc, n, i, j, a, b, c;
scanf("%d", &tc);
while (tc--) {
scanf("%d", &n);
doTheTask(n);
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
from math import sqrt
def solution(n):
for i in range(2, int(sqrt(n))+1):
if n % i == 0:
a = i
n_a = n // i
for j in range(2, int(sqrt(n_a))+1):
if n_a % j == 0 and j != a:
ra, rb, rc = a, j, n // (a * j)
if ra != rb and rb != rc and rc != ra:
return f"YES\n{ra} {rb} {rc}"
return "NO"
for line in sys.stdin:
t = int(line)
break
for line in sys.stdin:
n = int(line)
print(solution(n))
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Class2 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
StringBuffer rs = new StringBuffer();
while (t-- > 0) {
long n=Integer.parseInt(br.readLine());
ArrayList<Long> ar=new ArrayList<>();
for(long i=2l;i<=(long)Math.sqrt(n);i++){
if(n%i==0){
ar.add(i);
ar.add(n/i);
}
}
int fl=0;
for(long i:ar){
for(long j:ar){
for(long k:ar){
if(i==j||i==k||j==k){
continue;
}
if(i*j*k==n){
rs.append("YES\n");
rs.append(i+" "+j+" "+k+"\n");
fl=1;
break;
}
}
if (fl==1){
break;
}
}
if(fl==1){
break;
}
}
if(fl==0){
rs.append("NO\n");
}
}
System.out.println(rs);
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for _ in range(input()):
n = input()
dic = {}
x = 2
while x*x <= n:
while n%x == 0:
n /= x
if x in dic:
dic[x] += 1
else:
dic[x] = 1
x += 1
if n > 1:
dic[n] = 1
ans = []
#print dic
if len(dic) >= 3:
for i in dic:
ans.append(pow(i, dic[i]))
while len(ans) > 3:
val = ans.pop()
ans[-1] *= val
print "YES"
print ' '.join([str(x) for x in ans])
elif len(dic) == 2 and sum(dic.values()) <= 3:
print "NO"
elif len(dic) == 2:
print "YES"
vals = dic.keys()
print vals[0], vals[1], pow(vals[0], dic[vals[0]]-1)*pow(vals[1], dic[vals[1]]-1)
elif len(dic) == 1 and sum(dic.values()) >= 6:
print "YES"
vals = dic.keys()
print pow(vals[0], 1), pow(vals[0], 2), pow(vals[0], dic[vals[0]]-3)
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, a = 1, b = 1, c = 1;
set<int> s;
cin >> n;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
a = i;
n /= a;
s.insert(a);
break;
}
}
for (int i = a + 1; i * i <= n; i++) {
if (n % i == 0) {
b = i;
n /= b;
s.insert(b);
break;
}
}
if (s.size() < 2 || s.count(n) || n == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
cout << a << " " << b << " " << 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 | """
-----------------------------Pseudo---------------------------------
"""
import copy
import sys
from collections import defaultdict, Counter
#sys.setrecursionlimit(20000)
#PI = 3.1415926535897932384626433832795
def input(): return sys.stdin.readline()
def mapi(): return map(int,input().split())
def maps(): return map(str,input().split())
#
def print(arg, *argv, end=None):
sys.stdout.write(str(arg))
for i in argv: sys.stdout.write(" "+str(i))
sys.stdout.write(end) if end else sys.stdout.write("\n")
#
def GCD(x, y): return GCD(y,x%y) if y else x
#
def modPow(x, y, p):
res,x = 1,x%p
while(y>0):
if(y&1)==1: res=(res*x)%p
y,x = y>>1,(x*x)%p
return res
def modInv(s, mod): return modPow(s,mod-2,mod)
#---------------------------------------------------------------#
from math import *
def solve():
t = 1
t = int(input())
while(t):
t-=1
n = int(input())
a = 0
b = 0
flag = 0
for i in range(int(pow(n,1/3))+1, 1,-1):
if n%i == 0:
a = i
#print(a)
tmp = n//a
for j in range(int(sqrt(tmp))+1, 1,-1):
if (tmp)%j==0 and a!=j:
b = j
c = tmp//b
if a!=c and b!=c:
if c>=2:
flag = 1
break
if flag:
print("YES")
print(a,b,c)
else:
print("NO")
#---------------------------------------------------------------#
if __name__ == '__main__':
solve()
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t, a;
cin >> t;
while (t--) {
cin >> a;
int f1 = 0, f2 = 0, rs1, rs2, rs3;
for (int i = 2; i < min(a, 100000); i++) {
if (a % i == 0) {
a = a / i;
f1 = 1;
rs1 = i;
for (int j = i + 1; j < min(a, 100000); j++) {
if (a % j == 0) {
a = a / j;
f2 = 1;
rs2 = j;
rs3 = a;
break;
}
}
break;
}
}
if (f1 == 1 && f2 == 1) {
if (rs1 < rs2 && rs2 < rs3 && rs1 < rs3) {
cout << "YES" << endl;
cout << rs1 << " " << rs2 << " " << rs3 << endl;
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t = 0;
cin >> t;
while (t--) {
int n = 0;
int a = 0, b = 0, c = 0;
cin >> n;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
a = i;
n /= i;
break;
}
}
for (int i = a + 1; i * i <= n; i++) {
if (n % i == 0) {
if (n / i != i && n / i != a && n / i >= 2) {
b = i;
c = n / i;
}
}
}
if (a >= 2 && b >= 2 && c >= 2) {
cout << "YES"
<< "\n";
cout << a << " " << b << " " << c << "\n";
} else {
cout << "NO"
<< "\n";
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 |
import java.util.*;
public class test {
static int N = (int) 2e5 + 99;
public static class pair implements Comparable<pair> {
int x;
int s;
public pair(int x, int s) {
this.x = x;
this.s = s;
}
@Override
public int compareTo(pair o) {
return (this.s - o.s);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
StringBuilder st = new StringBuilder();
while (t-- > 0) {
int n=sc.nextInt();
HashSet<Integer> hs=solve(n);
if(hs.contains(1))hs.remove(1);
if(hs.size()>=3) {System.out.println("YES");
for(Integer val: hs ) {
System.out.print(val+" ");
}
System.out.println();
}
else System.out.println("NO");
}
System.out.println(st);
}
static HashSet<Integer> solve(int n) {
HashSet<Integer> hs=new HashSet<>();
int i = 2, j = 0;
int N=n;
while (i <= Math.sqrt(n)) {
if (hs.size()==2)
break;
if (N % i == 0) {
hs.add(i);
N = N/ i;
}
i++;
}
hs.add(N);
return hs;
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static int mod=(int)1e9+7;
public static void main(String[] args) throws IOException {
FastReader sc = new FastReader();
int t=sc.nextInt();
while (t-->0){
int n=sc.nextInt();
HashMap<Integer,Integer> hm= fac(n);
int[] arr1=new int[hm.size()];
int[] arr2=new int[hm.size()];
int count=0;
for (int x:hm.keySet()){
arr1[count]=x;
arr2[count]=hm.get(x);
count++;
}
if (count>=3){
System.out.println("YES");
System.out.println(arr1[0]+" "+arr1[1]+" "+n/(arr1[0]*arr1[1]));
}else if (count==2){
if (arr2[0]+arr2[1]>=4){
System.out.println("YES");
System.out.println(arr1[0]+" "+arr1[1]+" "+(n/(arr1[0]*arr1[1])));
}else System.out.println("NO");
}else{
if (arr2[0]>=6){
System.out.println("YES");
System.out.println(arr1[0]+" "+(arr1[0]*arr1[0])+" "+(n/(arr1[0]*arr1[0]*arr1[0])));
}else System.out.println("NO");
}
}
}
static HashMap<Integer, Integer> fac(int x){
HashMap<Integer,Integer> map=new HashMap<>();
for (int i=2;i*i<=x;i++){
int cnt=0;
boolean f=false;
while (x%i==0){
f=true;
x/=i;
cnt++;
}
if (f)map.put(i,cnt);
}
if (x>1)map.put(x,map.getOrDefault(x,0)+1);
return map;
}
}
class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import sqrt
t = int(input())
for test in range(t):
n = int(input())
k = int(sqrt(n))
a = 0
b = 0
c = 0
for j in range(2,k+1):
if n %j == 0:
n = n//j
a = j
break
k = int(sqrt(n))
for j in range(2,k+1):
if n %j == 0 and not(j==a) and not(a == n//j):
n = n//j
b = j
break
c = n
if c > 1 and a> 0 and b > 0 and not(c==b):
print('YES')
print(a,b,c)
else:
print('NO') | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.ArrayList;
import java.util.Scanner;
public class ProductofThreeNumbers {
public static ArrayList<Integer> factors;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while (t-- > 0) {
int n = in.nextInt();
getFactors(n);
//brute force
boolean found = false;
for (int i=0;i<factors.size()-2;i++) {
for (int j=i+1;j<factors.size()-1;j++) {
for (int k=j+1;k<factors.size();k++) {
if ((factors.get(i) * factors.get(j) * factors.get(k)) == n) {
//print the numbres
System.out.println("YES");
System.out.println(factors.get(i) + " " + factors.get(j) + " " + factors.get(k));
found = true;
i = factors.size();
j = factors.size();
k = factors.size();
break;
}
}
}
}
if (!found) {
System.out.println("NO");
}
}
in.close();
}
public static void getFactors(int n) {
factors = new ArrayList<>();
for (int i = 2; i <= Math.sqrt(n); i++) {
if (n % i == 0)
factors.add(i);
}
int size = factors.size() - 2;
if (factors.size() == 0) {
return;
}
if (factors.get(size + 1) * factors.get(size + 1) != n) {
factors.add(n / factors.get(size + 1));
}
for (int i=size;i>=0;i--) {
factors.add(n / factors.get(i));
}
}
public static void printFactors() {
for (int i=0;i<factors.size();i++) {
System.out.print(factors.get(i) + " ");
}
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 | """
Author: guiferviz
Time: 2020-02-08 17:10:34
"""
def prime_factors(n):
factors = []
while n % 2 == 0:
n //= 2
factors.append(2)
for i in range(3, int(n**0.5 + 1), 2):
while n % i == 0:
n //= i
factors.append(i)
if n != 1:
factors.append(n)
return factors
def solve():
n = int(input())
f = prime_factors(n)
a, b, c = 1, 1, 1
for i in f:
if a == 1:
a = i
elif b == 1 or a == b:
b *= i
else:
c *= i
sol = False
if a * b * c == n and a != b and b != c and a != c and b > 1 and c > 1:
sol = True
if sol:
print("YES")
print(a, b, c)
else:
print("NO")
def main():
t = int(input())
for _ in range(t):
solve()
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 | from math import sqrt
for _ in range(int(input())):
n=int(input())
a=[]
s=int(sqrt(n))
for i in range(2,s+1):
if n%i==0:
a.append(i)
n//=i
if len(a)==2:
if a[1]!=n and a[0]!=n:
a.append(n)
break
if len(a)==3:
print('YES')
print(*a)
else:
print('NO') | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.*;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.StringTokenizer;
// ΩΩΨ±Ψͺ Ψ§ΩΩΩΨ― ΩΨ§ ΩΨ¨ΩΨ± Ψ§ΨͺΩΨΆΩ
// ΩΨ§ Ψ±Ψ¨ Accepted
public class ProductOfThreeNumbers {
static ArrayList<Integer> primes;
public static void primeFactors(int n) {
while (n % 2 == 0) {
primes.add(2);
n /= 2;
}
for (int i = 3; i <= Math.sqrt(n); i += 2) {
while (n % i == 0) {
primes.add(i);
n /= i;
}
}
if (n > 1)
primes.add(n);
}
public static void main(String[] args) {
FastReader in = new FastReader();
PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
int t = in.nextInt();
while (t-- > 0) {
primes = new ArrayList<>();
int x = in.nextInt();
primeFactors(x);
if (primes.size() < 3)
out.println("NO");
else {
HashSet<Integer> set = new HashSet<>();
int sum = 1, size = 0;
for (Integer i : primes) {
if (size < 3)
if (!set.contains(i)) {
set.add(i);
size++;
} else if (!set.contains(sum * i)) {
set.add(sum * i);
sum = 1;
size++;
} else
sum *= i;
else
sum *= i;
}
if (sum != 1)
for (Integer i : set) {
if (!set.contains(i * sum)) {
set.remove(i);
set.add(i * sum);
sum = 1;
break;
}
}
if (set.size() < 3 || sum != 1)
out.println("NO");
if (set.size() == 3) {
out.println("YES");
for (Integer i : set) {
out.print(i + " ");
}
out.println();
}
}
}
out.close();
}
private static class FastReader {
BufferedReader br;
StringTokenizer st;
FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
}
}
| 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
q=int(input())
for j in range(q):
n=int(input())
d=[]
flag=0
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
if len(d)==2:
break
else:
d.append(i)
n=int(n/i)
if len(d)==1 or len(d)==0:
flag=1
elif len(d)==2:
if n>1:
if n!=d[0] and n!=d[1]:
print("YES")
print(d[0],end=" ")
print(d[1],end=" ")
print(n)
else:
flag=1
# print("NO")
else:
flag=1
if flag==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 | # -*- coding: utf-8 -*-
"""
Created on Sat Jan 25 10:20:51 2020
@author: Anthony
"""
def abc(num):
threshold=num**0.5
myDivisors=[]
potentialDiv=2
current=num
while(potentialDiv<=threshold and current!=1):
if current//potentialDiv == current/potentialDiv:
myDivisors.append(potentialDiv)
current/=potentialDiv
potentialDiv+=1
if len(myDivisors)>=2 and (current not in myDivisors):
myDivisors.append(int(current))
return myDivisors
if len(myDivisors)>=3 and current==1:
return myDivisors
else:
return False
repeat=int(input())
for i in range(0,repeat):
temp=abc(int(input()))
if temp:
for i in range(0,len(temp)):
for j in range(i+1,len(temp)):
if (temp[i]*temp[j] not in temp) and len(temp)>3:
temp[i]*=temp[j]
temp[j]=1
safiye=[]
for x in temp:
if x!=1:
safiye.append(x)
if len(safiye)==3:
print("YES")
for x in safiye:
print(x,end=" ")
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 | for _ in range(int(input())):
n=nn=int(input())
l1=[]; i=2
while len(l1)<2 and i*i<=nn:
if n%i==0: l1.append(i); n//=i
i+=1
if len(l1)<2 or l1[1]==n or l1[0]==n: print("NO")
else: print("YES"); print(l1[0],l1[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 range(int(input())):
n=int(input())
def solve(n):
ans=[]
for i in range(2,int(n**0.5)+1):
if n%i==0:
ans.append(i)
n/=i
break
if len(ans)==0:
return []
for i in range(2,int(n**0.5)+1):
if n%i==0 and i!=ans[0] and n/i!=ans[0] and i!=n/i:
ans.append(i)
ans.append(int(n/i))
break
return ans
ans=solve(n)
if len(ans)!=3:
print('NO')
else:
print('YES')
print(' '.join(list(map(str,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 f(n):
i = 2
v = []
while i <= int(n**(1/2)) + 1:
if n % i == 0:
v.append(i)
n //= i
if len(v) >= 2:
if (n not in v) and (n != 1):
return (v[0], v[1], n)
else:
return False
i += 1
return False
for _ in range(int(input())):
v = f(int(input()))
if v == False:
print('NO')
else:
print('YES')
print(*v) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
using edge = tuple<int, int, int, int>;
using graph = vector<vector<edge>>;
void go() {
ll n;
cin >> n;
ll a, b, c, m;
for (a = 2; a * a <= n; a++) {
if (n % a == 0) {
m = n / a;
for (b = 2; b * b <= m; b++) {
if (m % b == 0) {
c = m / b;
if (a != b && a != c && b != c) {
cout << "YES\n";
if (a < b && a < c)
cout << a << " " << min(b, c) << " " << max(b, c) << "\n";
else if (b < a && b < c)
cout << b << " " << min(a, c) << " " << max(a, c) << "\n";
else
cout << c << " " << min(a, b) << " " << max(a, b) << "\n";
return;
}
}
}
}
}
cout << "NO\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
while (t--) go();
}
| 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
from collections import Counter
from collections import OrderedDict
from collections import defaultdict
from functools import reduce
sys.setrecursionlimit(10**6)
def inputt():
return sys.stdin.readline().strip()
def printt(n):
sys.stdout.write(str(n)+'\n')
def listt():
return [int(i) for i in inputt().split()]
def gcd(a,b):
return math.gcd(a,b)
def lcm(a,b):
return (a*b) // gcd(a,b)
def factors(n):
step = 2 if n%2 else 1
return set(reduce(list.__add__,([i, n//i] for i in range(1, int(math.sqrt(n))+1, step) if n % i == 0)))
def comb(n,k):
factn=math.factorial(n)
factk=math.factorial(k)
fact=math.factorial(n-k)
ans=factn//(factk*fact)
return ans
def is_prime(n):
if n <= 1:
return False
if n == 2:
return True
if n > 2 and n % 2 == 0:
return False
max_div = math.floor(math.sqrt(n))
for i in range(3, 1 + max_div, 2):
if n % i == 0:
return False
return True
def maxpower(n,x):
B_max = int(math.log(n, x)) + 1#tells upto what power of x n is less than it like 1024->5^4
return B_max
def sf(s,n):
for i in range(s,int(math.sqrt(n)+1)):
if n%i==0:
n=n//i
return i,n
return 1,n
t=int(inputt())
#t=1
for _ in range(t):
a,b,c=1,1,1
n=int(inputt())
a,n=sf(2,n)
b,n=sf(a+1,n)
c=n
#print(a,b,c)
if a!=b and b!=c and c!=1 and a!=c and a!=1 and b!=1:
print("YES")
print(a,b,c)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
num = int(input())
nums = []
for i in range(num):
nums.append(int(input()))
def isPrime(num):
for i in range(2, int(math.sqrt(num)) + 1):
if num % i == 0:
return False
return True
def getDel(num, left):
for i in range(left, int(math.sqrt(num)) + 1):
if num % i == 0:
return [i, num // i]
return [-1]
def thirdNum(f, s, num):
if num != f and num != s:
return num
elif isPrime(num):
return -1
else:
for i in range(s + 1, num):
if num % i == 0:
return i
return -1
for i in nums:
if isPrime(i) == True:
print("NO")
else:
f = getDel(i, 2)
if f[0] > 0:
s = getDel(f[1], f[0] + 1)
if s[0] > 0:
t = thirdNum(f[0], s[0], s[1])
if t > 0:
print("YES")
print(' '.join(map(str, [f[0],s[0],t])))
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 | import math,sys
t = int(input())
answer = []
while t!=0:
t-=1
n = int(input())
num = n
if num in answer:
print('NO')
continue
even = True if num%2==0 else False
if even == True:
arr = [1]
counter = 1
else:
arr = [2]
counter = 2
while len(arr)!=3:
i = arr[-1]+1
if i>n:
break
while n%i!=0 and i<int(pow(n,0.5)):
i+=1
arr.append(i)
n=n//i
if n!=1 and len(arr)==3 and (n not in arr) and arr[1]*arr[2]*n == num:
print('YES')
arr.append(n)
arr = map(str,arr[1:])
print(' '.join(arr))
else:
if num not in answer:
answer.append(num)
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for i in range(int(input())):
n = int(input())
d = []
cnt = 2
a,b,c = 1,1,1
for i in range(2,int(n**0.5)+1):
if n%i==0:
a = i
break
x = n//a
for i in range(2,int(x**0.5)+1):
if x%i==0 and i!=a:
b = i
break
c = n//(a*b)
if a<b<c and a*b*c==n and min(a,b,c)>1:
print("YEs\n",a,b,c)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
t = int(sys.stdin.readline().rstrip())
for _ in range(t):
n = int(sys.stdin.readline().rstrip())
i = 2
sol = []
while i<=n**(1/2):
if n%i == 0:
n = n//i
sol.append(str(i))
i+=1
if len(sol) == 2:
if str(n) not in sol and n != 1:
sol.append(str(n))
break
if len(sol) == 3:
print('YES')
print(' '.join(sol))
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
void parr(int arr[], int n, string name) {
int i;
for (i = 0; i < n; i++) cout << arr[i] << " ";
cout << "\n";
}
template <typename T>
void p(T x, string name = " ") {
cout << name << " : " << x << "\n";
}
void fn(int n) {
int a, b, c;
int i, j, temp;
bool found = false;
for (i = 2; i * i <= n; i++) {
temp = n;
if (temp % i == 0) {
a = i;
temp = temp / a;
for (j = 2; j * j <= temp; j++) {
if (j != a && temp % j == 0) {
b = j;
c = n / (a * b);
if (c != a && c != b && c != 1) {
cout << "YES\n";
cout << a << " " << b << " " << c;
found = true;
break;
}
}
}
if (found) break;
}
}
if (!found) cout << "NO";
}
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
fn(n);
cout << "\n";
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t = int(input())
while t > 0:
n = int(input())
d = set()
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0 and not i in d:
d.add(i)
n /= i
break
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0 and not i in d:
d.add(i)
n /= i
break
if n == 1 or len(d) < 2 or n in d:
print("NO")
else:
d.add(int(n))
print("YES")
print("{} {} {}".format(*list(d)))
t = t - 1 | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.Arrays;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t=sc.nextInt();
int a[]=new int[3];
while(t-->0) {
Arrays.fill(a,0);
int cnt=0;
int n=sc.nextInt();
for(int i=2;i<=Math.sqrt(n);i++) {
if(n%i==0) {
a[cnt++]=i;
n/=i;
if(cnt==2) {a[cnt]=n;break;}
}
}
if(cnt==2&&a[2]>a[1]) {
System.out.println("YES\n"+a[0]+" "+a[1]+" "+a[2]);
}
else System.out.println("NO");
}
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 | #include <bits/stdc++.h>
using namespace std;
long long t, n, z, x, c, s;
int main() {
cin >> t;
while (t--) {
cin >> n;
long long f = 0;
for (int i = 2; i * i <= n; i++) {
for (int j = i + 1; j * j <= (n / i); j++) {
z = i * j;
x = n / z;
s = i * j * x;
if (s == n) {
if (i != j && i != x && j != x) {
f = 1;
cout << "YES"
<< "\n";
cout << i << " " << j << " " << x << "\n";
break;
} else
continue;
}
}
if (f == 1) break;
}
if (f == 0)
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 | """
Template written to be used by Python Programmers.
Use at your own risk!!!!
Owned by adi0311(rating - 1989 at CodeChef and 1405 at CodeForces).
"""
import sys
from bisect import bisect_left as bl, bisect_right as br, bisect # Binary Search alternative
import math
from timeit import default_timer as dt # To get the running time of a program
from itertools import zip_longest as zl # zl(x, y) return [(x[0], y[0]), ...]
from itertools import groupby as gb # gb(x, y)
from itertools import combinations as comb # comb(x, y) return [all subsets of x with len == y]
from itertools import combinations_with_replacement as cwr
from collections import defaultdict as dd # defaultdict(<datatype>) Free of KeyError.
from collections import deque as dq # deque(list) append(), appendleft(), pop(), popleft() - O(1)
from collections import Counter as c # Counter(list) return a dict with {key: count}
# sys.setrecursionlimit(2*pow(10, 6))
# sys.stdin = open("input.txt", "r")
# sys.stdout = open("output.txt", "w")
mod = pow(10, 9) + 7
mod2 = 998244353
# def data(): return sys.stdin.readline().strip()
# def out(var): sys.stdout.write(var)
def data(): return input()
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [[val for i in range(n)] for j in range(m)]
def factors(n):
s = set()
i = 2
while i <= math.sqrt(n):
if n % i == 0:
s.add(n//i)
s.add(i)
i += 1
return s
for _ in range(int(data())):
n = int(data())
ans = factors(n)
if len(ans) < 3:
print("NO")
else:
r = False
for i in ans:
for j in ans:
if i != j:
if n//(i*j) == n/(i*j) and n//(i*j) != 1 and n//(i*j) != i and n//(i*j) != j:
print("YES")
print(i, j, n//(i*j))
r = True
break
if r:
break
if not r:
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 factor(int y, int z) {
for (int i = z + 1; i * i <= y; i++) {
if (y % i == 0) return i;
}
return 0;
}
int main() {
int t;
cin >> t;
while (t > 0) {
int n;
cin >> n;
int x = factor(n, 1);
if (x >= 2) {
int m = factor(n / x, x);
if (m >= 2 && m != x) {
int z = n / (x * m);
if (z != x && z != m && z >= 2) {
cout << "yes" << endl;
cout << x << " " << m << " " << z << endl;
} else
cout << "no" << endl;
} else
cout << "no" << endl;
} else
cout << "no" << endl;
t--;
}
}
| 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 solve(x):
factors = []
i = 2
while i*i < x:
if x % i == 0:
x //= i
factors.append(i)
if len(factors) == 2:
break
i += 1
factors.append(x)
if len(factors) == 3:
print("YES")
print(f"{factors[0]} {factors[1]} {factors[2]}")
else:
print("NO")
def main():
t = int(input())
for i in range(t):
x = int(input())
solve(x)
main()
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def solve(n):
A=[]
for i in range(2,int(math.sqrt(n))+1):
if(n%i==0):
A.append(i)
break
if(len(A)==0):
print("NO")
return
n=n//A[0]
for i in range(A[0]+1,int(math.sqrt(n))+1):
if(n%i==0):
A.append(i)
A.append(int(n/(i)))
break
if(len(A)!=3):
print("NO")
return
if(A[0]<A[1] and A[1]<A[2]):
print("YES")
print(A[0],A[1],A[2])
else:
print("NO")
t=int(input())
for _ in range(t):
n=int(input())
solve(n) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
from collections import defaultdict
import math
def primeFactors(n):
# Print the number of two's that divide n
ans=[]
while n % 2 == 0:
ans.append(2)
n = n / 2
# n must be odd at this point
# so a skip of 2 ( i = i + 2) can be used
for i in range(3, int(math.sqrt(n)) + 1, 2):
# while i divides n , print i ad divide n
while n % i == 0:
ans.append(i)
n = n / i
# Condition if n is a prime
# number greater than 2
if n > 2:
ans.append(int(n))
return ans
t = int(input())
for _ in range(t):
n=int(input())
#n,k=map(int,input().split())
#b=list(map(int,input().split()))
req=primeFactors(n)
d=defaultdict(lambda:0)
for j in req:
d[j]+=1
l=sorted(list(set(req)))
if len(l)>=3:
print("YES")
print(l[0], l[1], n//(l[0]*l[1]))
elif len(l)==2:
ans=[l[0],l[1],n//(l[0]*l[1])]
if len(set(ans))==3 and min(ans)!=1:
print("YES")
print(l[0], l[1], n // (l[0] * l[1]))
else:
print("NO")
else:
if d[l[0]]<6:
print("NO")
else:
print('YES')
print(l[0], l[0]**2, n//(l[0]**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
for _ in range(int(input())):
n = int(input())
flag = False
if n < 24:
print('NO')
elif n == 24:
print('YES')
print(2, 3, 4)
else:
for a in range(2, int(math.sqrt(n)) + 1):
if n % a == 0:
tn = int(n / a)
for b in range(a + 1, int(math.sqrt(tn)) + 1):
if tn % b == 0:
c = int(tn / b)
if c != b and a != c:
print('YES')
print(a, b, c)
flag = True
break
if flag is True:
break
if flag is False:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t=int(input())
for k in range(t):
x=int(input())
A=[]
start=2
while((start**2)<x):
if len(A)==2:
break
if x%start==0:
x/=start
A.append(start)
start+=1
if len(A)==2:
print("YES")
print(int(A[0]),end=" ")
print(int(A[1]),end=" ")
print(int(x))
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t=int(input())
while t>0:
n=int(input())
flag=-1
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
for j in range(2,int(math.sqrt(n//i))+1):
if (n//i)%j==0 and j!=i and (n//j)//i !=j and (n//j)//i !=i and (n//j)//i !=1:
flag=1
print('YES')
print(i,j,(n//i)//j)
break
if flag==1:
break
if flag==-1:
print('NO')
t-=1 | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
//System.out.println("Enter T: ");
int T=sc.nextInt();
for(int t=0;t<T;t++){
int n=sc.nextInt();
solve(n);
}
}
public static void solve(int n) {
int n_copy=n;
ArrayList<Integer>list=new ArrayList<>();
for(int i=2;i<=Math.sqrt(n);i++){
if(n_copy%i==0){
list.add(n/i);
}
}
int a=0,b=0,c=0;
boolean flag=false;
String res="NO";
for(int i=0;i<list.size();i++){
int num=list.get(i);
for(int j=2;j<=Math.sqrt(num);j++){
if(num%j==0){
int num2=num/j;
int third=n/num;
if(num2!=j&&num2!=third&&j!=third){
a=num2;
b=j;
c=n/num;
res="YES";
flag=true;
break;
}
}
}
if(flag==true){break;}
}
System.out.println(res);
if(res.equals("YES")){
System.out.println(a+" "+b+" "+c);
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 |
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while (t-- > 0) {
int n = sc.nextInt();
int a = 0, b = 0, c = 0;
for (int i = 2; i <= 1000 && i < n; i++) {
if (n % i == 0) {
int sum = n / i;
for (int j = i + 1; j < 30000 && j < sum; j++) {
if (sum % j == 0 && sum / j != i && sum / j != j) {
a = j;
b = sum / j;
c = i;
break;
}
}
}
if (a != 0)
break;
}
if (a != 0) {
System.out.println("YES");
System.out.println(a + " " + c + " " + b);
} 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 functools
import heapq as hp
import collections
import bisect
import math
def unpack(func=int):
return map(func, input().split())
def l_unpack(func=int):
"""list unpack"""
return list(map(func, input().split()))
def s_unpack(func=int, rev=False):
"""sorted list unpack"""
return sorted(map(func, input().split()), reverse=rev)
def ml_unpack(n): # multiple line unpack
"""list of n integers passed on n line, one on each"""
return [int(input()) for i in range(n)]
def range_n():
return range(int(input()))
def getint():
return int(input())
def counter(a):
d = {}
for x in a:
if x in d:
d[x] += 1
else:
d[x] = 1
return d
def main():
for _ in range_n():
n = getint()
d = {}
i = 2
while i * i <= n:
if i>n:
break
if not n % i:
d[i] = 0
while not n % i:
n //= i
d[i] += 1
if len(d) == 2:
break
i += 1
if n > 1:
d[n] = 1
key = list(d)
# print(d)
if len(key) == 1 and d[key[0]] > 5:
k = key[0]
a, b, c = k, k ** 2, k ** (d[k] - 3)
elif len(key) == 2:
a, b = key
if d[a] > 2:
b = b ** d[b]
c = a ** (d[a] - 1)
elif d[b] > 2:
a = a ** d[a]
c = b ** (d[b] - 1)
elif d[a] == d[b] == 2:
c = a * b
else:
print('NO')
continue
elif len(key) == 3:
a, b, c = key
a, b, c = a ** d[a], b ** d[b], c ** d[c]
else:
print('NO')
continue
print('YES')
print(a, b, c)
main()
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t=int(input())
while (t>0):
t=t-1
n=int(input())
c=[]
i=2
while (len(c)<2 and i*i<n):
if (n%i)==0:
c.append(i)
n=n//i
i+=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 | def f1(x,k):
for i in range(int(math.sqrt(x)),1,-1):
if (x%i==0):
y=x//i
if (i!=y) and (i!=k) and (y!=k):
return i
return 0
import math
t=int(input())
for i in range(t):
n=int(input())
if (n<24):
print("NO")
continue
a=0
b=0
c=0
for j in range(int(pow(n,1/3)),1,-1):
if (n%j==0):
p=n//j
z=f1(p,j)
if (z!=0):
a=j
b=z
c=p//z
break
if (a!=0):
print("YES")
print(a,b,c)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import sqrt, ceil
def s(y, x=0):
for i in range(2, ceil(sqrt(y))):
n = y // i
if y % i == 0 and i != x and n != x and i != n :
return i, n
else:
return 0, 0
for i in range(int(input())):
x, y = s(int(input()))
y, z = s(y, x)
if y == z:
print('NO')
else:
print('YES')
print(x, y, z) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.Scanner;
public class ProductOfThreeNumbers{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t-- > 0){
long n = sc.nextLong();
long a = 1, b = 1, c = 1;
for(long i = 2; i * i <= n; i++){
if(n % i == 0){
if(a == 1){
a = i;
n /= i;
}else if((n/i) != i && b == 1 && i != a){
b = i;
break;
}
}
}
c = n/b;
if(a != b && b != c && c != 1 && a != 1 && b != 1){
System.out.println("YES");
System.out.println(a + " " + b + " " + c);
}else{
System.out.println("NO");
}
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
int n, a = 0, b = 0, c = 0, n1;
cin >> n;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
n1 = n / i;
a = i;
break;
}
}
for (int i = a + 1; i <= sqrt(n1); i++) {
if (n1 % i == 0) {
b = i;
break;
}
}
if (a > 0 && b > 0) c = n / (a * b);
if (c > 1 && c != a && c != b)
cout << "YES" << endl << a << " " << b << " " << c << endl;
else
cout << "NO" << endl;
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t=int(input())
for i in range(t):
n=int(input())
l=[]
i=2
while(len(l)<2 and i*i < n):
if(n%i==0):
n=n//i
l.append(i)
i+=1
if len(l)==2 and n not in l:
print("YES")
print(*l,n)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import sqrt
n=int(input())
for i in range(n):
t=int(input())
if t<24:
print("NO")
continue
else:
a,b=0,0
for j in range(2,int(sqrt(t))+1):
if t%j==0:
a=j
t//=j
break
for j in range(2,int(sqrt(t))+1):
if t%j==0 and j!=a:
b=j
t//=j
break
if a==0 or b==0 or t==b or t==a or t<2:
print("NO")
else:
print("YES")
print(a,b,t)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author laxit
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
OutputWriter out = new OutputWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC {
public void solve(int testNumber, InputReader in, OutputWriter out) {
int test = in.nextInt();
while (test-- > 0) {
int n = in.nextInt();
boolean flag = false;
int k = 0, i = 0;
int[] arr = new int[3];
for (i = 2; (i * i * i) <= n; i++) {
if (n % i == 0) {
arr[k++] = i;
n = n / i;
i++;
break;
}
}
for (; i * i <= n; i++) {
if (n % i == 0) {
arr[k++] = i;
n = n / i;
break;
}
}
if (k == 2 && n > arr[1]) {
arr[k] = n;
flag = true;
}
if (flag) {
out.println("YES");
out.println(arr[0] + " " + arr[1] + " " + arr[2]);
} else
out.println("NO");
}
}
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private InputReader.SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars == -1) {
throw new InputMismatchException();
}
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
} catch (IOException e) {
throw new InputMismatchException();
}
if (numChars <= 0) {
return -1;
}
}
return buf[curChar++];
}
public int nextInt() {
int c = read();
while (isSpaceChar(c)) {
c = read();
}
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if (c < '0' || c > '9') {
throw new InputMismatchException();
}
res *= 10;
res += c - '0';
c = read();
} while (!isSpaceChar(c));
return res * sgn;
}
public boolean isSpaceChar(int c) {
if (filter != null) {
return filter.isSpaceChar(c);
}
return isWhitespace(c);
}
public static boolean isWhitespace(int c) {
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
static class OutputWriter {
private final PrintWriter writer;
public OutputWriter(OutputStream outputStream) {
writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
}
public OutputWriter(Writer writer) {
this.writer = new PrintWriter(writer);
}
public void print(Object... objects) {
for (int i = 0; i < objects.length; i++) {
if (i != 0) {
writer.print(' ');
}
writer.print(objects[i]);
}
}
public void println(Object... objects) {
print(objects);
writer.println();
}
public void close() {
writer.close();
}
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def primeFactors(n):
# Print the number of two's that divide n
l=[]
while n % 2 == 0:
l.append(2)
n = n / 2
# n must be odd at this point
# so a skip of 2 ( i = i + 2) can be used
for i in range(3,int(math.sqrt(n))+1,2):
# while i divides n , print i ad divide n
while n % i== 0:
l.append(i)
n = n / i
if n > 2:
l.append(n)
return l
t=int(input())
while t:
n=int(input())
l=[]
l=primeFactors(n)
n1=len(l)
a,b,c=0,0,0
a=l[0]
x=list(set(l))
n2=len(x)
if n1>=5:
if l[0]!=l[1]:
b=l[1]
r=2
else:
b=l[1]*l[2]
r=3
c=1
for i in range(r,n1):
c=c*l[i]
if n1==3 and n2==3:
b=l[1]
c=l[2]
if n1==4:
if l[0]!=l[1]:
b=l[1]
c=l[2]*l[3]
else:
b=l[1]*l[2]
c=l[3]
a=int(a)
b=int(b)
c=int(c)
if a!=b and b!=c and c!=a:
print("YES")
print(a,b,c)
else:
print("NO")
t-=1
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | # https://codeforces.com/contest/1294/problem/C
import math
for _ in range(int(input())):
n = int(input())
l = []
i = 2
x = int(math.sqrt(n))
while i < (x + 1) and len(l)<2:
if n%i == 0:
n /= i
x = int(math.sqrt(n))
l.append(i)
i += 1
l.append(int(n))
if len(set(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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n, i = 2, a = 0, b = 0, c = 0, k = 0;
cin >> n;
for (; i <= sqrt(n); i++)
if (n % i == 0) break;
n /= i;
a = i++;
for (; i <= sqrt(n); i++)
if (n % i == 0) {
k = 1;
break;
}
if (k) b = i, c = n / i;
if (a != b && b != c && (c != a) && (a >= 2) && (b >= 2) && (c >= 2)) {
cout << "YES\n";
cout << a << " " << b << " " << c << endl;
} else
cout << "NO\n";
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int x;
int t;
cin >> t;
for (int k = 0; k < t; k++) {
cin >> x;
int a = 0, b = 0, c = 0;
for (int i = 2; i < sqrt(x); i++) {
if (x % i == 0) {
for (int j = i + 1; j < sqrt(x / i); j++) {
if ((x / i) % j == 0 && x / i / j > 2) {
a = i;
b = j;
c = x / i / j;
}
}
}
}
if (a == 0) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
cout << a << " " << b << " " << c << endl;
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import time
s=time.time()
primes=[]
poss=[True for i in range(40000)]
for i in range(2,40000):
if(poss[i]):
primes.append(i)
for j in range(i,40000,i):
poss[j]=False
# print(primes)
# print(time.time()-s)
def find(n):
# n=int(input())
primedivisor=[]
for i in primes:
if(i>n):
break
if(n%i==0):
primedivisor.append(i)
if(len(primedivisor)==0):
# print("NO")
return -1
elif(len(primedivisor)==1):
temp=1
ans=-1
while(n%temp==0):
temp*=primedivisor[0]
ans+=1
if(ans<3):
# print("NO")
return -1
elif(ans<6):
if(primedivisor[0]**ans !=n):
return[1,primedivisor[0],primedivisor[0]**2]
else:
return -1
else:
# print("YES")
return [primedivisor[0]**(ans-3),primedivisor[0],primedivisor[0]**2]
elif(len(primedivisor)==2):
temp=1
ans=-1
while(n%temp==0):
temp*=primedivisor[0]
ans+=1
temp=1
ans2=-1
while(n%temp==0):
temp*=primedivisor[1]
ans2+=1
# print(ans,ans2)
if(ans>2):
# print("YES")
return [primedivisor[1]**ans2,primedivisor[0],primedivisor[0]**(ans-1)]
elif(ans2>2):
# print("YES")
return [primedivisor[0]**ans,primedivisor[1],primedivisor[1]**(ans2-1)]
elif(ans==2):
if(ans2==1):
# print("NO")
if(primedivisor[0]**2)*primedivisor[1]!=n :
return[1,primedivisor[0],primedivisor[1]]
return -1
else:
# print("YES")
return [primedivisor[1]*primedivisor[0],primedivisor[0],primedivisor[1]]
elif(ans2==2):
if(ans==1):
# print("NO")
if(primedivisor[1]**2)*primedivisor[0]!=n :
return[1,primedivisor[0],primedivisor[1]]
return -1
else:
# print("YES")
return [primedivisor[1]*primedivisor[0],primedivisor[0],primedivisor[1]]
elif(ans==1 and ans2==1):
if(primedivisor[1]*primedivisor[0]!=n):
return[1,primedivisor[0],primedivisor[1]]
return-1
else:
# print("YES")
ap=[]
temp=1
while(n%temp==0):
temp*=primedivisor[0]
# print(temp//primedivisor[0],end=" ")
ap.append(temp//primedivisor[0])
temp=1
while(n%temp==0):
temp*=primedivisor[1]
# print(temp//primedivisor[1],end=" ")
ap.append(temp//primedivisor[1])
temp=1
for j in range(2,len(primedivisor)):
while(n%temp==0):
temp*=primedivisor[j]
temp=temp//primedivisor[j]
# print(temp,end=" ")
ap.append(temp)
return ap
t=int(input())
for _ in range(t):
n=int(input())
x=find(n)
# print(x)
if(x!=-1):
temp=x[0]*x[1]*x[2]
if(temp!=n):
x[0]*=n//temp
print("YES")
print(*x)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for t in range(int(input())):
n = int(input())
try:
a = list(i for i in range(2, int(n**.5)+1) if n%i == 0)[0]
n //= a
b = list(i for i in range(a+1, int(n**.5)+1) if n%i == 0)[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 | import java.util.Scanner;
public class ProductofThreeNumbers {
public static int findDiv(int last, int n){
for(int i=last+1; i<Math.sqrt(n) ;i++){
if(n%i==0)
return i;
}
return -1;
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while (t-- > 0) {
int n = s.nextInt();
int a=findDiv(1, n);
int b=findDiv(a, n/a);
int c=n/(a*b);
if(a<0 || b<0 || a==c || b==c)
System.out.println("NO");
else{
System.out.println("YES");
System.out.print(a+ " "+ b+ " "+c);
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
scanf("%d", &t);
while (t--) {
int n;
scanf("%d", &n);
int a = -1, b = -1, c = -1;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
a = i;
break;
}
}
if (a == -1)
printf("NO\n");
else {
int x = n / a;
for (int i = 2; i * i <= x; i++) {
if (x % i == 0) {
if (a != x / i && a != i && x / i != i) {
b = i;
c = x / i;
break;
}
}
}
if (b == -1 || c == -1)
printf("NO\n");
else {
printf("YES\n");
printf("%d %d %d\n", a, b, c);
}
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
set<int> v;
void solve() {
int n;
cin >> n;
int nn = n;
v.clear();
for (int i = 2; i * i <= n; i++)
if (n % i == 0) {
v.insert(i);
n /= i;
}
if (n > 1) v.insert(n);
if (v.size() <= 2) {
cout << "NO" << endl;
return;
}
cout << "YES" << endl;
int s1 = *v.begin();
v.erase(v.begin());
int s2 = *v.begin();
v.erase(v.begin());
cout << s1 << ' ' << s2 << ' ' << nn / (s1 * s2) << endl;
}
int main() {
int t;
cin >> t;
while (t--) solve();
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
using namespace std;
void solve() {
int n;
cin >> n;
int arr[3];
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
arr[0] = i;
n /= i;
break;
}
}
bool good1 = false;
for (int j = 2; j <= sqrt(n); j++) {
if (n % j == 0) {
if (j != n && j != arr[0]) {
arr[1] = j;
n /= j;
good1 = true;
break;
}
}
}
if (n != arr[0] && n != arr[1] && n != 1 && good1)
cout << "YES\n" << arr[0] << " " << arr[1] << " " << n << "\n";
else
cout << "NO\n";
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed;
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 | #include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
for (; b; a %= b, swap(a, b))
;
return a;
}
vector<long long> pr;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
pr.push_back(2);
for (long long i = 3; i * i <= 1000000000; i++) {
bool flag = false;
for (int j = 0; j < pr.size() && pr[j] * pr[j] <= i; j++) {
if (i % pr[j] == 0) {
flag = true;
break;
}
}
if (!flag) pr.push_back(i);
}
int t;
cin >> t;
while (t--) {
map<long long, int> mp;
long long n;
cin >> n;
for (int i = 0; i < pr.size(); i++) {
while (n % pr[i] == 0) {
n /= pr[i];
mp[pr[i]]++;
}
}
if (n != 1) mp[n]++;
if (mp.size() >= 3) {
cout << "YES\n";
long long tmp = 1;
int cnt = 0;
for (auto &it : mp) {
if (cnt < 3) tmp = 1;
for (int i = 0; i < it.second; i++) tmp *= it.first;
if (cnt < 2) {
cout << tmp << ' ';
}
cnt++;
}
cout << tmp << ' ';
cout << '\n';
} else if (mp.size() == 2) {
int twoCnt = 0;
bool flag = false;
for (auto &it : mp) {
if (it.second >= 3)
flag = true;
else if (it.second == 2)
twoCnt++;
}
if (!flag) {
if (twoCnt == 2) {
cout << "YES\n";
long long f1 = (*mp.begin()).first;
long long f2 = (*++mp.begin()).first;
cout << f1 << ' ' << f2 << ' ' << f1 * f2 << '\n';
} else
cout << "NO\n";
continue;
}
cout << "YES\n";
bool hasPrinted = false;
for (auto &it : mp) {
if (it.second >= 3 && !hasPrinted) {
cout << it.first << ' ';
long long tmp = 1;
for (int i = 0; i < it.second - 1; i++) tmp *= it.first;
cout << tmp << ' ';
hasPrinted = true;
} else {
long long tmp = 1;
for (int i = 0; i < it.second; i++) tmp *= it.first;
cout << tmp << ' ';
}
}
cout << '\n';
} else if (mp.size() == 1) {
auto it = *mp.begin();
if (it.second < 6) {
cout << "NO\n";
continue;
}
cout << "YES\n";
long long num = it.first;
cout << num << ' ' << num * num << ' ';
long long tmp = 1;
for (int i = 0; i < it.second - 3; i++) tmp *= it.first;
cout << tmp << '\n';
} else
cout << "NO\n";
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import sqrt
n=int(input())
for i in range(n):
m=int(input())
m1=m
c=2
p=[]
while len(p)<3 and c<=sqrt(m1):
if m%c==0:
m=m//c
p.append(c)
else:
c=c+1
if len(p)==3:
if p[0]==p[1]:
p[1]=p[1]*p[2]
p[2]=m1//p[0]//p[1]
if len(p)==2:
p.append(m1//p[0]//p[1])
if len(p)==3 and p[2]>1 and p[0]!=p[2] and p[1]!=p[2] and p[0]!=p[1]:
print ('YES')
print (*p)
else:
print ('NO') | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
# N, M = map(int, input().split())
# A = list(map(int, input().split()))
T = int(input())
def primeFactors(n):
c = 1
for i in range(2,int(math.sqrt(n))+1,1):
while n % i== 0:
c = c*i
if c not in L and c > 1 and len(L) < 2:
L.append(c)
c = 1
n = n // i
# Condition if n is a prime
# number greater than 2
if n > 2:
c *= n
if c > 1 and c not in L:
L.append(c)
for t in range(T):
N = int(input())
L = []
primeFactors(N)
if len(L) == 3:
print("YES")
# print(L)
print(L[0], L[1], L[2])
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 |
// import java.util.Vector;
import java.util.*;
import java.lang.Math;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.management.Query;
import java.io.*;
import java.util.Arrays;
import java.math.BigInteger;
public class Main {
static int mod = 1000000007;
/* ======================DSU===================== */
static class dsu {
static int parent[], n;// min[],value[];
static long size[];
dsu(int n) {
parent = new int[n + 1];
size = new long[n + 1];
// min=new int[n+1];
// value=new int[n+1];
this.n = n;
makeSet();
}
static void makeSet() {
for (int i = 1; i <= n; i++) {
parent[i] = i;
size[i] = 1;
// min[i]=i;
}
}
static int find(int a) {
if (parent[a] == a)
return a;
else {
return parent[a] = find(parent[a]);// Path Compression
}
}
static void union(int a, int b) {
int setA = find(a);
int setB = find(b);
if (setA == setB)
return;
if (size[setA] >= size[setB]) {
parent[setB] = setA;
size[setA] += size[setB];
} else {
parent[setA] = setB;
size[setB] += size[setA];
}
}
}
/* ======================================================== */
static class Pair implements Comparator<Pair> {
long x;
long y;
// Constructor
public Pair(long x, long y) {
this.x = x;
this.y = y;
}
public Pair() {
}
@Override
public int compare(Main.Pair o1, Main.Pair o2) {
// if (o1.y < o2.y)
// return -1;
// if (o1.y > o2.y)
// return 1;
// if (o1.y == o2.y) {
// if (o1.x <= o2.x) {
// return -1;
// } else {
// return 1;
// }
// }
// return 0;
return ((int) (o1.x - o2.x));
}
}
static class FastReader {
BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] intArr(int n) {
int res[] = new int[n];
for (int i = 0; i < n; i++)
res[i] = nextInt();
return res;
}
long[] longArr(int n) {
long res[] = new long[n];
for (int i = 0; i < n; i++)
res[i] = nextLong();
return res;
}
}
static FastReader f = new FastReader();
static BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
static boolean isPrime(long n) {
if (n <= 1)
return false;
if (n <= 3)
return true;
if (n % 2 == 0 || n % 3 == 0)
return false;
for (long i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0)
return false;
return true;
}
static int LowerBound(int a[], int x) { // x is the target value or key
int l = -1, r = a.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (a[m] >= x)
r = m;
else
l = m;
}
return r;
}
static int UpperBound(int a[], int x) {// x is the key or target value
int l = -1, r = a.length;
while (l + 1 < r) {
int m = (l + r) >>> 1;
if (a[m] <= x)
l = m;
else
r = m;
}
return l + 1;
}
static long gcd(long a, long b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
static long lcm(long a, long b) {
return (a * b) / gcd(a, b);
}
static long power(long x, long y, long p) {
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1; // y = y/2
x = (x * x) % p;
}
return res;
}
static long power(long x, long y) {
long res = 1;
while (y > 0) {
if (y % 2 == 1)
res = (res * x);
y >>= 1;
x = (x * x);
}
return res;
}
static int power(int x, int y) {
int res = 1;
while (y > 0) {
if (y % 2 == 1)
res = (res * x);
y >>= 1;
x = (x * x);
}
return res;
}
static int ceil(int x, int y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
static long ceil(long x, long y) {
return (x % y == 0 ? x / y : (x / y + 1));
}
/*
* ===========Modular Operations==================
*/
static long modInverse(long n, long p) {
return power(n, p - 2, p);
}
static long modAdd(long a, long b) {
return (a % mod + b % mod) % mod;
}
static long modMul(long a, long b) {
return ((a % mod) * (b % mod)) % mod;
}
static long nCrModPFermat(int n, int r) {
long p = 1000000007;
if (r == 0)
return 1;
long[] fac = new long[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) % p;
}
/*
* ===============================================
*/
static List<Character> removeDup(ArrayList<Character> list) {
List<Character> newList = list.stream().distinct().collect(Collectors.toList());
return newList;
}
static void ruffleSort(long[] a) {
int n = a.length;
Random r = new Random();
for (int i = 0; i < a.length; i++) {
int oi = r.nextInt(n);
long temp = a[i];
a[i] = a[oi];
a[oi] = temp;
}
Arrays.sort(a);
}
static void ruffleSort(int[] a) {
int n = a.length;
Random r = new Random();
for (int i = 0; i < a.length; i++) {
int oi = r.nextInt(n);
int temp = a[i];
a[i] = a[oi];
a[oi] = temp;
}
Arrays.sort(a);
}
/*
* ===========Dynamic prog Recur Section===========
*/
static int DP[][];
static ArrayList<ArrayList<Integer>> g;
static int count = 0;
static ArrayList<Long> bitMask(ArrayList<Long> ar, int n) {
ArrayList<Long> ans = new ArrayList<>();
for (int mask = 0; mask <= Math.pow(2, n) - 1; mask++) {
long sum = 0;
for (int i = 0; i < n; i++) {
if (((1 << i) & mask) > 0) {
sum += ar.get(i);
}
}
ans.add(sum);
}
return ans;
}
static long calNum(long year) {
return (year / (long) 4) - (year / (long) 100) + (year / (long) 400);
}
/*
* ====================================Main=================================
*/
static String reverse(String n) {
String s = "";
for (int i = n.length() - 1; i >= 0; i--) {
if (n.charAt(i) == '2') {
s += "5";
} else if (n.charAt(i) == '5') {
s += "2";
} else {
s += n.charAt(i);
}
}
return s;
}
static boolean check(int n) {
int a = n % 10;
int b = n / 10;
if ((a == 0 || a == 1 || a == 2 || a == 5 || a == 8) && ((b == 0 || b == 1 || b == 2 || b == 5 || b == 8))) {
return true;
}
return false;
}
public static void main(String args[]) throws Exception {
// File file = new File("D:\\VS Code\\Java\\Output.txt");
// FileWriter fw = new FileWriter("D:\\VS Code\\Java\\Output.txt");
Random rand = new Random();
int t = 1;
t = f.nextInt();
while (t-- != 0) {
int n=f.nextInt();
int n1=n;
int a=0,b=0,c=0;
for(a=2;a<=Math.sqrt(n);a++){
if(n%a==0){
break;
}
}
n/=a;
for(b=a+1;b<Math.sqrt(n);b++){
if(n%b==0){
break;
}
}
n/=b;
if(n!=a && n!=b && n!=1 && n!=0 && a*b*n==n1){
w.write("YES\n"+a+" "+b+" "+n);
}else{
w.write("NO");
}
w.write("\n");
}
w.flush();
}
} | JAVA |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.