Search is not available for this dataset
name
stringlengths 2
112
| description
stringlengths 29
13k
| source
int64 1
7
| difficulty
int64 0
25
| solution
stringlengths 7
983k
| language
stringclasses 4
values |
---|---|---|---|---|---|
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
from collections import defaultdict, Counter, deque
INF = float('inf')
def gcd(a, b):
while b:
a, b = b, a%b
return a
def primeFactor(n):
if n % 2 == 0:
return 2
i = 3
while (i ** 2) <= n:
if n % i == 0:
return i
i += 1
return n
def main():
n = int(input())
num1 = 2
l = math.ceil((n ** (1 / 3)))
while num1 <= l:
num2 = l
while n % num1 == 0 and num2 <= l * l:
if n % (num1 * num2) == 0:
num3 = n // (num1 * num2)
if num3 != 1 and num1 != num3 and num2 != num3 and num1 != num2:
print('YES')
print(num1, num2, num3)
return
num2 += 1
num1 += 1
num1 = 2
while num1 <= l:
num2 = num1 + 1
while n % num1 == 0 and num2 <= l:
if n % (num1 * num2) == 0:
num3 = n // (num1 * num2)
if num3 != 1 and num1 != num3 and num2 != num3 and num1 != num2:
print('YES')
print(num1, num2, num3)
return
num2 += 1
# print('#')
num1 += 1
print('NO')
return
if __name__ == "__main__":
t = int(input())
# t = 1
for _ in range(t):
main()
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def pf(n):
l =[]
while n % 2 == 0:
l.append(2)
n = n / 2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
l.append(i)
n = n / i
if n > 2:
l.append(n)
return l
for _ in range(input()):
n = input()
a = pf(n)
if len(a)<3:
print "NO"
elif len(set(a))<3:
b = list(set(a))
for i in range(len(b)):
b[i] = [b[i],a.count(b[i])]
b.sort(key = lambda x: x[1])
lil = n
if len(b)==1 and b[0][1]<6:
print "NO"
elif len(b)==1 and b[0][1]>5:
print "YES"
l = 1
for i in range(len(a)-3):
j = i+3
l *= a[i]
print a[0], a[1]*a[2], l
elif len(b)==2 and b[1][1]==2 and b[0][1]==1:
print "NO"
else:
print "YES"
print b[0][0], b[1][0], lil/(b[0][0]* b[1][0])
else:
print "YES"
b = list(set(a))
print b[0],b[1],n/(b[0]*b[1])
| 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 | for tin in range(int(input())):
n=int(input())
f=n; k=0;
for i in range(2,int(n**0.5)+1):
if f%i==0 and f//i!=i:
a=i; f=f//i;
for j in range(i+1,int(f**0.5)+1):
if f%j==0 and f//j!=j:
b=j; c=f//j; k=1; print("YES"); print(a,b,c); break;
if k==1:
break
if k==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 | """
1294C
"""
def inp():
"""
For taking integer inputs.
"""
return(int(input()))
def get_n_ints(n):
"""
For taking List inputs.
"""
result = []
i = 0
while i < n:
val = input().rstrip("\n")
result.append(int(val))
i += 1
return result
def problem(number):
seen = list()
i = 2
while i*i <= number:
if i not in seen:
if number%i == 0:
seen.append(i)
number = number//i
if len(seen) == 2 and number > seen[-1]:
seen.append(number)
print("YES")
print(*(seen))
return
i += 1
print("NO")
n = inp()
arr = get_n_ints(n)
for i in range(n):
problem(arr[i]) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def prime(n) :
if (n <= 1) :
return False
if (n <= 3) :
return True
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
t=int(input())
for i in range(t):
n=int(input())
if(prime(n)):
print("NO")
else:
flag=0
ans=[]
for i in range(2,int(math.sqrt(n))+1):
if(flag==1):
break
if(n%i)==0:
if (prime(i)==False ):
a=n/i
for j in range(2,int(math.sqrt(i))+1):
if(i%j==0 and a!=j and a!=i//j and j!=i//j):
b=j
c=i//j
flag=1
break
break
elif (prime(n//i)==False ):
x=n//i
a=i
for j in range(2,int(math.sqrt(x))+1):
if(x%j==0 and a!=j and a!=x//j and j!=x//j):
b=j
c=x//j
flag=1
break
break
else:
flag=0
if(flag==0):
print("NO")
else:
print("YES")
print(a,b,c)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t = int(input())
for _ in range(t):
n = int(input())
ans = [-1,-1,-1]
i = 2
now = 0
while i**2 <= n:
if n%i == 0:
ans[now] = i
n//=i
if now == 1:break
now += 1
i += 1
if n >= 2:
ans[2] = n
if ans[1] != -1 and ans[2] == n and ans[1] != ans[2]:
print("YES")
print(*ans)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
import bisect as bi
import math
from collections import defaultdict as dd
import heapq
import itertools
input=sys.stdin.readline
from random import randint
##import numpy as np
##sys.setrecursionlimit(10**7)
mo=10**9+7
def cin():
return map(int,sin().split())
def ain():
return list(map(int,sin().split()))
def sin():
return input()
def inin():
return int(input())
for _ in range(inin()):
k=inin()
d=dd(int)
sq=int(math.sqrt(k))+1;c=0;ans=[];f=0
for i in range(2,sq+1):
if(k%i==0):
k=k//i
c+=1
ans+=[i]
if(c==2 and k!=1 and k not in ans):
f=1
break
if(f):
print("YES")
print(*ans,k)
else:print("NO")
## if((n*(n+1)//2)%2):print("NO")
## else:
## print("YES")
## print(n//2)
## print(l[
##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):
## pre=[0]*n
## if(f==0): ##from beginning
## pre[0]=a[0]
## for i in range(1,n):
## pre[i]=a[i]+pre[i-1]
## else: ##from end
## pre[-1]=a[-1]
## for i in range(n-2,-1,-1):
## pre[i]=pre[i+1]+a[i]
## return pre
##maxint=10**24
##def kadane(a,size):
## max_so_far = -maxint - 1
## max_ending_here = 0
##
## for i in range(0, size):
## max_ending_here = max_ending_here + a[i]
## if (max_so_far < max_ending_here):
## max_so_far = max_ending_here
##
## if max_ending_here < 0:
## max_ending_here = 0
## return max_so_far
##def power(x, y):
## if(y == 0):return 1
## temp = power(x, int(y / 2))%mo
## if (y % 2 == 0):return (temp * temp)%mo
## else:
## if(y > 0):return (x * temp * temp)%mo
## else:return ((temp * temp)//x )%mo
##for _ in range(1):
## n=inin()
## l=ain()
## d=dd(list)
## dp=dd(set)
## for k in range(n):
## i=l[k]
## dp[i].add(k)
## b=bin(i)[2:]
## c=0
## for j in b[::-1]:
## if j=='1':
## d[c]+=[[i,k]]
## c+=1
## key=sorted(list(d.keys()),reverse=True)
## ans=0
## for i in key:
## va=d[i]
## va.sort(reverse=True)
## p=len(va)
## if(p!=0):
## c=0;tans=0
## for j,po in va:
## if(po in dp[j]):
## c+=1
## f1,f2=j,po
## tans+=j
## dp[j].remove(po)
## if(c%2==0 and c!=0):
## c-=1
##
## ans+=tans
## print(ans,i,c,va)
## print(ans)
##
##
##
##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):
## pre=[0]*n
## if(f==0): ##from beginning
## pre[0]=a[0]
## for i in range(1,n):
## pre[i]=a[i]+pre[i-1]
## else: ##from end
## pre[-1]=a[-1]
## for i in range(n-2,-1,-1):
## pre[i]=pre[i+1]+a[i]
## return pre
##maxint=10**24
##def kadane(a,size):
## max_so_far = -maxint - 1
## max_ending_here = 0
##
## for i in range(0, size):
## max_ending_here = max_ending_here + a[i]
## if (max_so_far < max_ending_here):
## max_so_far = max_ending_here
##
## if max_ending_here < 0:
## max_ending_here = 0
## return max_so_far
##def power(x, y):
## if(y == 0):return 1
## temp = power(x, int(y / 2))%mo
## if (y % 2 == 0):return (temp * temp)%mo
## else:
## if(y > 0):return (x * temp * temp)%mo
## else:return ((temp * temp)//x )%mo
##def msb(n):n|=n>>1;n|=n>>2;n|=n>>4;n|=n>>8;n|=n>>16;n|=n>>32;n|=n>>64;return n-(n>>1) #2 ki power
##def pref(a,n,f):
## pre=[0]*n
## if(f==0): ##from beginning
## pre[0]=a[0]
## for i in range(1,n):
## pre[i]=a[i]+pre[i-1]
## else: ##from end
## pre[-1]=a[-1]
## for i in range(n-2,-1,-1):
## pre[i]=pre[i+1]+a[i]
## return pre
##maxint=10**24
##def kadane(a,size):
## max_so_far = -maxint - 1
## max_ending_here = 0
##
## for i in range(0, size):
## max_ending_here = max_ending_here + a[i]
## if (max_so_far < max_ending_here):
## max_so_far = max_ending_here
##
## if max_ending_here < 0:
## max_ending_here = 0
## return max_so_far
##def power(x, y):
## if(y == 0):return 1
## temp = power(x, int(y / 2))%mo
## if (y % 2 == 0):return (temp * temp)%mo
## else:
## if(y > 0):return (x * temp * temp)%mo
## else:return ((temp * temp)//x )%mo
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible 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
def factor(n):
a=[]
for x in range(2,int(n**.5)+1):
if n%x==0 and (x!=n//x):
a.append([x,n//x])
return a
t=int(input())
while(t):
t=t-1
found=False
n=int(input())
for f in range(2,int(n**.5)+1):
if n%f==0:
j=factor(n//f)
for x in j:
if x[0]!=f and x[1]!=f:
print("YES")
print(f,x[0],x[1])
found=True
break
if found:
break
if found==False:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t=int(input())
while(t!=0):
t-=1
a=[]
c=0
n=int(input())
j=0
for i in range(2,int(math.sqrt(n))+1):
if(n%i==0):
a.append(i)
n/=i
j=i
break
for i in range(j+1,int(math.sqrt(n))+1):
if(n%i==0):
a.append(i)
n/=i
j=i
break
if(n>j and len(a)==2):
c=1
a.append(int(n))
if(c==1):
print("YES")
print(a[0],a[1],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 | from sys import stdin,stdout
def main():
t = int(input())
for z in range(t):
n = int( input() )
i = 2
sw = 1
while i*i<n and sw:
if n%i==0:
j = 2
tmp = n // i
while j*j < tmp and sw:
if tmp%j==0 and j!=i and (tmp//j)!=i:
print("YES")
print(i,j,tmp//j)
sw = 0
j += 1
i += 1
if sw:
print("NO")
if __name__ == "__main__":
main()
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t = int(input())
for i in range(t):
n = int(input())
a = 1
for i in range(2,1001):
if n % i == 0:
a = i
break
if a == 1:
print("NO")
continue
n //= a
b = 1
c = 1
for i in range(a+1,int(n**0.5)+1):
if n % i == 0 and i ** 2 != n:
b = i
c = n // i
break
if b == 1:
print("NO")
continue
print("YES")
print(a,b,c)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t = int(input())
for i in range(t):
n = int(input())
ans = []
for j in range(2, int(math.sqrt(n)) + 1):
if n % j == 0:
ans.append(j)
n //= j
if len(ans) == 2:
ans.append(n)
break
if len(ans) != 3:
print("NO")
elif ans[1] >= ans[2]:
print("NO")
else:
print("YES")
print(*ans)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from sys import stdin
inp = stdin.readline
t = int(inp())
for i in range(t):
n = int(inp())
a = b = 0
for j in range(2, int(n**0.5) + 1):
if n % j == 0:
if a == 0:
a = j
n //= j
elif b == 0:
b = j
n//=j
break
if a!= 0 and b != 0 and n != a and n!= b:
print("YES")
print(a,b,n)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | def else1(N):
for a in range(2, int(N ** (1. / 3)) + 1):
for b in range(a + 1, int((N // a) ** 0.5) + 1):
c = N // a // b
if a * b * c == N and c != a and c != b:
print('YES')
print(a, b, c)
return
else:
print('NO')
def main():
t = int(input())
for i in range(t):
N = int(input())
L = []
if N ** (1./3) < 0.9:
print('NO')
else:
else1(N)
main()
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | def dividened(number,dict1):
for i in range(2,int((number)**(1/2))+1):
if number%i==0 and dict1.get(i)==None:
dict1[i] = 1
return number//i,i,dict1
return 1,number,dict1
for _ in range(int(input())):
number = int(input())
d = []
case= True
dict1 = {}
for i in range(2):
number,op,dict1= dividened(number,dict1)
if number==1 :
print("NO")
case = False
break
else:
d.append(op)
if dict1.get(number)==None:
d.append(number)
else:
case = False
print("NO")
if case:
print("YES")
print(*d)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def primeFactors(n):
mm=n+1
d=dict()
count=0
while n % 2 == 0:
count+=1
n = n // 2
if count!=0:
d[2]=count
# print("Intermediate n",n)
for i in range(3,int(math.sqrt(n))+1,2):
icount=0
while n % i== 0:
# print i,
n = n // i
icount+=1
# print("Andar")
# print("Intermediate icount",icount)
if icount!=0:
d[i]=icount
# print("Assigned")
if n > 2:
# print n
d[n]=1
n=mm-1
li=[]
for i in d:
# print(i,d[i])
li.append(i)
# print(len(d))
if len(d)>=3:
print("YES")
num1=li[0]
num2=li[1]
num3=n//num1
num3=num3//num2
print(num1,num2,num3)
elif len(d)==2:
anss=0
for i in d:
anss+=d[i]
if anss>=4:
print("YES")
fi=li[0]
se=li[1]
print(fi,se,(n//fi)//se)
else:
print("NO")
else:
anss=0
for i in d:
anss+=d[i]
if anss>=6:
print("YES")
num1=li[0]
num2=num1**2
num3=num1**3
print(num1,num2,(n//num1)//num2)
else:
print("NO")
t=int(input())
for i in range(0,t):
n=int(input())
primeFactors(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 | ''' ===============================
-- @uthor : Kaleab Asfaw
-- Handle : kaleabasfaw2010
-- Bio : High-School Student
==============================='''
# Fast IO
import sys
import os
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")
# Others
# from math import floor, ceil, gcd
# from decimal import Decimal as d
mod = 10**9+7
def lcm(x, y): return (x * y) / (gcd(x, y))
def fact(x, mod=mod):
ans = 1
for i in range(1, x+1): ans = (ans * i) % mod
return ans
def arr2D(n, m, default=0):
lst = []
for i in range(n): temp = [default] * m; lst.append(temp)
return lst
def sortDictV(x): return {k: v for k, v in sorted(x.items(), key = lambda item : item[1])}
def findFactor(n):
lst = set()
for i in range(2, int(n ** 0.5) + 1):
if n % i == 0:
lst.add(i)
lst.add(n//i)
return list(lst)
def solve(n):
for i in findFactor(n):
for j in findFactor(i):
a = j
b = i // j
c = n // i
if a != b and b != c and a != c:
print("YES")
return str(a) + " " + str(b) + " " + str(c)
return "NO"
for _ in range(int(input())): # Multicase
n = int(input())
print(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 | from math import sqrt
def factorize3(n):
f, s = 1, 1
for i in range(2, int(sqrt(n)) + 1):
if n % i == 0:
f = i
n = n // i
break
for i in range(f + 1, int(sqrt(n)) + 1):
if n % i == 0:
s = i
n = n // i
break
if s != n and f != 1 and s != 1:
print("YES")
print(f, s, n)
else:
print("NO")
test_size = int(input())
for i in range(test_size):
n = int(input())
factorize3(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 | from math import sqrt
t = int(input())
for ti in range(t):
n = int(input())
try:
a = 0
b = 0
c = 0
for i in range(2,int(sqrt(n))+1):
if n % i == 0:
a = i
break
# a is 1st factor
for i in range(2,int(sqrt(n/a))+1):
if int(n/a) % i == 0 and i != a:
b = i
c = int(n/(a*b))
if c == b:
raise Exception
break
if a == 0 or b == 0 or c == 0:
raise Exception
else:
print("YES")
print(a,b,c)
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 | """
NTC here
"""
import sys
inp= sys.stdin.readline
input = lambda : inp().strip()
flush= sys.stdout.flush
# import threading
# sys.setrecursionlimit(10**6)
# threading.stack_size(2**25)
def iin(): return int(input())
def lin(): return list(map(int, input().split()))
# range = xrange
# input = raw_input
def factors(a):
fact = []
if a % 2 == 0:
ch = 0
while a % 2 == 0:
ch += 1
a //= 2
fact.extend([2]*ch)
i = 3
while i*i <= a:
if a % i == 0:
ch = 0
while a % i == 0:
ch += 1
a //= i
fact.extend([i]*ch)
i += 2
if a > 1:
fact.append(a)
return fact
def main():
t = iin()
ans = ['YES', "NO"]
while t:
t-=1
n = iin()
fct = factors(n)
if len(fct)>=3:
l = len(fct)
a, b= fct[0], fct[1]
c = 1
if b==a:
if l>3:
b*=fct[2]
for i in range(3, l):
c *= fct[i]
else:
print(ans[1])
continue
else:
for i in range(2, l):
c *= fct[i]
if a!=b and b!=c and c!=a:
print(ans[0])
print(a, b, c)
continue
print(ans[1])
main()
# threading.Thread(target=main).start()
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | # A Better (than Naive) Solution to find all divisiors
import math
# method to print the divisors
def printDivisors(n) :
fact = []
# Note that this loop runs till square root
i = 1
while i <= math.sqrt(n):
if (n % i == 0) :
# If divisors are equal, print only one
if (n / i == i) :
fact.append(i)
else :
# Otherwise print both
fact.append(i)
fact.append(n//i)
i = i + 1
fact.sort()
return fact[1:]
for _ in range(int(input())):
n=int(input())
f1=printDivisors(n)
a=f1[0]
if len(f1)==1 or len(f1)==2:
print("NO")
continue
f2 = printDivisors(n//a)
try:
f2.remove(a)
except:
pass
b = f2[0]
c= n//(a*b)
if (a>1 and b>1 and c>1 and a!=b and b!=c and a!=c):
print("YES")
print(a,b,c)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def func(N,x):
val = N**0.5
val = int(val)+1
tem = 0
for i in range(x+1,val):
if(N%i==0):
if(N//i>1 and N//i!=i):
print("YES")
print(x,i,N//i)
tem = 1
break
if(tem==0):
print("NO")
for _ in range(int(input())):
N = int(input())
val = N**0.5
val = int(val)+1
temp=0
for i in range(2,val):
if(N%i==0):
if(N//i!=i):
temp=1
func(N//i,i)
break
if(temp==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 math
def divisorGenerator(n):
large_divisors = []
for i in range(1, int(math.sqrt(n) + 1)):
if n % i == 0:
yield i
if i*i != n:
large_divisors.append(n / i)
for divisor in reversed(large_divisors):
yield divisor
def solver(k):
divs = list(divisorGenerator(k))[1:-1]
if len(divs) > 0:
a = int(divs[0])
second_divs = [el for el in list(divisorGenerator(k//a))[1:-1] if el > a]
if len(second_divs) > 0:
b = int(second_divs[0])
c = int(k // b // a)
if k % (b * a) == 0 and c > b:
print('yes')
print(f'{a} {b} {c}')
else:
print('no')
else:
print('no')
else:
print('no')
n = int(input())
for i in range(n):
k = int(input())
solver(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 | #include <bits/stdc++.h>
using namespace std;
template <class T>
using minheap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
void setmax(T& a, T b) {
a = max(a, b);
};
template <typename T>
void setmin(T& a, T b) {
a = min(a, b);
};
int getPow(int a, int b) {
int p = 1;
for (int i = 0; i < b; i++) p *= a;
return p;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while (t--) {
map<int, int> fac;
int n;
cin >> n;
int cpy = n;
for (long long i = 2; i * i <= n; i++) {
while (n % i == 0) {
fac[i]++;
n /= i;
}
}
if (n > 1) {
fac[n]++;
}
n = cpy;
if (fac.size() == 1) {
auto [p, e] = *fac.begin();
if (e < 6) {
cout << "NO\n";
} else {
cout << "YES\n";
cout << p << " " << p * p << " " << (n / (p * p * p)) << '\n';
}
} else if (fac.size() == 2) {
auto x = *fac.begin();
auto y = *fac.rbegin();
int p = x.first, e = x.second;
int q = y.first, u = y.second;
if (e > u) {
swap(p, q);
swap(e, u);
}
if ((e == 1 && u == 1) || (e == 1 && u == 2)) {
cout << "NO\n";
} else {
cout << "YES\n";
if (u == 2) {
cout << q << " " << (q * p) << " " << p << '\n';
} else {
cout << q << " ";
cout << getPow(q, u - 1) << " ";
cout << getPow(p, e) << " ";
}
}
} else {
vector<int> vals(3, 1);
int i = 0;
for (auto [p, e] : fac) {
vals[(i++) % 3] *= getPow(p, e);
}
cout << "YES\n";
for (int x : vals) cout << x << " ";
cout << '\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 | #code by rb
import math
for tt in range(int(input())):
nvar=int(input())
flag=False
for i in range(2,int(math.sqrt(nvar))+1):
if nvar%i==0:
x=i
yy=nvar//i
for j in range(i+1,int(math.sqrt(yy))+1):
if yy%j==0:
y=j
z=yy//j
if z>=2 and z!=y and z!=x:
flag=True
l=[x,y,z]
print("YES")
print(*l)
break
if flag:
break
if flag==False:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | def findprimefactors(n):
l=[]
while(n%2==0):
l.append(2)
n//=2
for i in range(3,int(n**.5)+1,2):
while(n%i==0):
n//=i
l.append(i)
if n>2:
l.append(n)
return l
for _ in range(int(input())):
n=int(input())
k=findprimefactors(n)
l=set(k)
z=len(l)
if z>=3:
print("YES")
l=list(l)
prod=l[0]*l[1]
prod1=1
print(*l[:2],end=" ")
for i in k:
prod1*=i
print(prod1//prod)
elif z==2:
if len(k)<4:
print("NO")
else:
prod=1
print("YES")
l=list(l)
prod1=1
for i in l:
print(i,end=" ")
prod*=i
for i in k:
prod1*=i
print(prod1//prod)
elif z==1:
prod=1
if len(k)>5:
print("YES")
print(k[0],k[1]*k[2],end=" ")
for i in k[3:]:
prod*=i
print(prod)
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 = int(input())
ok = False
c = 2
while not ok and c*c*c <= n:
if n % c != 0:
c += 1
continue
# a * b = n / c
# a > b > c
b = c+1
while not ok and b*b <= (n // c):
if (n // c) % b != 0:
b += 1
continue
a = n // (c * b)
if a > b:
print('YES')
print(a, b, c)
ok = True
b += 1
c += 1
if not ok:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
const int N = 1000002;
const double PI = 4 * atan(1);
const double eps = 1e-7;
const long long oo = 1e18;
vector<pair<long long, long long> > v;
long long t;
long long n;
int main() {
ios::sync_with_stdio(0);
cin >> t;
while (t--) {
cin >> n;
vector<long long> v;
long long x = sqrt(n);
for (int i = 2; i <= x; i++) {
if (n % i == 0) {
v.push_back(i);
n /= i;
if (v.size() == 2) break;
}
}
if (n >= 2 && v.size() == 2 && n != v[0] && n != v[1]) {
cout << "YES\n";
cout << v[0] << " " << v[1] << " " << n << endl;
} else {
cout << "NO\n";
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
for _ in range(int(input())):
n = int(input())
d = set()
for i in range(2, int(math.sqrt(n)) + 1):
if len(d) >= 2:
break
if n % i == 0:
d.add(i)
n = n // i
if len(d) < 2 or n == 1 or n in d:
print("NO")
else:
print("YES")
for t in d:
print(t, end = ' ')
print(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 | #C. Product of Three Numbers
from math import sqrt,ceil
for _ in range(int(input())):
n = int(input())
uniq = set()
for i in range(2,ceil(sqrt(n))):
if n%i == 0 :
uniq.add(i)
n /= i
break
#print(uniq,sqrt(n))
for i in range(2,ceil(sqrt(n))):
if n%i == 0 and (i not in uniq):
uniq.add(i)
n /= i
break
#print(uniq)
if len(uniq)<2 or (n in uniq) or n == 1:
print("NO")
else:
print("YES")
uniq.add(int(n))
print(*uniq) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible 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 factors(n):
ret = []
while n % 2 == 0:
ret.append(2)
n = n // 2
for i in range(3, int(math.sqrt(n)) + 1, 2):
while n % i == 0:
ret.append(i)
n = n // i
if n > 2:
ret.append(n)
return ret
for _ in range(int(input())):
n = int(input())
pf = factors(n)
s = set()
if len(pf)<3:
print("NO")
elif len(pf)==3 and len(set(pf))==3:
print("YES")
l = map(str,pf)
print(" ".join(l))
else:
s.add(pf[0])
cnt = pf[1]
i = 2
while cnt in s:
cnt*=pf[i]
i+=1
s.add(cnt)
last = 1
while i < len(pf):
last*=pf[i]
i+=1
if last in s or last<=1:
print("NO")
else:
print("YES")
print("{} {} {}".format(pf[0],cnt,last)) | PYTHON |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | def div(n):
s = set()
for i in range(2, int(n**.5)+2):
if n % i == 0:
s.add(i)
s.add(n // i)
return s
t = int(input())
for _ in range(t):
n = int(input())
s = list(div(n))
s.sort()
if len(s) > 2:
found = 0
a = b = c = 0
d = len(s)
for i in range(d):
for j in range(i + 1, d):
if n % (s[i] * s[j]) == 0:
g = n // (s[i] * s[j])
if g != s[i] and g != s[j] and g >= 2:
found = 1
a = s[i]
b = s[j]
c = g
break
if found:
break
if found:
print('YES')
print(a, b, c)
else:
print('NO')
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from collections import defaultdict as dd
def facts(x):
f=set()
for i in range(2,int(x**0.5)+1):
if x%i==0:
f.add(i)
f.add(x//i)
return list(f)
for _ in range(int(input())):
n=int(input())
fac=facts(n)
if len(fac)<3:
print('NO')
else:
have=dd(lambda:False)
root=n**0.5
for x in fac:
have[x]=True
done=False
for i in range(len(fac)):
for j in range(i+1,len(fac)):
x,y=fac[i],fac[j]
z=n//(x*y)
if z==x or z==y:
continue
if have[z]==True and x*y*z==n:
done=True
print('YES')
print(x,y,z)
break
if done:
break
if not done:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def getnumbers(n):
divisor=[]
while n % 2 == 0:
divisor.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:
divisor.append(int(i)),
n = n / i
# Condition if n is a prime
# number greater than 2
if n > 2:
divisor.append(int(n))
# Initialize the variables with 1
a, b, c, size = 0, 0, 0, 0
a = b = c = 1
size = len(divisor)
for i in range(size):
# check for first number a
if (a == 1):
a = a * divisor[i]
# check for second number b
elif (b == 1 or b == a):
b = b * divisor[i]
# check for third number c
else:
c = c * divisor[i]
# check for all unwanted condition
if (a == 1 or b == 1 or c == 1
or a == b or b == c or a == c):
print('NO')
else:
print("YES")
print(a, b, c)
# Driver function
for i in range(int(input())):
n =int(input())
getnumbers(n)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n;
cin >> t;
for (int p = 0; p < t; p++) {
cin >> n;
vector<int> ans;
for (int i = 2; i <= sqrt(n); i++) {
if (ans.size() == 2) break;
if (n % i == 0) {
ans.push_back(i);
n /= i;
}
}
auto it = find(ans.begin(), ans.end(), n);
if (it == ans.end() && (n > 1)) ans.push_back(n);
if (ans.size() < 3)
cout << "NO\n";
else {
printf("YES\n%d %d %d\n", ans[0], ans[1], ans[2]);
}
}
}
| 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 as m
def divisor(n):
arr=[]
for i in range(2,int(m.sqrt(n))+1):
if n%i==0:
arr.append(i)
return arr
t=int(input())
for _ in range(t):
n=int(input())
temp=divisor(n)
if temp==[]:
print("NO")
else:
a=temp[0]
n=n//temp[0]
temp=divisor(n)
boo=True
for i in temp:
if i!=a and n%i==0 and n//i!=a and n//i!=i and n//i!=1:
print("YES")
print(a,i,n//i)
boo=False
break
if boo:
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 *
t = int(input())
def check(x):
count = 0
flag = 0
for i in range(2,floor(sqrt(x))+1):
if x%i == 0:
flag = 1
break
if flag!=0:
for j in range(2,floor(sqrt(x/i))+1):
if j!=i and (x/i)%j == 0:
count = 1
break
if count != 0:
if x/(i*j)!=i and x/(i*j)!=1 and x/(i*j)!= j:
return "YES\n"+str(i)+" "+str(j)+" "+str(int(x/(i*j)))
return "NO"
for _ in range(t):
x = int(input())
print(check(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 | n=int(input())
for i in range(n):
m=int(input())
c=2
p=[]
while len(p)<2 and c*c<m:
if m%c==0:
m=m//c
p.append(c)
c+=1
if len(p)==2 and m not in p:
print("YES")
print(*p,m)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from sys import stdin,stdout
for _ in range(int(stdin.readline())):
n=int(stdin.readline())
# a,b,c,n=list(map(int,stdin.readline().split()))
f=2;A=B=C=-1;f1=[]
while f*f<=n:
if n%f==0:
f1+=[f]
f+=1
nn=len(f1)
for i in range(nn):
for j in range(i+1,nn):
c=n//(f1[i]*f1[j])
if c*f1[i]*f1[j]==n and c!=f1[i] and c!=f1[j]:
A,B,C=f1[i],f1[j],c
break
if A==-1:
print('NO')
else:
print('YES')
print(A,B,C) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long p = 0;
long long n;
cin >> n;
long long a, b, c;
for (long long i = 2; i < sqrt(n); i++) {
if (n % i == 0) {
a = i;
p = 1;
break;
}
}
if (p == 0)
cout << "NO" << endl;
else {
long long x = n / a;
p = 0;
for (long long i = a + 1; i < sqrt(x); i++) {
if (x % i == 0 && b / i != a) {
cout << "YES" << endl;
cout << a << " " << i << " " << x / i << endl;
p = 1;
break;
}
}
if (p == 0) 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 math
def prf(x):
a = []
b = 1
n = 2
m = int(math.sqrt(x))
# print(m)
while n <= m:
if x%n == 0:
if not(n in a): a.append(n)
elif not(n*b in a):
a.append(n*b)
b = 1
else: b *= n
x //= n
else:
if n == 2: n += 1
else: n += 2
# print(a, b, x, n)
if len(a) == 2 and not(x*b in a) and x*b>1:
a.append(x*b)
return a
elif len(a) == 3: return a
elif len(a) == 2:
return 'NO'
return 'NO'
n = int(input())
for i in range(n):
x = int(input())
re = prf(x)
if type(re) == type('NO'): print(re)
else:
print('YES')
print(*sorted(re)) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible 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 cal1(n,tmp):
i = 2
while i*i<=n:
if n % i == 0:
if (i != n//i and i != tmp and n//i != tmp):
return (tmp,i,n//i)
i+=1
return (-1,0,0)
def cal(n):
i = 2
while i*i<=n:
if n % i == 0 and n//i != i:
#i, n//i
res ,a,b = cal1(n//i,i)
if res != -1:
return (1,res,a,b)
i+=1
return (0,0,0,0)
for i in range(int(input())):
n = int(input())
res,a,b,c = cal(n)
if res == 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 | def STR(): return list(input())
def INT(): return int(input())
def MAP(): return map(int, input().split())
def MAP2():return map(float,input().split())
def LIST(): return list(map(int, input().split()))
def STRING(): return input()
import string
import sys
from heapq import heappop , heappush
from bisect import *
from collections import deque , Counter , defaultdict
from math import *
from itertools import permutations , accumulate
dx = [-1 , 1 , 0 , 0 ]
dy = [0 , 0 , 1 , - 1]
for tt in range(INT()):
n = INT()
x = []
c = 0
for i in range(2 , int(sqrt(n)) + 1):
if n % i == 0 :
x.append(i)
n//= i
c += 1
if c == 2 :
break
#print(n)
if len(x) < 2 :
print('NO')
else:
if x[0] != n and x[1] != n :
x.append(n)
if len(x) == 3 :
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 | import math
t=int(input())
for i in range(t):
f=False
a=-1
b=-1
c=-1
n=int(input())
primes=set()
st=math.ceil(n**0.5)+1
p=[True]*(st)
for i in range(2,st):
if p[i]:
primes.add(i)
for j in range(i,st,i):
p[j]=False
#print(primes)
for i in range(2,st):
if f:
break
if n%i==0:
a=i
bc=n//i
st1=math.ceil(bc**0.5)+1
if bc not in primes:
for j in range(2,st1):
if j==a:
continue
if bc%j==0 :
if bc//j==a or j==bc//j:
continue
b=j
c=bc//j
f=True
#print(a,b,c)
break
if f:
print("YES")
print(a,b,c)
else:
print("NO")
#print(15*3*4115)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
input = sys.stdin.readline
t=int(input())
import math
def f(x):
xr=math.ceil(math.sqrt(x))
LIST=[]
for i in range(1,xr+1):
if x%i==0:
LIST.append(i)
LIST.append(x//i)
return sorted(set(LIST))[1:]
for test in range(t):
n=int(input())
L=f(n)
A=L[0]
for i in f(n):
if i!=A and i*A<n and n%(i*A)==0 and n//(i*A)!=i and n//(i*A)!=A and n//(i*A)!=1:
print("YES")
print(A,i,n//(i*A))
break
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from collections import defaultdict as dc
from heapq import *
import math
import bisect
from collections import deque as dq
def inp():
p=int(input())
return p
def line():
p=list(map(int,input().split()))
return p
def check(n,d,x):
if x<0:
return 0
return n>=(x+math.ceil(d/(x+1)))
def unique(a,b,c):
p=set()
p.add(a)
p.add(b)
p.add(c)
if len(p)==3:
return 1
return 0
def bs(a,n,z,val):
l=0
r=n
while(l<r):
mid=(l+r)//2
if val%(a*z[mid])==0 and val//(a*z[mid])!=1:
#print(a,z[mid])
if(unique(a,z[mid],val//(a*z[mid]))):
return mid
if val>(a*z[mid]):
l=mid+1
else:
r=mid-1
if val%(a*z[mid])==0 and val//(a*z[mid])!=1:
if(unique(a,z[mid],val//(a*z[mid]))):
return mid
return -1
for _ in range(inp()):
a=inp()
z=[]
for i in range(2,int(pow(a,0.5))+1):
if a%i==0:
z.append(i)
if(i!=a//i):
z.append(a//i)
z.sort()
k=0
for i in range(len(z)):
l=z[i]
ans=bs(l,len(z),z,a)
if ans!=-1:
print('YES')
print(l,z[ans],a//(l*z[ans]))
k=1
break
if k==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 | #1294C
t = int(input())
for i in range(t):
n = int(input())
ans = []
for i in range(2,int(n**(2/3))+1):
if len(ans) == 2:
break
if n%i == 0:
ans.append(i)
n = n//i
if len(ans) == 2 and ans[1] < n:
print('YES')
print(*ans, n)
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for _ in range(int(input())):
n=int(input())
m=n
l=[]
t=1
f=0
g=0
if n<8:
print("NO")
else:
for i in range(2,int(n**0.5)+1):
if n%i==0:
if not l:
l.append(i)
f=1
break
# print(l)
if f==1:
n=n//l[-1]
for i in range(l[-1],int(n**0.5)+1):
while n%i==0:
if l[-1]==t*i:
t=t*i
else:
l.append(t*i)
# print(l)
n=n//i
g=1
break
n=n//i
if g==1:
break
if len(l)<2:
# print(l)
if t==1 or t==l[-1]:
print("NO")
else:
l.append(t)
m=m//(l[0]*l[1])
# print(l)
if m>=2:
l.append(m)
s=set(l)
if len(s)<len(l) or len(l)<=2:
print("NO")
else:
print("YES")
print(" ".join(map(str,l)))
else:
m=m//(l[0]*l[1])
if m>=2:
l.append(m)
# print(l)
s=set(l)
if len(s)<len(l) or len(l)<=2:
print("NO")
else:
print("YES")
print(" ".join(map(str,l)))
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
public class C {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
//make(T);;
while (T-->0)
{
int N = sc.nextInt();
HashSet<Long> values = new HashSet<>();
values.add(1l);
long current_i = 1 ;
int sqrt = (int)Math.sqrt(N);
for(int i = 2 ; i <= sqrt && values.size()<3; i++)
{
while (N>0 && N%i==0 && values.size()<3)
{
if(!values.contains(current_i))
{
values.add(current_i);
current_i = 1;
}else {
current_i*=i;
N/=i;
}
if(N==0)
break;
}
}
if(!values.contains(current_i))
values.add(current_i);
if(N > 1)
values.add((long)N);
values.remove(1l);
if(values.size()<3)
{
System.out.println("NO");
}else {
TreeSet<Long> set = new TreeSet<>(values);
while(set.size()>3)
{
set.add(set.pollLast()*set.pollLast());
}
StringBuilder bw = new StringBuilder();
System.out.println("YES");
for (long a :
set) {
bw.append(a+" ");
}
bw.deleteCharAt(bw.length()-1);
System.out.println(bw);
}
}
}
private static boolean bf(int a)
{
for(int i = 2 ; i < a ;i++)
{
for(int j = i+1 ; j < a ;j++)
{
int ab = i*j;
int dev = a/ab;
if(a%ab==0 && dev!=i && dev>j)
{
return true;
}
}
}
return false;
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
import math
from functools import reduce
def getN():
return int(input())
def getNM():
return map(int, input().split())
def getList():
return list(map(int, input().split()))
def getArray(intn):
return [int(input()) for i in range(intn)]
def input():
return sys.stdin.readline().rstrip()
def factorize(n):
factors = []
for i in range(2, int(math.sqrt(n) + 1)):
while n % i == 0:
factors.append(i)
n //= i
if n != 1:
factors.append(n)
return factors
for _ in range(int(input())):
n = getN()
factors = factorize(n)
if len(factors) < 3:
print("NO")
continue
if factors[0] == factors[1]:
factors[1] = factors[1] * factors[2]
factors.pop(2)
if len(factors) < 3:
print("NO")
continue
factors[2] = reduce((lambda x, y: x * y), factors[2:])
if len(set(factors)) < 3:
print("NO")
continue
print("YES")
print(*factors[: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 java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
public static void main (String[] args) throws java.lang.Exception
{
// your code goes here
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in));
int t=Integer.parseInt(buf.readLine());
StringBuilder sb=new StringBuilder();
for(int j=0;j<t;j++)
{
long n=Long.parseLong(buf.readLine());
long max=(long)(Math.ceil(Math.sqrt(n)));
int flag1=0,flag2=0;
long a=0,b=0,c=0;
for(long i=2;i<=max;i++)
{
if(n%i==0)
{
flag1=1;
a=i;
break;
}
}
if(flag1==0)
sb.append("NO"+"\n");
else
{
long r=n/a;
long max2=(long)(Math.ceil(Math.sqrt(r)));
for(long i=2;i<=max2;i++)
{
if(r%i==0 && i!=a)
{
flag2=1;
b=i;
break;
}
}
if(flag2==0)
sb.append("NO"+"\n");
else
{
long div=a*b;
if(n%div==0)
{
long g=n/div;
if(g!=a && g!=b && g!=1)
{
c=g;
sb.append("YES"+"\n"+a+" "+b+" "+c+"\n");
}
else
sb.append("NO"+"\n");
}
else
sb.append("NO"+"\n");
}
}
}
System.out.println(sb);
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int t;
cin >> t;
while (t--) {
long long int n, cp = 0;
cin >> n;
vector<long long int> v1;
long long int i;
for (i = 2; i <= sqrt(n); i++) {
if (n % i == 0 && n / i != i) {
v1.push_back(i);
cp++;
n /= i;
break;
}
}
if (!cp)
cout << "NO" << endl;
else {
for (long long int j = sqrt(n); j > i; j--) {
if (n % j == 0 && n / j != j) {
v1.push_back(j);
v1.push_back(n / j);
break;
}
}
if (v1.size() == 3) {
cout << "YES" << endl;
cout << v1[0] << " " << v1[1] << " " << v1[2] << 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 | import sys
from math import *
input=sys.stdin.readline
from math import *
t=int(input())
while t>0:
t-=1
n=int(input())
d={}
for i in range(2,int(ceil(sqrt(n)))+1):
if n%i==0:
d[i]=0
while n%i==0:
n//=i
d[i]+=1
if n>2:
d[n]=1
if len(d)>=3:
a=[]
for i in d:
a.append(i**d[i])
a.sort(reverse=True)
p=a[0]
q=a[1]
s=1
for k in range(2,len(a)):
s*=a[k]
print("YES")
print(p,q,s)
continue
elif len(d)==2:
a=[]
s=0
for i in d:
s+=d[i]
if s<=3:
print("NO")
continue
s=1
for i in d:
a.append(i)
s*=i**(d[i]-1)
a.sort()
p=a[0]
q=a[1]
print("YES")
print(p,q,s)
else:
c=0
a=[]
for i in d:
if 6>d[i]>=3:
a.append(i)
d[i]-=1
a.append(i**(d[i]))
elif d[i]>=6:
a.append(i)
a.append(i**2)
a.append(i**(d[i]-3))
else:
a.append(i**d[i])
if len(a)<3:
print("NO")
continue
a.sort(reverse=True)
p=a[0]
q=a[1]
s=1
for k in range(2,len(a)):
s*=a[k]
print("YES")
print(p,q,s)
continue | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t = int(input())
import math
while t:
n = int(input())
s = int(math.sqrt(n) + 10)
ans = []
for i in range(s)[2:]:
if n % i == 0 and len(ans) < 2:
ans.append(i)
n //= i
if len(ans) == 2 and ans[1] < n:
ans.append(n)
if len(ans) == 3:
print("YES")
print(ans[0], ans[1], ans[2], sep=' ')
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):
output=[]
while n % 2 == 0:
output.append(2)
n = n / 2
for i in range(3,int(math.sqrt(n))+1,2):
while n%i==0:
output.append(i)
n = n / i
if n > 2:
output.append(int(n))
return output
t=int(input())
for g in range(0,t):
n=int(input())
a=primeFactors(n)
a.sort()
output=1
i=1
x=y=z=0
x=a[0]
if(len(a)==1):
output=0
if(output==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:
output=0
if(output==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 | from __future__ import division, print_function
import os
import sys, math
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
prime = []
def pp(n):
while n%2 == 0:
n /= 2
prime.append(2)
import math
k = int(math.sqrt(n))
for i in range(3, k+1):
if n%i == 0:
while n%i == 0:
n /= i
prime.append(i)
if n > 2:
prime.append(n)
def main():
t = int(input())
while t:
t -= 1
n = int(input())
prime.clear()
pp(n)
if len(prime) < 3:
print("NO")
continue
ok = True
a = prime[0]
b = prime[1]
c = 1
for i in range(2, len(prime)):
c *= prime[i]
if b == a:
b *= prime[2]
c /= prime[2]
if len(prime) < 4 or c == a or c == b:
print("NO")
continue
print("YES")
c = int(c)
print(a, b, c)
elif b == c:
print("NO")
else:
print("YES")
c = int(c)
print(a, b, c)
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main() | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #!/usr/bin/python3
import math
di = dict()
def couns(x,n):
z = int(math.sqrt(n))
for i in range(x, z+2):
if n%i == 0:
return i
return 1
def countofmul(n):
#if n in di:
# return di[n]
li = list()
i = 2
val = 0
while n >= 2:
i = couns(i, n)
if i != 1:
li.append(i)
n = n // i
#print(li)
if len(li) == 3:
li[-2] *= li[-1]
li.remove(li[-1])
if len(li) == 2:
if li[0] != li[1] and li[1] != n and li[0] != n and n != 1:
li.append(n)
return li
else:
return []
return []
"""
while n >= 2:
i = couns(n)
if i not in li and i != 1:
n = int(n/i)
li.append(i)
if len(li) == 2:
if n not in li and n != 1:
li.append(n)
return li
else:
i += 1
if i == n:
return li
return li
"""
n = int(input())
for i in range(n):
x = int(input())
r = countofmul(x)
#print(r)
if len(r) >= 3:
a = r[0]
b = r[1]
c = r[2]
print("YES")
print(a,b,c)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long t;
cin >> t;
while (t--) {
long long n, i;
cin >> n;
vector<long long> v;
map<long long, long long> mp;
while (n % 2 == 0) {
v.push_back(2);
mp[2]++;
n = n / 2;
}
for (i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
v.push_back(i);
mp[i]++;
n = n / i;
}
}
if (n > 2) {
v.push_back(n);
mp[n]++;
}
if (v.size() < 6 && mp.size() == 1)
cout << "NO\n";
else {
if (mp.size() == 3 && v.size() == 3) {
cout << "YES\n" << v[0] << " " << v[1] << " " << v[2] << endl;
} else {
long long ans1 = v[1], ans2 = 1;
i = 2;
while (ans1 == v[0]) {
ans1 = ans1 * v[i];
i++;
}
while (i < v.size()) {
ans2 = ans2 * v[i];
i++;
}
if (ans1 == v[0] || ans2 == v[0] || ans1 == ans2 || v[0] == 1 ||
ans1 == 1 || ans2 == 1)
cout << "NO\n";
else
cout << "YES\n" << v[0] << " " << ans1 << " " << ans2 << endl;
}
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
import math
input = sys.stdin.readline
ins = lambda: input().rstrip()
ini = lambda: int(input().rstrip())
inm = lambda: map(int, input().split())
inl = lambda: list(map(int, input().split()))
t = ini()
for _ in range(t):
n = ini()
i = 2
tmp = []
while n >= i * i:
if i == 5 and n % 5 == 0 and 4 in tmp:
tmp.remove(4)
if n % i == 0:
tmp.append(i)
if len(tmp) == 3:
break
i += 1
if len(tmp) <= 1:
print("NO")
elif len(tmp) >= 2:
if len(tmp) == 3:
y = (n / (tmp[0] * tmp[2])).is_integer()
if tmp[0] * tmp[1] * tmp[2] == n:
print("YES")
print(tmp[0], tmp[1], tmp[2])
continue
elif y and n / (tmp[0] * tmp[2]) not in tmp:
print("YES")
print(tmp[0], tmp[2], n // (tmp[0] * tmp[2]))
continue
x = (n / (tmp[0] * tmp[1])).is_integer()
if x and n / (tmp[0] * tmp[1]) not in tmp:
print("YES")
print(tmp[0], tmp[1], n // (tmp[0] * tmp[1]))
else:
print("NO")
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
template <class T>
void printArray(vector<T> arr) {
for (T a : arr) cout << a << " ";
cout << '\n';
}
void printVerdict(bool verdict) { cout << (verdict ? "YES" : "NO") << '\n'; }
vector<long long> findPrime(long long n) {
vector<long long> ret;
for (int i = 2; i * i <= n && ret.empty(); i++) {
if (n % i == 0) ret.push_back(i);
}
if (ret.empty()) return {};
for (int i = 2; i * i <= n / ret.front(); i++) {
if ((n / ret.front()) % i == 0 && i != ret.front()) {
ret.push_back(i);
break;
}
}
ret.push_back((n / ret.front()) / ret.back());
if (ret.back() == ret[0] || ret.back() == ret[1]) return {};
return ret;
}
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0);
int t;
cin >> t;
while (t--) {
long long n;
cin >> n;
bool verdict = true;
vector<long long> ret = findPrime(n);
if (ret.empty()) verdict = false;
printVerdict(verdict);
if (verdict) printArray(ret);
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
set<int> used;
for (int i = 2; i * i < n; i++) {
if (n % i == 0 && !used.count(i)) {
used.insert(i);
n /= i;
break;
}
}
for (int i = 2; i * i < n; i++) {
if (n % i == 0 && !used.count(i)) {
n /= i;
used.insert(i);
break;
}
}
if (used.size() < 2 || used.count(n) || n == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
used.insert(n);
for (auto i : used) cout << i << " ";
cout << endl;
}
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin >> t;
for (int tt = 0; tt < t; tt++) {
int n;
cin >> n;
set<int> used;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0 && !used.count(i)) {
used.insert(i);
n /= i;
break;
}
}
for (int i = 2; i * i <= n; i++) {
if (n % i == 0 && !used.count(i)) {
used.insert(i);
n /= i;
break;
}
}
if (used.size() < 2 || used.count(n) || n == 1) {
cout << "NO\n";
} else {
cout << "YES\n";
used.insert(n);
for (auto v : used) cout << v << " ";
cout << '\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.ArrayList;
import java.util.List;
import java.util.Scanner;
import static java.lang.Math.sqrt;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
//int n = 100;
List<Long> set = new ArrayList<>();
for (int i = 0; i < n; i++) {
set.add(scanner.nextLong());
//set.add((long)999999901 + i);
}
set.forEach(number -> {
int a = 0;
int b = 0;
int c = 0;
long t = 0;
int g =(int) sqrt(number);
for (int i = 2; i < number / i; i++) {
if (number % i == 0) {
a = i;
t = number / a;
break;
}
}
if (t != 0) {
int h = (int)(number / a);
for (int i = a + 1; i < h / i; i++) {
if (t % i == 0) {
b = i;
break;
}
}
}
if (a != 0 && b != 0) {
c = (int) (number / a) / b;
if (c == a || c == b || c < 2) {
System.out.println("NO");
return;
}
}
if (a != 0 && b != 0 && c != 0) {
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 | # Product of three numbers
from math import *
for i in range(int(input())):
num = int(input())
if 2*3*4 > num:
print("NO")
else:
a,b = 0,0
for i in range(2, int(sqrt(num))+1):
if num % i == 0:
a = i
num //= i
break
for i in range(2, int(sqrt(num))+1):
if num % i == 0 and i != a:
b = i
num//= i
break
if a==0 or b==0 or num==b or num ==a:
print("NO")
else:
print("YES")
print(a,b,num)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.*;
import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.geom.*;
import java.math.*;
import java.text.*;
import java.math.BigInteger.*;
import java.util.Arrays;
public class getbackintoit
{
BufferedReader in;
StringTokenizer as;
int nums[],nums2[];
Map<Integer,Integer > map = new HashMap<Integer, Integer>();
ArrayList < Integer > ar = new ArrayList < Integer >();
ArrayList < Long > ar2 = new ArrayList < Long >();
public static void main (String[] args)
{
new getbackintoit ();
}
public getbackintoit ()
{
try
{
in = new BufferedReader (new InputStreamReader (System.in));
int a = nextInt();
for(int xx1 = 0;xx1<a;xx1++)
{
int times = 0;
String out = "";
int b = nextInt();
for(int x = 2;x*x <b;x++)
{
if(b % x == 0)
{
out += x + " ";
times++;
b = b/x;
}
if(times == 2)
{
out += b;
break;
}
}
if(times ==2 )
System.out.println("YES" + '\n' + out);
else
System.out.println("NO");
}
}
catch(IOException e)
{
}
}
String next () throws IOException
{
while (as == null || !as.hasMoreTokens ())
{
as = new StringTokenizer (in.readLine ().trim ());
}
return as.nextToken ();
}
long nextLong () throws IOException
{
return Long.parseLong (next ());
}
int nextInt () throws IOException
{
return Integer.parseInt (next ());
}
double nextDouble () throws IOException
{
return Double.parseDouble (next ());
}
String nextLine () throws IOException
{
return in.readLine ().trim ();
}
} | 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())
a = 2
tr = False
cnt=0
ans=[]
while (a*a<=n) and (cnt<2):
if n%a==0:
n=n//a
ans.append(a)
cnt+=1
a+=1
ans.append(n)
if (len(ans)==3) and (ans[1] < ans[2]):
print ('YES')
print (*ans)
else:
print ('NO') | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for i in range(int(input())):
from math import sqrt
# Function to find the required triplets
def findTriplets(x):
# To store the factors
fact = [];
factors = set();
# Find factors in sqrt(x) time
for i in range(2, int(sqrt(x))):
if (x % i == 0):
fact.append(i);
if (x / i != i):
fact.append(x // i);
factors.add(i);
factors.add(x // i);
found = False;
k = len(fact);
for i in range(k):
# Choose a factor
a = fact[i];
for j in range(k):
# Choose another factor
b = fact[j];
# These conditions need to be
# met for a valid triplet
if ((a != b) and (x % (a * b) == 0)
and (x / (a * b) != a)
and (x / (a * b) != b)
and (x / (a * b) != 1)):
# Print the valid triplet
print("YES")
print(a, b, x // (a * b));
found = True;
break;
# Triplet found
if (found):
break;
# Triplet not found
if (not found):
print("NO");
# Driver code
if __name__ == "__main__":
x = int(input());
findTriplets(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 | def petit(a,k):
for i in range(a+1,int(k**0.5)+1):
if k%i==0:
return i, k//i
return -1, -1
n = int(input())
for i in range(n):
k = int(input())
a1, k2 = petit(1, k)
if a1==-1:
print('NO')
else:
a2, a3 = petit(a1,k2)
if a2==-1:
print('NO')
elif (a2 == a3) or (a3 == a1):
print('NO')
else:
print('YES')
print(a1, a2, a3) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math as mt
def func(n):
a=[]
while(n%2==0):
a.append(2)
n=n//2
for i in range(3,mt.ceil(mt.sqrt(n))+1,2):
#print(i)
while(n%i==0):
n=n//i
a.append(i)
if(n>2):
a.append(n)
return a
t=int(input())
for i in range(t):
n=int(input())
C=list(func(n))
X=[]
j=C[0]
X.append(C[0])
h=1
k=1
#print(C)
while(k<len(C) and h<=j):
h=h*C[k]
k+=1
X.append(h)
p=1
if(k>len(C)):
print("NO")
else:
for i in range(k,len(C)):
p=p*C[i]
if(p!=1 and p!=X[0] and p!=X[1]):
X.append(p)
if(len(set(X))==3):
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 | import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class App{
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int t = in.nextInt();
while(t-- > 0){
int n = in.nextInt();
boolean flag = true;
for(int i = 2;i*i < n;i++){
if(n%i == 0){
for(int j = i+1;j*j < n/i;j++){
if((n/i)%j == 0){
flag = false;
System.out.println("YES");
System.out.println(i + " " + j + " " + n/i/j);
i = n;
break;
}
}
}
}
if(flag){
System.out.println("NO");
}
}
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.*;
import java.util.*;
public class Task {
public static void main(String[] args) throws Exception {
new Task().go();
}
PrintWriter out;
Reader in;
BufferedReader br;
Task() throws IOException {
try {
//br = new BufferedReader( new FileReader("input.txt") );
//in = new Reader("input.txt");
in = new Reader("input.txt");
out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
}
catch (Exception e) {
//br = new BufferedReader( new InputStreamReader( System.in ) );
in = new Reader();
out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
}
}
void go() throws Exception {
int t = in.nextInt();
//int t = 1;
while (t > 0) {
solve();
t--;
}
out.flush();
out.close();
}
int inf = 2000000000;
int mod = 1000000007;
double eps = 0.000000001;
int n;
int m;
ArrayList<Integer>[] g;
void solve() throws IOException {
int n = in.nextInt();
ArrayList<Integer> list = new ArrayList<>();
for (int i = 2; i <= Math.sqrt(n); i++)
if (n % i == 0) {
list.add(i);
if (n / i != i) list.add(n / i);
}
for (int x : list)
for (int y : list)
if (x != y && n / x % y == 0) {
int z = n / x / y;
if (z > 1 && z != x && z != y) {
out.println("YES");
out.println(x + " " + y + " " + z);
return;
}
}
out.println("NO");
}
class Pair implements Comparable<Pair> {
int a;
int b;
Pair(int a, int b) {
this.a = a;
this.b = b;
}
public int compareTo(Pair p) {
if (a != p.a)
return Integer.compare(a, p.a);
else
return Integer.compare(b, p.b);
}
}
class Item {
int a;
int b;
int c;
Item(int a, int b, int c) {
this.a = a;
this.b = b;
this.c = c;
}
}
class Reader {
BufferedReader br;
StringTokenizer tok;
Reader(String file) throws IOException {
br = new BufferedReader( new FileReader(file) );
}
Reader() throws IOException {
br = new BufferedReader( new InputStreamReader(System.in) );
}
String next() throws IOException {
while (tok == null || !tok.hasMoreElements())
tok = new StringTokenizer(br.readLine());
return tok.nextToken();
}
int nextInt() throws NumberFormatException, IOException {
return Integer.valueOf(next());
}
long nextLong() throws NumberFormatException, IOException {
return Long.valueOf(next());
}
double nextDouble() throws NumberFormatException, IOException {
return Double.valueOf(next());
}
String nextLine() throws IOException {
return br.readLine();
}
}
static class InputReader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public InputReader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public InputReader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String readLine() throws IOException
{
byte[] buf = new byte[64]; // line length
int cnt = 0, c;
while ((c = read()) != -1)
{
if (c == '\n')
break;
buf[cnt++] = (byte) c;
}
return new String(buf, 0, cnt);
}
public int nextInt() throws IOException
{
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
inline long long read() {
long long X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = getchar();
}
while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
return w ? -X : X;
}
inline char power_getchar() {
static char buf[200000], *p1 = buf, *p2 = buf;
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 200000, stdin), p1 == p2)
? EOF
: *p1++;
}
inline long long _read() {
long long X = 0, w = 0;
char ch = 0;
while (!isdigit(ch)) {
w |= ch == '-';
ch = power_getchar();
}
while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = power_getchar();
return w ? -X : X;
}
inline void write(long long x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) write(x / 10);
putchar(x % 10 + '0');
}
int main() {
int T = read();
while (T--) {
long long n = read();
bool f = false;
int sq = 0;
for (int i = 1; i * i * i <= n; i++) sq = i;
for (int i = 2; i <= sq; i++) {
int sqq = sqrt(n / i);
for (int j = i + 1; j <= sqq; j++) {
int tmp = n / i / j;
if (n % i == 0 && (n / i) % j == 0 && (tmp != i && tmp != j) &&
tmp >= 2) {
puts("YES");
printf("%d %d %d\n", i, j, n / i / j);
f = true;
break;
}
}
if (f) break;
}
if (!f) puts("NO");
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from itertools import combinations
from math import sqrt
for _ in range(int(input())):
l=[]
n=int(input())
for i in range(2,int(sqrt(n))+1):
if n%i==0:
if n//i!=i:
l.append(i)
l.append(n//i)
else:
l.append(i)
if len(l)<3:
print("NO")
else:
k=combinations(l,3)
for i in k:
if i[0]*i[1]*i[2]==n:
print("YES")
print(i[0],i[1],i[2])
break
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
test_cases = int(input())
def process():
n = int(input())
for a in range(2, int(math.sqrt(n)) + 1):
for b in range(a + 1, int(math.sqrt(n // a)) + 1):
c = n // (a * b)
if a * b * c == n and c != b and c != a:
print('YES')
print(a, b, c)
return
print('NO')
for i in range(test_cases):
process()
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | // Working program using Reader Class
// Probably fastest
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.List;
import java.util.Collections;
import java.util.Map;
import java.util.HashMap;
import java.util.Comparator;
import java.util.stream.IntStream;
import java.util.ArrayDeque;
import java.util.Set;
import java.util.HashSet;
import java.util.PriorityQueue;
public class Main1 {
private static PrintWriter out = new PrintWriter(System.out);
// private static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
int t = fs.nextInt();
outer :while(t-->0)
{
List<Integer> list = new ArrayList<>();
// Set<Integer> set = new HashSet<>();
int n = fs.nextInt();
int n1 =n;
int count =0;
// int arr[] = new int [1001];
int res[] = new int[2];
int kl = 0;
// int res[] = new int[2];
for(int i=2;i*i<=n;i++)
{
if(n%i==0 &&kl<2)
{
count++;
res[kl] = i;
// System.out.println(i);
kl++;
}
while(n%i==0)
{
list.add(i);
n/=i;
}
}
if(n>1)
{
if(kl==1 && n != res[kl-1])
{
res[kl] = n;
count++;
}
list.add(n);
}
if(list.size()>=6)
{
System.out.println("YES");
int m = list.size();
int a1 = list.get(m-1);
int b1 = list.get(m-2)*list.get(m-3);
int c1 =1;
for(int i=0;i<(m-3);i++)
c1 *= list.get(i);
System.out.println(a1+" "+b1+" "+c1);
}
else if(count>=2)
{
int a = res[0];
int b = res[1];
// System.out.println(a+" "+b);
if(n1%(a*b)==0 && (n1/(a*b)) !=a && (n1/(a*b)) !=b && (n1/(a*b)) !=1)
{
System.out.println("YES");
System.out.println(a+" "+b+" "+(n1/(a*b)));
}
else System.out.println("NO");
}
else System.out.println("NO");
}
}
interface Input {
public String next();
public String nextLine();
public int nextInt();
public long nextLong();
public double nextDouble();
}
static class StdIn implements Input {
final private int BUFFER_SIZE = 1 << 16;
final private int STRING_SIZE = 1 << 11;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public StdIn() {
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public StdIn(String filename) {
try{
din = new DataInputStream(new FileInputStream(filename));
} catch(Exception e) {
throw new RuntimeException();
}
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String next() {
byte[] buf = new byte[STRING_SIZE]; // string length
int cnt = 0, c;
while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r'));
while (c != -1)
{
if (c == ' ' || c == '\n'||c=='\r')
break;
buf[cnt++] = (byte) c;
c=read();
}
return new String(buf, 0, cnt);
}
public String nextLine() {
byte[] buf = new byte[STRING_SIZE]; // line length
int cnt = 0, c;
while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r'));
while (c != -1)
{
if (c == '\n'||c=='\r')
break;
buf[cnt++] = (byte) c;
c = read();
}
return new String(buf, 0, cnt);
}
public int nextInt() {
int ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do
{
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public int[] readIntArray(int n) {
int[] ar = new int[n];
for(int i=0; i<n; ++i)
ar[i]=nextInt();
return ar;
}
public long nextLong() {
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() {
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException {
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() {
try{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
} catch(IOException e) {
throw new RuntimeException();
}
}
public void close() throws IOException {
if (din == null)
return;
din.close();
}
}
private static StdIn fs = new StdIn();
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 |
import java.util.*;
public class C {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int t=in.nextInt();
for(int i=0;i<t;i++){
int n=in.nextInt();
int lasttemp=1;
List<Integer> res=new ArrayList<>();
for(int temp=2;temp<=Math.sqrt(n)&&n!=1;temp++) {
while (n%temp==0) {
res.add(temp);
n /= temp;
}
}
if(n!=1) res.add(n);
List<Integer> integers = get(res);
if(integers.size()>2) {
System.out.println("YES");
System.out.println(integers.get(0) + " " + integers.get(1) + " " + (integers.get(2) * (integers.size()>3?integers.get(3):1)));
}else
System.out.println("NO");
}
}
public static List<Integer> get(List<Integer> list){
List<Integer> res=new ArrayList<>();
int cur=1;
int i;
for(i=0;i<list.size()&&res.size()<3;i++){
cur*=list.get(i);
int j=0;
for(;j<res.size();j++)if(res.get(j)==cur)break;
if(j==res.size()){
res.add(cur);cur=1;
}
}
int temp=1;
for(int j=i;j<list.size();j++)temp*=list.get(j);
if(temp!=1)
res.add(temp);
return res;
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t=int(input())
ans=[]
for _ in range(t):
n=int(input())
fac=[]
count=0
i=2
p=0
z=math.sqrt(n)
while count!=2 and i<z:
if n%i==0:
p=1
fac.append(str(i))
n=n//i
count+=1
i+=1
if str(n) not in fac and len(fac)==2:
ans.append("YES")
fac.append(str(n))
ans.append(' '.join(fac))
else:
ans.append("NO")
for i in ans:
print(i) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def isPrime(n) :
# Corner cases
if (n <= 1) :
return False
if (n <= 3) :
return True
# This is checked so that we can skip
# middle five numbers in below loop
if (n % 2 == 0 or n % 3 == 0) :
return False
i = 5
while(i * i <= n) :
if (n % i == 0 or n % (i + 2) == 0) :
return False
i = i + 6
return True
def print_factors(x):
num=0
fac=1
li=[]
tri=x
for i in range(2, int(math.sqrt(x))+1):
if tri % i == 0:
num+=1
fac = fac*i
li.append(i)
tri = tri/i
if(num==2):
break
if(x%fac==0):
if(int(x/fac)>i):
li.append(int(x/fac))
return li
isp= False
num = int(input())
for i in range(num):
lis=[]
a = int(input())
if(a>=2):
isp = isPrime(a)
if(isp==True):
print("NO")
else:
#print("YES")
lis = print_factors(a)
if(len(lis)==3):
print("YES")
for i in range(2):
print(lis[i],end=" ")
print(lis[i+1])
else:
print("NO")
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def isPrime(n):
for i in range(2,n):
if n % i:
return False
return True
t = int(input())
for _ in range(t):
n = int(input())
if isPrime(n):
print("NO")
else:
ip = False
i = 0
for i in range(2,int(math.sqrt(n)) + 1):
if n % i == 0:
if not isPrime(n // i):
ip = True
break
if ip:
ip = False
for j in range(i+1,int(math.sqrt(n//i)) + 1):
if (n // i) % j == 0:
ip = True
a = i
b = j
c = (n//i)//j
break
if ip and (a !=b and b !=c and a != c):
print("YES")
print(a,b,c)
else:
print("NO")
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
import java.lang.*;
import java.io.*;
public class d {
public static void main (String[] args) {
PrintWriter pw=new PrintWriter(System.out);
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int i=0;i<t;i++){
int n=sc.nextInt();
int s1=0,s2=0,s3=0,f=0,r=0;
int[] a=new int[3];
for(int k=2;k<Math.sqrt(n);k++){
if(n%k==0){
s1=k;
r=n/k;
for(int k1=k+1;k1<Math.sqrt(r);k1++){
if((r)%k1==0){
s2=k1;
s3=(r)/k1;
f=1;
k=n;
break;
}
}
}
}
if(f==1){
pw.println("YES");
pw.println(s1+" "+s2+" "+s3);}
else
pw.println("NO");
}
pw.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 | from sys import stdin
inp = (s.rstrip() for s in stdin).__next__
def mpint():
return map(int, inp().split())
# sieve
N = int(1e5)
is_prime = [True] * (N + 1) # have 0
is_prime[0] = is_prime[1] = False
prime = []
for n in range(2, N + 1):
if is_prime[n]:
prime.append(n)
for p in prime:
if n * p > N: # Index out of range
break
is_prime[p * n] = False
# print("%d*%d = %d" % (p, n, p*n))
if n % p == 0:
break
# print(prime)
def f():
global n
if len(ans) == 2:
return
for p in prime:
if p*p > n:
return
if n % p == 0:
n //= p
ans.append(p)
return f()
for case in range(int(inp())):
n = int(inp())
ans = []
f()
if len(ans) <= 1:
print("NO")
continue
if ans[0] == ans[1]:
for p in range(2, int(n**0.5)+1):
if n % p == 0:
n //= p
ans[1] *= p
break
if len(set(ans + [n])) == 3:
print("YES")
print(*ans, n)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.math.*;
import java.io.*;
import java.util.*;
import java.awt.*;
public class CP {
public static void main(String[] args) throws Exception {
new Solver().solve();
}
}
class Solver {
final Helper hp;
final int MAXN = 1000_006;
final long MOD = (long) 1e9 + 7;
Solver() {
hp = new Helper(MOD, MAXN);
hp.initIO(System.in, System.out);
}
void solve() throws Exception {
int i, j, k;
for (int tc = hp.nextInt(); tc > 0; --tc) {
long N = hp.nextLong();
hp.println(factorise(N));
}
hp.flush();
}
String factorise(final long N) {
Random rnd = new Random();
for (int t = 30; t > 0; --t) {
long[] prod = new long[] {1, 1, 1};
long i, n = N;
for (i = 2; i * i <= n; ++i) if (n % i == 0) {
while (n % i == 0) {
prod[rnd.nextInt(3)] *= i;
n /= i;
}
}
if (n > 1) prod[rnd.nextInt(3)] *= n;
Arrays.sort(prod);
if (hp.min(prod) > 1 && prod[0] < prod[1] && prod[1] < prod[2]) {
return "YES\n" + hp.joinElements(prod);
}
}
return "NO";
}
}
class Helper {
final long MOD;
final int MAXN;
final Random rnd;
public Helper(long mod, int maxn) {
MOD = mod;
MAXN = maxn;
rnd = new Random();
}
public static int[] sieve;
public static ArrayList<Integer> primes;
public void setSieve() {
primes = new ArrayList<>();
sieve = new int[MAXN];
int i, j;
for (i = 2; i < MAXN; ++i)
if (sieve[i] == 0) {
primes.add(i);
for (j = i; j < MAXN; j += i) {
sieve[j] = i;
}
}
}
public static long[] factorial;
public void setFactorial() {
factorial = new long[MAXN];
factorial[0] = 1;
for (int i = 1; i < MAXN; ++i) factorial[i] = factorial[i - 1] * i % MOD;
}
public long getFactorial(int n) {
if (factorial == null) setFactorial();
return factorial[n];
}
public long ncr(int n, int r) {
if (r > n) return 0;
if (factorial == null) setFactorial();
long numerator = factorial[n];
long denominator = factorial[r] * factorial[n - r] % MOD;
return numerator * pow(denominator, MOD - 2, MOD) % MOD;
}
public long[] getLongArray(int size) throws Exception {
long[] ar = new long[size];
for (int i = 0; i < size; ++i) ar[i] = nextLong();
return ar;
}
public int[] getIntArray(int size) throws Exception {
int[] ar = new int[size];
for (int i = 0; i < size; ++i) ar[i] = nextInt();
return ar;
}
public String[] getStringArray(int size) throws Exception {
String[] ar = new String[size];
for (int i = 0; i < size; ++i) ar[i] = next();
return ar;
}
public String joinElements(long[] ar) {
StringBuilder sb = new StringBuilder();
for (long itr : ar) sb.append(itr).append(" ");
return sb.toString().trim();
}
public String joinElements(int[] ar) {
StringBuilder sb = new StringBuilder();
for (int itr : ar) sb.append(itr).append(" ");
return sb.toString().trim();
}
public String joinElements(String[] ar) {
StringBuilder sb = new StringBuilder();
for (String itr : ar) sb.append(itr).append(" ");
return sb.toString().trim();
}
public String joinElements(Object[] ar) {
StringBuilder sb = new StringBuilder();
for (Object itr : ar) sb.append(itr).append(" ");
return sb.toString().trim();
}
public long gcd(long a, long b) {
return b == 0 ? a : gcd(b, a % b);
}
public int gcd(int a, int b) {
return b == 0 ? a : gcd(b, a % b);
}
public long max(long[] ar) {
long ret = ar[0];
for (long itr : ar) ret = Math.max(ret, itr);
return ret;
}
public int max(int[] ar) {
int ret = ar[0];
for (int itr : ar) ret = Math.max(ret, itr);
return ret;
}
public long min(long[] ar) {
long ret = ar[0];
for (long itr : ar) ret = Math.min(ret, itr);
return ret;
}
public int min(int[] ar) {
int ret = ar[0];
for (int itr : ar) ret = Math.min(ret, itr);
return ret;
}
public long sum(long[] ar) {
long sum = 0;
for (long itr : ar) sum += itr;
return sum;
}
public long sum(int[] ar) {
long sum = 0;
for (int itr : ar) sum += itr;
return sum;
}
public void shuffle(int[] ar) {
int r;
for (int i = 0; i < ar.length; ++i) {
r = rnd.nextInt(ar.length);
if (r != i) {
ar[i] ^= ar[r];
ar[r] ^= ar[i];
ar[i] ^= ar[r];
}
}
}
public void shuffle(long[] ar) {
int r;
for (int i = 0; i < ar.length; ++i) {
r = rnd.nextInt(ar.length);
if (r != i) {
ar[i] ^= ar[r];
ar[r] ^= ar[i];
ar[i] ^= ar[r];
}
}
}
public long pow(long base, long exp, long MOD) {
base %= MOD;
long ret = 1;
while (exp > 0) {
if ((exp & 1) == 1) ret = ret * base % MOD;
base = base * base % MOD;
exp >>= 1;
}
return ret;
}
static byte[] buf = new byte[2048];
static int index, total;
static InputStream in;
static BufferedWriter bw;
public void initIO(InputStream is, OutputStream os) {
try {
in = is;
bw = new BufferedWriter(new OutputStreamWriter(os));
} catch (Exception e) {
}
}
public void initIO(String inputFile, String outputFile) {
try {
in = new FileInputStream(inputFile);
bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(outputFile)));
} catch (Exception e) {
}
}
private int scan() throws Exception {
if (index >= total) {
index = 0;
total = in.read(buf);
if (total <= 0)
return -1;
}
return buf[index++];
}
public String next() throws Exception {
int c;
for (c = scan(); c <= 32; c = scan()) ;
StringBuilder sb = new StringBuilder();
for (; c > 32; c = scan())
sb.append((char) c);
return sb.toString();
}
public int nextInt() throws Exception {
int c, val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+')
c = scan();
for (; c >= '0' && c <= '9'; c = scan())
val = (val << 3) + (val << 1) + (c & 15);
return neg ? -val : val;
}
public long nextLong() throws Exception {
int c;
long val = 0;
for (c = scan(); c <= 32; c = scan()) ;
boolean neg = c == '-';
if (c == '-' || c == '+')
c = scan();
for (; c >= '0' && c <= '9'; c = scan())
val = (val << 3) + (val << 1) + (c & 15);
return neg ? -val : val;
}
public void print(Object a) throws Exception {
bw.write(a.toString());
}
public void printsp(Object a) throws Exception {
print(a);
print(" ");
}
public void println() throws Exception {
bw.write("\n");
}
public void println(Object a) throws Exception {
print(a);
println();
}
public void flush() throws Exception {
bw.flush();
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from functools import reduce
def is_prime(n):
if n == 1:
return False
i = 2
while i*i <= n:
if n % i == 0:
return False
i += 1
return True
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
t = int(input())
while(t):
t-=1
n = int(input())
b=True
l=[]
if is_prime(n):
print("NO")
continue
elif int(n**0.5)==n**0.5:
if is_prime(n**0.5):
print("NO")
continue
elif int(n**0.25)==n**0.25:
if is_prime(n**0.25):
print("NO")
continue
for i in range(2,int(n**0.5)+1):
if n%i==0:
n = int(n/i)
s = sorted(list(factors(n)))
if 1 in s:
s.pop(s.index(1))
if n in s:
s.pop(s.index(n))
if len(s)>1:
for ii in range(len(s)):
if s[ii]>i:
j=s[ii]
k=s[len(s)-ii-1]
if j!=k and i!=k:
l.append(i)
l.append(j)
l.append(k)
print("YES")
print(*l)
b=False
break
if not b:
break
if b:
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 | n = int(input())
def f(a):
q = a
x = 0
y = 0
z = 0
for i in range(2, a):
if i * i > a:
break
if a % i == 0:
x = i
break
if x == 0:
return 'NO'
else:
a = a // x
for i in range(2, a):
if i * i > a:
break
if i != x and a % i == 0:
y = i
break
if y == 0:
return 'NO'
else:
z = a//y
if z != y and z != x and y != x and x * y * z == q:
return 'YES' + '\n' + str(x) + ' ' + str(y) + ' ' + str(z)
return 'NO'
for i in range(n):
a = int(input())
print(f(a))
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for _ in range(int(input())):
n=int(input())
y=0
for i in range(2,int(n**0.5)+1):
if n%i==0:
x=n//i
for j in range(i+1,int(n**0.5)+1):
if x%j==0:
if x//j!=i and (x//j)>1 and (x//j)!=j:
print("YES")
print(i,j,n//(i*j))
y=1
break
if y==1:
break
if y==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 math
for _ in range(int(input())):
t = n = int(input())
dels = []
sq = int(math.sqrt(n))
d = 2
while d <= sq:
if n % d != 0:
d += 1
else:
dels.append(d)
n //= d
sq = int(math.sqrt(n))
dels.append(n)
a = dels[0]
b = 1
i = 1
while i < len(dels) and b <= a:
b *= dels[i]
i += 1
a, b, c = sorted([a, b, t // (a * b)])
# print(dels, '\n', a, b, c)
if (a > 1) and (a < b < c):
print('YES')
print(a, b, t // (a * b))
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
test=int(input())
for i in range(test):
n=int(input())
count=0
j=2
temp=n
ans=[]
r=math.ceil(math.sqrt(n))
while count<2 and j<r:
if n%j==0:
count+=1
n//=j
ans.append(j)
j+=1
if count==0 or count<2:
print('NO')
else:
s=1
for i in ans:
s*=i
if temp//s not in ans:
print('YES')
print(*ans,temp//s)
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 | #https://codeforces.com/problemset/problem/1294/C
from math import sqrt
for _ in range(int(input())):
n=int(input())
f=0
for i in range(2,int(sqrt(n))+1):
if n%i==0:
if n//i != i:
t=n//i
for j in range(2,int(sqrt(t))+1):
if t%j==0:
if t//j !=j:
if i!=j and i!=t//j:
print('YES')
print(i,j,t//j)
f=1
break
if f:
break
if not f:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
# inf = open('input.txt', 'r')
# reader = (line.rstrip() for line in inf)
reader = (line.rstrip() for line in sys.stdin)
input = reader.__next__
t = int(input())
for _ in range(t):
n = int(input())
primes = {}
if not n & 1:
primes[2] = 0
while not n & 1:
n >>= 1
primes[2] += 1
f = 3
lim = int(n ** 0.5) + 1
while f < lim and f <= n:
if n % f == 0:
primes[f] = 0
while n % f == 0:
n //= f
primes[f] += 1
f += 2
if n > 1:
primes[n] = 1
if len(primes) > 2:
ans = []
f = 1
i = 0
for i, (k, p) in enumerate(primes.items()):
f *= pow(k, p)
if i < 2:
ans.append(f)
f = 1
ans.append(f)
print('YES')
print(*ans)
elif len(primes) == 1:
for k, p in primes.items():
if p > 5:
ans = [k, k * k, pow(k, p-3)]
print('YES')
print(*ans)
else:
print('NO')
else:
powers = sum(primes.values())
if powers > 3:
fs = []
for k, p in primes.items():
fs.extend([k] * p)
ans = []
if fs[0] != fs[1]:
ans.append(fs[0])
ans.append(fs[1])
rest = 2
else:
ans.append(fs[0])
ans.append(fs[1] * fs[2])
rest = 3
c = 1
for f in fs[rest:]:
c *= f
ans.append(c)
print('YES')
print(*ans)
else:
print('NO')
# inf.close() | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | rr= lambda: input().strip()
rri= lambda: int(rr())
rrm= lambda: [int(x) for x in rr().split()]
def fact(n):
res=[]
for i in range(2, int(n**.5)+1):
if n%i==0:
res.append(i)
res.append(n//i)
if (int(n**.5)**2==n):
res.pop()
return res
def sol():
n=rri()
f=fact(n)
#print(f)
if (len(f)<3):
print("NO")
return
f.sort()
a=f[0]
d=n//a
for i in range(1, len(f)):
for j in range(i+1, len(f)):
if f[i]*f[j]==d:
print("YES")
print (a, f[i], f[j])
return
print("NO")
return
t=rri()
for _ in range(t):
#a,b,c=rrm()
sol()
#print(ans) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
input=sys.stdin.readline
t=int(input())
import math
from functools import reduce
def factors(n):
return set(reduce(list.__add__,
([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))
for i in range(t):
n=int(input())
ffactor=(factors(n))
#print(ffactor)
ffactor2=list(set(ffactor))
ffactor2.sort()
ok=False
#print(ffactor2)
for i in range(len(ffactor2)):
for j in range(i+1,len(ffactor2)):
for k in range(j+1,len(ffactor2)):
if ffactor2[i]>=2 and ffactor2[j]>=2 and ffactor2[k]>=2:
if ffactor2[i]*ffactor2[j]*ffactor2[k]==n:
ok=True
f=ffactor2[i]
s=ffactor2[j]
t=ffactor2[k]
break
if ok==True:
break
if ok==True:
break
if ok==True:
print("YES")
print(int(f),int(s),int(t))
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):
ar = []
while n % 2 == 0:
ar.append(2)
n = n / 2
for i in range(3, int(math.sqrt(n))+1, 2):
while n % i == 0:
ar.append(i)
n = n / i
if n > 2:
ar.append(n)
return ar
for _ in xrange(input()):
n = input()
ar = primeFactors(n)
ar.sort()
ans = []
if len(ar) < 3:
print "NO"
continue
ans.append(ar.pop(0))
if ar[0] in ans:
ans.append(ar[0]*ar[1])
ar = ar[2:]
if len(ar) == 0:
print "NO"
else:
pr = 1
for x in ar:
pr = pr*x
if pr in ans:
print "NO"
else:
print "YES"
ans.append(pr)
print " ".join(str(x) for x in ans)
else:
ans.append(ar.pop(0))
if len(ar) == 0:
print "NO"
else:
pr = 1
for x in ar:
pr = pr*x
if pr in ans:
print "NO"
else:
print "YES"
ans.append(pr)
print " ".join(str(x) for x in ans)
| PYTHON |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main
{
public static void main(String[] args)
{
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
static class TaskC
{
public void solve(int testNumber, Scanner in, PrintWriter out)
{
int t = in.nextInt();
while (t-- > 0)
{
solve(in, out);
}
}
private void solve(Scanner in, PrintWriter out)
{
int n = in.nextInt();
int N = n;
int a = 1;
int b = 1;
int c = 1;
int sqrt = (int) Math.sqrt(1_000_000_000) + 1;
for (int i = 2; i <= sqrt; i++)
{
if (n % i == 0)
{
a = i;
n /= i;
break;
}
}
if (a == 1)
{
out.println("NO");
return;
}
for (int i = 2; i <= sqrt; i++)
{
if (i != a)
{
if (n % i == 0)
{
b = i;
n /= i;
break;
}
}
}
if (b == 1)
{
out.println("NO");
return;
}
c = n;
if (c == 1)
{
out.println("NO");
return;
}
if (a == b || b == c || a == c)
{
out.println("NO");
return;
}
if (a * b * c == N)
{
out.println("YES");
out.println(a + " " + b + " " + c);
return;
}
out.println("NO");
}
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t=int(input())
li=[]
def p2(m,a):
for i in range(2,int(m**(0.5))+1):
if (int(m/i)==m/i)and(i!=m/i!=a)and(i!=a):
return [int(i),int(m/i)]
return "no"
for i in range(t):
li=li+[int(input())]
for k in li:
if p2(k,1)!="no":
l=p2(k,1)
if p2(l[0],l[1])!="no":
print("YES")
print(l[1],p2(l[0],l[1])[0],(p2(l[0],l[1])[1]))
elif p2(l[1],l[0])!="no":
print("YES")
print(l[0],p2(l[1],l[0])[0],(p2(l[1],l[0])[1]))
else:
print("NO")
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t=int(input())
for _ in range(0,t):
n=int(input())
z=int(math.sqrt(n))+10
a=[]
for i in range(2,z+1):
if n%i==0:
n=n//i
a.append(i)
if len(a)==2:
break
if len(a)==2 and n!=1:
if n not in a:
print("YES")
print(a[0],a[1],n)
else:
print("NO")
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible 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):
root=int(math.sqrt(n))
a=-1
b=-1
c=0
i=2
while(i<=root):
if(n%i==0):
a=i
n=n/i
break
i=i+1
root=int(math.sqrt(n))
i=2
while(i<=root):
if(n%i==0 and i!=a and n/i!=a and i!=n/i):
b=i
c=int(n/i)
break
i=i+1
if(a==-1 or b==-1):
print("NO")
else:
output="{0} {1} {2}"
print("YES")
print(output.format(a,b,c))
t=int(input())
while(t>=1):
n=int(input())
solve(n)
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 | for i in range(int(input())):
n = int(input())
abc = []
x = 2
while len(abc) < 2 and x*x < n:
if n % x == 0:
abc.append(x)
n //= x
x += 1
if len(abc) == 2 and n not in abc:
print('YES')
print(*abc, n)
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;
import java.io.*;
public class Main {
public static void main(String args[]) {
InputReader obj = new InputReader(System.in);
int t = obj.nextInt();
while(t-->0) {
int n=obj.nextInt();
boolean chk1=false;
for(int i=2;i<Math.sqrt(n);i++) {
boolean chk=false;
if(n%i==0) {
HashSet<Integer> hs = new HashSet<Integer>();
hs.add(i);
int x=n/i;
for(int j=2;j<Math.sqrt(x);j++) {
if(x%j==0 && !hs.contains(j) && !hs.contains(x/j)) {
System.out.println("YES");
System.out.println(i+" "+j+" "+x/j);
chk=true;
chk1=true;
break;
}
}
}
if(chk) {
break;
}
}
if(!chk1) {
System.out.println("NO");
}
}
}
public static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 |
import java.io.*;
import java.util.*;
public class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
String[] line = sc.readLine().split(" ");
int cases = Integer.parseInt(line[0]);
top:
for (int l = 0; l < cases; l++)
{
line = sc.readLine().split(" ");
int num = Integer.parseInt(line[0]);
int nums[] = new int[3];
int loc = 0;
for (int i = 2; i * i < num; i++)
{
if (num % i == 0)
{
nums[loc] = i;
num = num / i;
loc++;
}
if (loc == 2)
{
nums[2] = num;
System.out.println("YES");
System.out.println(nums[0] + " " + nums[1] + " " + nums[2] + " ");
continue top;
}
}
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;
const int ma1 = 3e5 + 5;
string no = "NO", yes = "YES";
const unsigned int MAX1 = 1000000007;
void f(int n) {
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
int d = n / i;
for (int j = i + 1; j < sqrt(d); j++) {
if (d % j == 0) {
cout << yes << endl;
cout << i << " " << j << " " << d / j << endl;
return;
}
}
}
}
cout << no << endl;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t;
cin >> t;
while (t--) {
long long n;
cin >> n;
f(n);
}
}
| CPP |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.