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 | t=input()
import math
from collections import Counter
# A function to print all prime factors of
# a given number n
def f(n):
l=[]
# Print the number of two's that divide n
while n % 2 == 0:
l.append(2)
n = n / 2
# n must be odd at this point
# so a skip of 2 ( i = i + 2) can be used
for i in range(3,int(math.sqrt(n))+1,2):
# while i divides n , print i ad divide n
while n % i== 0:
l.append(i)
n = n / i
# Condition if n is a prime
# number greater than 2
if n > 2:
l.append(n)
return l
for i in range(t):
n=input()
l=f(n)
c=Counter(l)
if len(c)==0:
print "NO"
elif len(c)==1:
for key in c:
if c[key]>=6:
print "YES"
print key,key**2,key**(c[key]-3)
break
else:
print "NO"
break
elif len(c)==2:
x=0
lis=[]
for key in c:
x+=c[key]
lis.append(key)
if x>=4:
print "YES"
print lis[0],lis[1],n/(lis[0]*lis[1])
else:
print "NO"
else:
j=0
s=''
x=1
for key in c:
if j<=1:
s=s+str(key)+' '
x=x*key
j+=1
t=n/x
print "YES"
print str(t)+' '+s
| PYTHON |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
n = int(input())
for i in range(n):
deb = t = int(input())
divs = []
for j in range(2,round(math.sqrt(t)+1)):
if t%j==0 and j not in divs:
divs.append(j)
t //= j
if len(divs) == 2:
divs.append(t)
break
if len(set(divs)) == 3 and deb == divs[0]*divs[1]*divs[2]:
print("YES")
print(divs[0],divs[1],divs[2])
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for _ in[0]*int(input()):
n=int(input());a=['YES'];i=j=2
while j<4and i*i<n:
if n%i<1:a+=i,;n//=i;j+=1
i+=1
print(*(a+[n],['NO'])[j<4]) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAX = 100002;
long long n, n_0;
bool c[MAX];
vector<int> primes, fact;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int t;
cin >> t;
for (int i = 2; i < MAX; i++) {
if (!c[i]) {
for (int j = i + i; j < MAX; j += i) {
c[j] = true;
}
}
}
while (t--) {
primes.clear();
fact.clear();
cin >> n;
n_0 = n;
c[0] = c[1] = true;
for (int i = 1; i <= sqrt(n) + 2; i++) {
if (!c[i]) primes.push_back(i);
}
for (int i = 0; i < primes.size(); i++) {
while (n % primes[i] == 0) {
fact.push_back(primes[i]);
n /= primes[i];
}
}
if (n != 1) fact.push_back(n);
sort(fact.begin(), fact.end());
if (fact.size() < 3) {
cout << "NO\n";
continue;
}
long long a = fact[0], b = fact[1], c = fact[2];
if (a == b) {
b *= c;
c = 1;
}
for (int i = 3; i < fact.size(); i++) {
c *= fact[i];
}
if (a != c && b != c && a != b && (a * b * c) == n_0 && c != 1) {
cout << "YES\n" << a << " " << b << " " << c << "\n";
} else
cout << "NO\n";
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, MOD = 1e9 + 7;
int t, n, a, b, c;
int main() {
cin >> t;
while (t--) {
cin >> n;
for (int i = 2; i * i <= n; ++i)
if (n % i == 0) {
a = i;
break;
}
if (a)
for (int i = 2; i * i <= n / a; ++i)
if ((n / a) % i == 0 && a != i) {
b = i;
break;
}
if (a && b && a != b && a != n / (a * b) && b != n / (a * b) &&
n % (a * b) == 0)
cout << "YES" << endl << a << " " << b << " " << n / (a * b) << endl;
else
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 | import sys
input=sys.stdin.readline
t=int(input())
import math
def primeFactors(n):
factor=[]
number=[]
while n % 2 == 0:
factor.append(2)
n = n / 2
for i in range(3,int(math.sqrt(n))+1,2):
while n % i== 0:
factor.append(int(i))
n = n / i
if n > 2:
factor.append(int(n))
return(factor)
for i in range(t):
n=int(input())
ffactor=(primeFactors(n))
#print(ffactor)
ffactor2=list(set(ffactor))
if len(ffactor2)>=3:
print("YES")
print(int(ffactor2[0]),int(ffactor2[1]),int(n/(ffactor2[1]*ffactor2[0])))
elif len(set(ffactor))>=2 and len(ffactor)>=4:
print("YES")
print(int(ffactor2[0]),int(ffactor2[1]),int(n/(ffactor2[1]*ffactor2[0])))
elif len(ffactor2)>=1 and len(ffactor)>=6:
print("YES")
first=int(ffactor2[0])
sec=int((ffactor2[0])**2)
third=int(n/(first*sec))
print(int(first),int(sec),int(third))
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t=int(input())
while t:
n=int(input())
cnt=0
i=2
ans=[]
while True:
while i*i<n:
if n%i==0:
ans.append(i)
cnt+=1
if cnt==2:
ans.append(int(n/i))
break
n=n/i
i+=1
if i*i>=n or cnt==2:
break
if cnt==2:
print("YES")
print(*ans,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 | def solve():
ans = []
n = int(input())
for j in range(2 , int(n ** (1 / 2)) + 1):
if(n % j == 0):
ans.append(j)
ans.append(n // j)
ans = list(set(ans))
if(len(ans) < 3):
print("NO")
else:
for j in range(len(ans)):
for g in range(j + 1, len(ans)):
for k in range(g + 1 , len(ans)):
if((ans[j] * ans[g] * ans[k]) == n):
print("YES")
print(ans[j] , ans[g] , ans[k])
return
print("NO")
t = int(input())
for i in range(t):
solve() | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
input=sys.stdin.readline
t=int(input())
p=[]
for _ in range(t):
n=int(input())
fac=[]
for i in range(2,int(n**0.5)+1):
if(n%i==0):
fac.append(i)
fac.append(n//i)
nn=len(fac)
st=0
# print(fac)
for i in range(nn):
for j in range(i+1,nn):
if(n%(fac[i]*fac[j])==0):
k=n//(fac[i]*fac[j])
if fac[i]==fac[j] or fac[i]==k or fac[j]==k:
continue
if 1 in [fac[i],fac[j],k]:
continue
st=1
ii,jj,kk=fac[i],fac[j],k
break
if st:
print("YES")
print(ii,jj,kk)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int t, n, a, b, c;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
a = 0;
b = 0;
c = 0;
int m = n;
for (int i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
a = i;
m /= a;
break;
}
}
for (int i = a + 1; i <= sqrt(n); i++) {
if (m % i == 0) {
b = i;
break;
}
}
if (a == 0 || b == 0) {
cout << "NO\n";
continue;
} else if (n / (a * b) == a || n / (a * b) == b || n / (a * b) == 1) {
cout << "NO\n";
continue;
} else {
cout << "YES\n" << a << " " << b << " " << n / (a * b) << "\n";
}
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t = int(input())
for tt in range(t):
n = int(input())
f = 0
for i in range(2, int(math.sqrt(n)) + 1):
if n % i == 0:
a = i
c = 1
b = 1
for j in range(2, int(math.sqrt(n / a)) + 1):
if (n / a) % j == 0 and j != a:
b = j
c = int(n / (a * j))
break
if a != c and b != c and c != 1:
print("YES")
print("%s %s %s" % (a, b, c))
f = 1
else:
print ("NO")
f = 1
break
if f == 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 | for T in range(int(input())):
N = int(input())
D = set()
for I in range(2, int(N**0.5)+1):
if N % I == 0:
D.add(I)
D.add(N//I)
D = sorted(list(D))
F = 0
if len(D) < 3:
F = 1
print('NO')
else:
for I in range(len(D)):
for J in range(len(D)):
if I != J:
X = N/(D[I]*D[J])
if X != D[I] and X != D[J] and X > 1 and X % 1 ==0:
F = 1
print('YES')
print(D[I], D[J], int(X))
break
if F == 1:
break
if F == 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())):
n = int(input())
f = []
i = 2
while i <= math.sqrt(n):
if n % i == 0:
if n // i == 0:
f.append(i)
else:
f.append(n//i)
f.append(i)
i = i + 1
f = set(f)
f = list(f)
#print(f)
ln = len(f)
f.sort()
f1 = 0
for i in range(ln):
for j in range(1,ln):
for k in range(2,ln):
if f[i]*f[j]*f[k] == n:
print("YES")
print(f[i],f[j],f[k])
f1 = 1
break
if f1 == 1:
break
if f1 == 1:
break
if f1 == 0:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t;
long long int n, i, j, k;
vector<long long int> vec;
cin >> t;
while (t--) {
int flag = 0;
vec.clear();
cin >> n;
for (i = 2; i * i <= n; i++) {
if (n % i == 0) {
if (i != (n / i)) {
vec.push_back(i);
vec.push_back(n / i);
} else
vec.push_back(i);
}
}
sort(vec.begin(), vec.end());
long long int m = vec.size();
for (i = 0; i < m; i++) {
for (j = i + 1; j < m; j++) {
for (k = j + 1; k < m; k++) {
if ((vec[i] * vec[j] * vec[k]) == n) {
flag = 1;
goto label;
}
}
}
}
goto label;
label:
if (flag) {
cout << "YES" << endl;
cout << vec[i] << " " << vec[j] << " " << vec[k] << endl;
} else
cout << "NO" << endl;
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
import math
Z = sys.stdin.readline
def main():
for t in range(int(Z().strip())):
n = int(Z().strip())
c=00
if n>=24:
r=[0]
for i in range(2,roundsqrt(n)):
if n%i==0:
q=n//i
r[0]=i
break
if r[0]!=0:
for i in range(r[0]+1,roundsqrt(q)):
if q%i==0:
r.append(i)
c=1
break
if c==1:
r.append(n/((r[0])*(r[1])))
print("YES")
print(" ".join(str(x) for x in r))
else:
print("NO")
else:
print("NO")
else:
print("NO")
def roundsqrt(x):
return int(math.ceil(math.sqrt(x)))
if __name__=="__main__":
main() | 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 | from math import sqrt
n = int(input())
for i in range(n):
q = int(input())
qq = q
for i in range(2, int(sqrt(q)) + 1):
if q % i == 0:
a = i
q //= i
break
else:
print("NO")
continue
for i in range(a + 1, int(sqrt(q)) + 1):
if q % i == 0:
b = i
c = qq // (a * b)
break
else:
print("NO")
continue
if a == b or b == c or a == c:
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 java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
static int mod=(int)1e9+7;
public static void main(String[] args) throws IOException {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
while (t-->0){
int n=sc.nextInt();
HashMap<Integer,Integer> hm= fac(n);
int[] arr1=new int[hm.size()];
int[] arr2=new int[hm.size()];
int count=0;
for (int x:hm.keySet()){
arr1[count]=x;
arr2[count]=hm.get(x);
count++;
}
if (count>=3){
System.out.println("YES");
System.out.println(arr1[0]+" "+arr1[1]+" "+n/(arr1[0]*arr1[1]));
}else if (count==2){
if (arr2[0]+arr2[1]>=4){
System.out.println("YES");
System.out.println(arr1[0]+" "+arr1[1]+" "+(n/(arr1[0]*arr1[1])));
}else System.out.println("NO");
}else{
if (arr2[0]>=6){
System.out.println("YES");
System.out.println(arr1[0]+" "+(arr1[0]*arr1[0])+" "+(n/(arr1[0]*arr1[0]*arr1[0])));
}else System.out.println("NO");
}
}
}
static HashMap<Integer, Integer> fac(int x){
HashMap<Integer,Integer> map=new HashMap<>();
for (int i=2;i*i<=x;i++){
int cnt=0;
boolean f=false;
while (x%i==0){
f=true;
x/=i;
cnt++;
}
if (f)map.put(i,cnt);
}
if (x>1)map.put(x,map.getOrDefault(x,0)+1);
return map;
}
} | 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
def f(n):
res=[]
for i in range(2,int(n**0.5)+1):
if n%i==0 and i not in res:
n=n//i
res.append(i)
break
for i in range(2,int(n**0.5)+1):
if n%i==0 and i not in res:
n=n//i
res.append(i)
break
if len(res) < 2 or n in res or n == 1:
return False
else:
return res+[n]
t=int(stdin.readline().strip())
for _ in range(t):
n=int(stdin.readline().strip())
res=f(n)
if res==False:
print('NO')
else:
print('YES')
print(' '.join(map(str,res))) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t=int(input())
for i in range(t):
n=int(input())
flag=0
for j in range(2,int(pow(n,0.5)+1)):
if n%j==0:
n1=n//j
for k in range(j+1,int(pow(n1,0.5)+1)):
n2=n1//k
if n1%k==0 and n2!=k:
flag=1
n2=n1//k
print("YES")
print(j,end=" ")
print(k,end=" ")
print(n2)
break
break
if flag==0:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, d, a, b, c, i;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
d = 2;
vector<int> ord;
while (d * d <= n) {
while (n % d == 0) {
ord.push_back(d);
n /= d;
}
d++;
}
if (n > 1) ord.push_back(n);
if (ord.size() < 3) {
printf("NO\n");
continue;
}
a = ord[0];
b = ord[ord.size() - 1], i = ord.size() - 2;
if (a == b && ord.size() > 2) b *= ord[ord.size() - 2], i = ord.size() - 3;
c = 1;
while (i > 0) c *= ord[i--];
if (a == b || b == c || a == c || c == 1)
printf("NO\n");
else {
printf("YES\n%d %d %d\n", a, b, c);
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
import java.lang.*;
import java.io.*;
public class Main
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
while(t>0){
int n = sc.nextInt();
int num = n;
final int MAX = 100000;
int[] arr = new int[MAX];
int id = 0;
for(int i=2;i*i<=num;i++) {
if(num%i==0) {
while(num%i==0) {
arr[id++] = i;
num = num/i;
}
}
}
if(num>1) arr[id++] = num;
if(id<3){
System.out.println("NO"); t--;continue;
}
int a = arr[0];
int b = 1;
int c = 1;
int st = 1;
if(arr[0]!=arr[1]){
b = arr[1];
st = 2;
}
else{
b = arr[1]*arr[2];
st = 3;
}
if(a*b==n){
System.out.println("NO");
t--;
continue;
}
for(int i=st;i<id;i++){
c = c*arr[i];
}
if(a!= b && b!=c && c!=a){
System.out.println("YES");
System.out.print(a + " " + b + " " + c);
System.out.println();}
else System.out.println("NO");
t--;
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
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 (int(used.size()) < 2 || used.count(n) || n == 1) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
used.insert(n);
for (auto it : used) cout << it << " ";
cout << endl;
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t = int(input())
for _ in range(t):
n = int(input())
n_i = n
if n<24:
print("NO")
else:
a, b, c = 2, 2, 2
sq = int(math.sqrt(n)) + 2
for i in range(a,sq):
if n%i==0:
a = i
n = n//a
sq = int(math.sqrt(n)) + 2
break
for i in range(a+1,sq):
if n%i==0:
b = i
n = n//b
break
c = n
if c==b or c==2 or b==2:
print("NO")
elif a==2 and n_i%2!=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 | # Python program to print prime factors
import math
def solution(n):
a = 0
b = 0
for i in range(2, int(math.sqrt(n))+1):
if n % i == 0:
a = i
n //= i
break
if a:
for j in range(a + 1, int(math.sqrt(n))+1):
if n % j == 0:
b = j
n //= j
break
if a and b and b != n:
print('YES')
print(f'{a} {b} {n}')
else:
print('NO')
t = int(input())
kls = [int(input()) for _ in range(t)]
for k in kls:
solution(k)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
import java.util.Map.Entry;
import java.lang.*;
import java.math.*;
import java.text.*;
import java.io.*;
public final class Solve {
static PrintWriter out = new PrintWriter(System.out);
static void flush() {
out.flush();
}
static void run(long s, long e) {
NumberFormat formatter = new DecimalFormat("#0.00000");
System.out.print("Execution time is " + formatter.format((e - s) / 1000d) + " seconds");
}
static int gcd(int a, int b) {
if (b == 0) return a;
return gcd(b, a % b);
}
static long gcd(long a, long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
static long lcm(long a, long b) {
return a*b/gcd(a, b);
}
static class FastReader {
static BufferedReader br;
StringTokenizer st;
public FastReader() {
br = new BufferedReader(new
InputStreamReader(System.in));
}
static boolean isPalindrome(String str1, String str2) {
String str3 = str1+str2;
int i = 0, j = str3.length()-1;
while(i < j) {
char a = str3.charAt(i), b = str3.charAt(j);
if(a != b) return false;
i++;j--;
}
return true;
}
static boolean isPalindrome(String str) {
int i = 0, j = str.length()-1;
while(i < j) {
char a = str.charAt(i), b = str.charAt(j);
if(a != b) return false;
i++;j--;
}
return true;
}
String next() {
while (st == null || !st.hasMoreElements()) {
try{st = new StringTokenizer(br.readLine());}
catch (IOException e) {e.printStackTrace();}
}
return st.nextToken();
}
int nextInt(){ return Integer.parseInt(next()); }
long nextLong() { return Long.parseLong(next());}
static int fact(int n) {
if(n == 1) return 1;
return n * fact(n-1);
}
public int[] readIntArray(int n) {
int[] arr = new int[n];
for(int i=0; i<n; ++i)
arr[i]=nextInt();
return arr;
}
public long[] readLongArray(int n) {
long[] arr = new long[n];
for(int i=0; i<n; ++i)
arr[i]=nextLong();
return arr;
}
public int[][] readIntArray(int m, int n){
int[][] arr = new int[m][n];
for(int i = 0;i<m;i++)
for(int j = 0;j<n;j++)
arr[i][j] = nextInt();
return arr;
}
public String[] readStringArray(int n) {
String[] arr = new String[n];
for(int i=0; i<n; ++i)
arr[i]= nextLine();
return arr;
}
double nextDouble() {return Double.parseDouble(next());}
String nextLine() {
String str = "";
try{str = br.readLine();}
catch (IOException e) {e.printStackTrace();}
return str;}
}
static void solve(int n){
int k = n,c = 0;
int j = 0;
List<Integer> list = new ArrayList<>();
int fl = 0;
Set<Integer> set = new HashSet<>();
for(int i = 2;i*i <= 1000000000;i++) {
if(k%i == 0) {
k = k/i;
list.add(i);
set.add(i);
c++;
}
if(c == 2) {
if(!set.contains(k) && k != 1) {
list.add(k);
fl = 1;
}
break;
}
}
if(c == 2 && fl == 1) {
out.println("Yes");
out.println(list.get(0)+" "+list.get(1)+" "+list.get(2));
}
else out.println("No");
}
public static void main(String args[]) throws IOException {
FastReader sc = new FastReader();
long s1 = System.currentTimeMillis();
int t = sc.nextInt();
while(t-- > 0 ) {
int n = sc.nextInt();
solve(n);
}
flush();
long e = System.currentTimeMillis();
// run(s1,e);
}
}
| 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
for _ in range(int(input())):
n=int(input())
if n<24:
print("NO")
continue
a=1
b=1
c=1
for i in range(2,int(math.sqrt(n))+1):
if n%i==0:
a=i
break
n//=a
for i in range(2,int(math.sqrt(n))+1):
if i!=a and n%i==0:
b=i
break
if b!=1:
c=n//b
if a is not b and b is not c and c is not a:
print("YES")
print(a,end=" ");print(b,end=" ");print(c)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for t in range(int(input())):
n = int(input())
k = 2
i = k
a = -1
b = -1
c = -1
while i <= n/k:
k+=1
if n%i == 0:
a = i
x = n/a
break
else:
i = k
if a == -1:
print("NO")
else:
# print(x)
k = 3
i = k
while i <= x/k:
k+=1
if x%i == 0 and i != a:
b = i
c = x//b
c = int(c)
break
else:
i = k
if b == -1 or c == -1:
print("NO")
elif a==c or b==c or a==b:
print("NO")
else:
print("YES")
print(a,b,c)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
for case in range (int (input ())) :
n = int (input())
a, b, c = 0, 0, 0
for i in range(2, int (math.sqrt (n)) + 1) :
if n % i == 0 :
a, b = i, n // i
break
if a :
for i in range (a + 1, int (math.sqrt(b)) + 1) :
if b % i == 0 :
b, c = i, b // i
break
print ("YES\n" + ' '.join ([str (a), str (b), str (c)]) if a >= 2 and b >= 2 and c >= 2 and b != c else "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 tt in range(t):
n=int(input())
m=n
fact=[]
while m%2==0:
fact.append(2)
m = m / 2
for i in range(3,int(math.sqrt(m))+1,2):
while m % i== 0:
fact.append(i)
m = m / i
if m > 2:
fact.append(m)
a,b = 1,1
for v in fact:
if a == 1:
a = v
elif b == 1 or b == a:
b *= v
else:
break
if (a*b) == 0:
print('NO')
continue
c = n/(a*b)
if c == 1 or c == a or c == b:
print('NO')
continue
print('YES')
d = int(c)
print(a,b,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 | from math import sqrt
t = int(input())
def factor(n):
factors = []
div = int(sqrt(n))
i = 2
count = 1
aux_n = n
while n > 1 and i <= div:
while n%i == 0:
factors.append(i)
n = n//i
count *= i
i += 1
if n > 1:
factors.append(aux_n//count)
return factors
for _ in range(t):
n = int(input())
primes = factor(n)
ans = []
i = 0
while i < len(primes):
count = primes[i]
if count not in ans:
ans.append(count)
i += 1
else:
i += 1
while i < len(primes) and count in ans:
count *= primes[i]
i += 1
ans.append(count)
if len(ans) > 2:
last = 1
for i in range(2, len(ans)): last *= ans[i]
ans = [ans[0], ans[1], last]
if len(set(ans)) == 3:
print("YES")
print(ans[0], ans[1], last)
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 | /******************************************************************************
Online Java Compiler.
Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.
*******************************************************************************/
import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
int t=scan.nextInt(),i;
int[] a=new int[3];
while(t-->0) {
int n=scan.nextInt();
a[0]=a[1]=a[2]=0;
int c=0;
for(i=2;i<=Math.sqrt(n);i++) {
if(n%i==0){
a[c++]=i;
n/=i;
if(c==2) {
a[2]=n;
break;
}
}
}
if(c==2&&a[1]<a[2]) {
System.out.println("YES\n"+a[0]+" "+a[1]+" "+a[2]);
}else
System.out.println("NO");
}}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import sqrt
from math import ceil
def find(fro, n):
if n % fro == 0:
return fro
return find(fro + 1, n)
t = int(input())
answers = []
for ti in range(t):
n = int(input())
first = -1
for i in range(2, ceil(sqrt(n)) + 1):
if n % i == 0:
first = i
break
if first == -1:
answers.append("NO")
continue
second = -1
nn = n // first
for i in range(first + 1, ceil(sqrt(nn))):
if nn % i == 0:
second = i
break
if second == -1:
answers.append("NO")
continue
third = nn // second
answers.append("YES")
answers.append(str(first) + " " + str(second) + " " + str(third))
for a in answers:
print(a)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
from math import sqrt
def readlines(type=int):
return list(map(type, sys.stdin.readline().split()))
def read(type=int):
return type(sys.stdin.readline().strip())
joint = lambda it, sep=" ": sep.join(
[str(i) if type(i) != list else sep.join(map(str, i)) for i in it])
def solve(num):
def break_(num, n, already=-1):
for i in range(n, int(sqrt(num)) + 1):
if num % i == 0 and i != num // i and i != already and num // i != already and num // i != 1:
return i, num // i
return -1, -1
first, second = break_(num, 2)
if first == -1:
return "NO"
third, fourth = break_(second, first + 1, first)
if third == -1:
return "NO"
return("YES\n{} {} {}".format(first, third, fourth))
return "NO"
def main():
print(joint(list(map(solve, [read() for _ in range(read())])), '\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 | for _ in range(int(input())):
n = int(input())
a = []
for i in range(2,int((n**0.5))+1):
if n%i == 0:
n=n//i
a.append(i)
break
if len(a)==1 :
for j in range(a[0]+1,int((n**0.5))+1):
if n%j == 0:
n=n//j
a.append(j)
break
a.append(n)
if len(a) == 3 and a[1]<a[2]:
print("YES")
print(*a)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
public class ProductOf3Numbers {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int t = sc.nextInt();
int arr[] = new int[t];
for(int i=0; i<t; i++) {
arr[i] = sc.nextInt();
}
sc.close();
for(int i=0; i<t; i++) {
if(isPossible(arr[i]) == "NO")
System.out.println(isPossible(arr[i]));
else {
System.out.println("YES");
System.out.println(isPossible(arr[i]));
}
}
}
static String isPossible(int n) {
int sqrt = (int)Math.floor(Math.pow(n,0.5));
ArrayList<Integer> arr = new ArrayList<>();
int i;
for(i=2; i<= sqrt; i++) {
if(n%i == 0 && arr.size() < 2) {
n = n/i;
arr.add(i);
}
}
if(arr.size() < 2) {
return "NO";
}
else {
if(arr.get(0) != n && arr.get(1) != n)
return arr.get(0) + " " + arr.get(1) + " " + n;
}
return "NO";
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for i in range(int(input())):
a=int(input())
b=[]
i=2
while(len(b)<2 and (i**2)<a):
if(a%i==0):
a=a//i
b.append(i)
i+=1
if(len(b)==2 and a not in b):
print('YES')
b.append(a)
b=' '.join(str(i) for i in b)
print(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 | t = int(input())
for i in range(t):
n=int(input())
f=False
for i in range(2,2000):
if n%i != 0:
continue
newn = n//i
if(f):
break
for j in range(2,100000):
if newn%j != 0:
continue
k = newn//j
if(k >=2 and i!=j and i!=k and j!=k):
print("YES")
print(i,j,k)
f=True
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 java.util.*;
public class CodeforcesContest {
private static void sport(int n) {
int r=n;
Set<Integer> used = new HashSet<>();
int a = div(n, used);
if (a < 0) {
System.out.println("NO");
return;
}
n/=a;
used.add(a);
int b = div(n, used);
if (b < 0) {
System.out.println("NO");
return;
}
used.add(b);
int c = r % (a * b) == 0 ? r / (a * b) : -1;
if (c < 2 || c == a || c == b) {
System.out.println("NO");
return;
}
System.out.println("YES");
System.out.println(a + " " + b + " " + c);
}
private static int div(int n, Set<Integer> set) {
int k = (int) Math.sqrt(n);
for (int i = 2; i <= k; i++) {
if (n % i == 0 && !set.contains(i)) {
return i;
}
}
return -1;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int nExperiments = Integer.valueOf(sc.nextLine());
for (int i = 0; i < nExperiments; i++) {
int n = sc.nextInt();
sport(n);
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | # cook your dish here
import math
def factors(n):
num = int(math.sqrt(n))+1
fac = []
for i in range(2, num):
if (n%i) == 0:
fac.append(i)
n = n//i
if (len(fac) == 2):
break
if (len(fac) == 2 and n > fac[1]):
print("YES")
print(fac[0], fac[1], n)
else:
print("NO")
for _ in range(int(input())):
n = int(input())
if (n <= 23):
print("NO")
else:
factors(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 n;
vector<int> p;
void solve() {
cin >> n;
p.clear();
int cur = n;
for (int i = 2; i * i <= cur; i++) {
while (cur % i == 0) {
p.push_back(i);
cur /= i;
}
}
if (cur > 1) {
p.push_back(cur);
}
sort(p.begin(), p.end());
if ((int)p.size() < 3) {
puts("NO");
return;
}
if (p[0] != p.back()) {
int num = 1;
for (int i = 1; i < (int)p.size() - 1; i++) {
num *= p[i];
}
if (p[0] != p.back() && p[0] != num && p.back() != num) {
puts("YES");
cout << p[0] << " " << p.back() << " " << num << endl;
} else {
puts("NO");
}
} else {
if ((int)p.size() - 3 <= 2) {
puts("NO");
return;
}
int num = 1;
for (int i = 3; i < (int)p.size(); i++) {
num *= p[i];
}
if (p[0] != p[0] * p[0] && p[0] != num && p[0] * p[0] != num) {
puts("YES");
cout << p[0] << " " << p[0] * p[0] << " " << num << endl;
} else {
puts("NO");
}
}
}
int main() {
int tn;
cin >> tn;
while (tn--) {
solve();
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | def kkk(n):
for i in range(2,min(1000,n-1)):
if n%i==0: return i
return 1
def kkk2(n,p):
for i in range(p,min(1000000,n-1)):
if n%i==0: return i
return 1
for i in range(int(input())):
n=int(input())
r=kkk(n)
if r==1:
print("NO")
else:
n=n//r
rr=kkk2(n,r+1)
if rr==1 or rr*rr==n or r==n//rr:
print("NO")
else:
print("YES")
print(r,rr,n//rr)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Class1 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(br.readLine());
StringBuffer rs = new StringBuffer();
while (t-- > 0) {
int n=Integer.parseInt(br.readLine());
ArrayList<Integer> ar=new ArrayList<>();
for(int i=2;i<=(int)Math.sqrt(n);i++){
if(n%i==0){
ar.add(i);
ar.add(n/i);
}
}
int fl=0;
for(int i:ar){
for(int j:ar){
for(int k:ar){
if(i==j||i==k||j==k){
continue;
}
if(i*j*k==n){
rs.append("YES\n");
rs.append(i+" "+j+" "+k+"\n");
fl=1;
break;
}
}
if (fl==1){
break;
}
}
if(fl==1){
break;
}
}
if(fl==0){
rs.append("NO\n");
}
}
System.out.println(rs);
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
for _ in range(ii()):
n=ii()
fg=0
oans=[-1,-1,-1]
for i in range(2,int(n**0.5)+1):
if n%i==0:
ans=[-1,-1]
for j in range(2,int((n//i)**0.5)+1):
if (n//i)%j==0 and (n//i)//j!=j and j!=i:
ans[0]=j
ans[1]=(n//i)//j
break
if not -1 in ans and ans[0]!=ans[1]!=i:
oans[0]=ans[0]
oans[1]=ans[1]
oans[2]=i
fg=1
break
if fg:
print('YES')
print(*oans)
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>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const long long INF = 0x3f3f3f3f3f3f3f3f;
const long long llinf = (1LL << 62);
const int inf = (1 << 30);
const int nmax = 1e3 + 50;
const int mod = 1e9 + 7;
using namespace std;
int n, x, t, i, a, b, c, bl, j;
vector<int> d;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cerr.tie(0);
cout.tie(0);
cin >> t;
while (t--) {
cin >> n;
d.clear();
for (i = 2; i * i <= n; i++) {
if (n % i == 0) {
d.push_back(i);
if (i * i != n) d.push_back(n / i);
}
}
bl = 0;
for (i = 0; i < (int)d.size(); i++) {
for (j = i + 1; j < (int)d.size(); j++) {
if (n % (d[i] * d[j]) == 0 && n / (d[i] * d[j]) != d[i] &&
n / (d[i] * d[j]) != d[j] && n / (d[i] * d[j]) != 1) {
a = d[i], b = d[j], c = n / (d[i] * d[j]);
bl = 1;
break;
}
}
}
if (!bl)
cout << "NO\n";
else
cout << "YES\n" << a << " " << b << " " << c << '\n';
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
input = sys.stdin.readline
def make_divisors(n):
divisors = []
for i in range(1, int(n**0.5)+1):
if n % i == 0:
divisors.append(i)
if i != n // i:
divisors.append(n//i)
# divisors.sort()
return divisors
def main():
t = int(input())
for _ in range(t):
N = int(input())
d = make_divisors(N)
if len(d) <= 2:
print("NO")
continue
fl = False
for i in d:
if i == 1 or i == N:
continue
f = make_divisors(N // i)
if len(f) <= 2:
continue
for j in f:
if j == 1 or j == (N // i):
continue
k = (N // i) // j
if k != i and j != i and k != j:
print("YES")
print(i, j, k)
fl = True
break
if fl:
break
if not fl:
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 | from math import *
sInt = lambda: int(input())
mInt = lambda: map(int, input().split())
lInt = lambda: list(map(int, input().split()))
def isPrime(n,w):
for i in range(w,int(sqrt(n))+1):
if n%i==0:
return False,i
return True,0
t = sInt()
for _ in range(t):
n = sInt()
q,a = isPrime(n,2)
if q==True:
print("NO")
else:
n = n//a
q,b = isPrime(n,a+1)
if q==True or b==n//b:
print("NO")
else:
print("YES")
print(a,b,n//b)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for _ in ' '*int(input()):
n = int(input())
m=n
p = []
d = 2
ln = 0
x = 0
while d * d <= n:
if n % d == 0:
p.append(d)
n //= d
ln += 1
else:
d += 1
if n > 1:
p.append(n)
ln+=1
#print(p)
if ln>2:
a = p[0]
if p[1]==p[0]:
b = p[1]*p[2]
if ln>3 and b!=m//b//a and a!=m//b//a:
print('YES\n', a,b,m//b//a)
else:
print('NO')
elif p[1]!=m//p[1]//a and a!=m//p[1]//a:
b = p[1]
print('YES\n', a,b,m//b//a)
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())
f=0
a=0
b=0
c=0
f2=0
for i in range(2,int(n**0.5)+1):
if n%i==0:
a=i
f2=1
break
#print(i,'yo')
#print(int(i**0.5)+1)
if f2==1:
for j in range(2,int((n//i)**0.5)+1):
if (n//i)%j==0 and j!=i and (n//i)//j!=j and (n//i)//j!=i:
#print(j)
b=(n//i)//j
c=j
f=1
break
if f==0:
print('NO')
else:
print("YES")
print(a,b,c) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
public class practice {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int T = in.nextInt();
while (T-->0) {
int n = in.nextInt();
int a=0, b=0;
for (int i=2; (i*i)<n; i++) {
if (n%i==0) {
n /= i;
if(a==0) {
a = i;
} else {
b = i;
break;
}
}
}
if(a != 0 && b != 0 && n > b) {
System.out.println("YES");
System.out.println(a + " " + b + " " + n);
} else {
System.out.println("NO");
}
}
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
import java.io.*;
public class CodeForces
{
public static void main(String[] args)throws IOException
{
Scanner sc=new Scanner(System.in);
//Scanner sc=new Scanner(new File("ip.txt"));
int tc,n,a,b,i,sq;
boolean flag;
tc=sc.nextInt();
while(tc-->0)
{
n=sc.nextInt();
sq=(int)Math.sqrt(n);
for(i=2;i<=sq;i++)
if(n%i==0)
break;
if(i==sq+1)
{
System.out.println("NO");
continue;
}
a=i;
n=n/i;
sq=(int)Math.sqrt(n);
for(i=2;i<=sq;i++)
if(n%i==0&&i!=a)
break;
if(i==sq+1)
{
System.out.println("NO");
continue;
}
b=i;
n=n/i;
if(n!=b&&n!=a)
{
System.out.println("YES");
System.out.println(a+" "+b+" "+n);
}
else
System.out.println("NO");
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t = int(input())
def isnotprime(n):
for i in range(1, int(n**0.5)+1):
if n%i == 0:
return True
return False
for _ in range(t):
n = int(input())
if n<8:
print('NO')
continue
found = list()
foundmul = 1
done = False
for i in range(2, int(((n//2)+1)**0.5)+1):
if n%i == 0:
found.append(i)
foundmul *= i
n //= i
if len(found) >= 2:
if n >= 2 and (n not in found):
print('YES')
print(found[0], found[1], n)
done = True
break
else:
done = True
print('NO')
break
if n <= 1:
done = True
print("NO")
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 | '''input
5
64
32
97
2
12345
'''
def chay(a,n):
i = a
while i*i <= n:
if n%i == 0:
b = i
c = int(n/i)
if b == c:
return(0,0)
else:
return(b,c)
i+=1
return(0,0)
def ktra(n):
i = 2
while i*i <= n:
if n%i == 0:
a = i
b, c = chay(a+1,int(n/i))
if b != 0:
return (1,a,b,c)
break
i+=1
return(0,0,0,0)
for i in range(int(input())):
n = int(input())
kq, a, b, c = ktra(int(n))
if kq == 1:
print('YES')
print(a,b,c)
else:
print('NO') | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
for t in range(int(input())):
n = int(input())
a = -1
b = -1
i = 2
while i * i < n:
if n%i == 0:
a = i
n /= i
break
i += 1
i = 2
while i * i < n:
if n%i == 0 and i != a:
b = i
n /= i
break
i += 1
if b == -1 or n == 1:
print("NO")
else:
print("YES")
print(a,b,int(n)) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import collections, math
local = False
if local:
file = open("inputt.txt", "r")
def inp():
if local:
return file.readline().rstrip()
else:
return input().rstrip()
def ints():
return [int(_) for _ in inp().split()]
t = int(inp())
for _ in range(t):
n = int(inp())
sqrtn = int(math.sqrt(n))
found = False
for a in range(2, sqrtn):
if n % a == 0:
rem = n//a
for b in range(a+1, sqrtn):
if rem % b == 0:
c = rem//b
if a != c and a != b and b != c:
print("YES")
print(str(a) + " " + str(b) + " " + str(c))
found = True
break
if found:
break
if not found:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | for _ in range(int(input())):
n=int(input())
f=0
a=set()
i=2
while(i*i<=n):
if n%i==0:
a.add(i)
a.add(n//i)
i+=1
a=list(a)
a.sort()
l=len(a)
for i in range(l):
for j in range(i+1,l):
for k in range(j+1,l):
if a[i]*a[j]*a[k]==n:
print("YES")
print(a[i],a[j],a[k])
f=1
break
if f:
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 | from sys import stdin,stdout
from math import gcd, ceil, sqrt
ii1 = lambda: int(stdin.readline().strip())
is1 = lambda: stdin.readline().strip()
iia = lambda: list(map(int, stdin.readline().strip().split()))
isa = lambda: stdin.readline().strip().split()
mod = 1000000007
n = ii1()
for _ in range(n):
num = ii1()
res = []
for i in range(2, int(sqrt(num)) + 1):
if num % i == 0:
num //= i
res.append(i)
if len(res) == 2 and num > 2:
res.append(num)
if len(set(res)) == 3:
print("YES")
print(*res)
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
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
for _ in range(int(input())):
n = int(input())
a = []
z = int(math.sqrt(n))
if is_prime(n) == True:
print("NO")
else:
for i in range(2, z):
if n%i==0:
a.append(i)
n = n//i
if len(a)==2:
break
if n<2:
print("NO")
elif len(a)==2:
if n==a[0] or n==a[1]:
print("NO")
else:
print("YES")
for i in a:
print(i, end=' ')
print(n)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t = int(input())
for zxx in range(t):
n = int(input())
l =[]
k =int(0)
for i in range(2,int(math.sqrt(n))):
if(n%i == 0 ):
n = n//i
l.append(i)
k = i
if len(l) == 2:
break
elif i>n:
break
else:
k = i
if len(l) == 2:
if(n > i):
l.append(n)
print('YES')
for x in l:
print(x, end=' ')
print()
else:
print('NO')
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
import java.io.*;
public class Linkedlist
{
static PrintWriter pw;
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(new
InputStreamReader(System.in));
}
String next()
{
while (st == null || !st.hasMoreElements())
{
try
{
st = new StringTokenizer(br.readLine());
}
catch (IOException e)
{
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt()
{
return Integer.parseInt(next());
}
long nextLong()
{
return Long.parseLong(next());
}
double nextDouble()
{
return Double.parseDouble(next());
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
return str;
}
}
public static int gcd(int a,int b)
{
return b==0?a:gcd(b,a%b);
}
public static boolean isPrime(long n)
{
if(n==2)return true;
int i=2;
while(i*i<=n)
{
if(n%i==0) return false;
i++;
}
return true;
}
public static long[] remove(long n)
{
long res[]=new long[1000000000];
long rese=0;
int i=0;
while(n>0)
{
long dig=n%10;
n=n/10;
if(dig>0)
{
rese=dig;
res[i++]=rese;
}
}
return res;
}
public static void main(String[] args)
{
FastReader ob=new FastReader();
pw = new PrintWriter(System.out);
int t=ob.nextInt();
while(t-->0) {
int n=ob.nextInt(),a=0,b=0,c=0;
for(int i=2;i<Math.sqrt(n);i++)
{
if(n%i==0)
{
if(a==0)
{
a=i;n/=i;
}
else
{
b=i;
n/=i;
if(a<b && b<n)
{
c=1;
break;
}
}
}
}
if(c==1)
{
pw.println("YES");
pw.println(a+" "+b+" "+n);
}
else
pw.println("NO");
}
pw.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 | num = int(input())
mas = [None] * num
for i in range(num):
mas[i] = int(input())
for i in range(num):
n = mas[i]
n0 = n
i = 2
delit = []
while i * i <= n0:
while n % i == 0:
delit.append(i)
n //= i
i += 1
if n != 1:
delit.append(n)
if len(set(delit)) == 1 and len(delit) > 5:
print("YES")
print(delit[0], delit[0] * delit[0], n0 // delit[0] ** 3)
elif (len(set(delit)) == 2 and len(delit) > 3) or len(set(delit)) > 2:
print("YES")
a = delit[0]
b = delit[-1]
print(a, b, n0 // (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 | for _ in range(int(input())):
n = int(input())
ans = []
count = 0
for i in range(2, int(n**(1/2) + 1)):
if (n % i == 0):
count += 1
ans.append(i)
n = n//i
if(count == 2):
if(n not in ans):
ans.append(n)
break
else:
break
if(len(ans) == 3):
print("YES")
for i in range(3):
ans[i] = str(ans[i])
print(" ".join(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 math
from collections import defaultdict,Counter
# input=sys.stdin.readline
# def print(x):
# sys.stdout.write(str(x)+"\n")
# sys.stdout=open("CP1/output.txt",'w')
# sys.stdin=open("CP1/input.txt",'r')
# m=pow(10,9)+7
t=int(input())
for i in range(t):
n=int(input())
a=b=c=-1
d=-1
for j in range(2,int(math.sqrt(n))+1):
if n%j==0:
a=j
if n//j!=j:
d=n//j
break
if a==-1 or d==-1:
print("NO")
else:
for j in range(2,int(math.sqrt(d))+1):
if d%j==0 and j!=a:
b=j
if d//j!=j:
c=d//j
break
if b==-1 or c==-1:
print("NO")
else:
print("YES")
print(a,b,c)
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | # -*- coding: utf-8 -*-
"""
Created on Sun Jan 19 16:11:01 2020
@author: PC
"""
def product(n):
A = []
L1 = isPrime(n, A)
if len(L1) != 1:
print("NO")
else:
n = n//L1[0]
L2 = isPrime(n, L1)
if len(L2) != 2:
print("NO")
else:
n = n//L2[1]
if n in L2:
print("NO")
else:
L2.append(n)
print("YES")
for el in L2:
print(el, end = " ")
def isPrime(n, B):
d = 2
isPrime = True
while d*d <= n and isPrime:
if n%d == 0 and d not in B:
B.append(d)
isPrime = False
else: d += 1
return B
t = int(input())
for i in range(t):
n = int(input())
product(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 sys import stdin, stdout
from collections import defaultdict
import math
rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
def main():
cases = rll()
for line in stdin:
n = int(line)
ans = []
f1 = 2
while f1 <= math.sqrt(n):
if n % f1 == 0:
ans.append(f1)
break
f1 += 1
if len(ans) == 0:
stdout.write("NO\n")
continue
m = n//f1
f2 = f1 + 1
while f2 <= math.sqrt(m):
if m % f2 == 0:
ans.append(f2)
break
f2 += 1
if len(ans) == 1:
stdout.write("NO\n")
continue
f3 = n//(f1*f2)
if f3 not in {f1, f2}:
stdout.write("YES\n")
stdout.write(" ".join((str(x) for x in [f1, f2, f3])))
stdout.write("\n")
else:
stdout.write("NO\n")
stdout.close()
if __name__ == "__main__":
main() | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
public class Main
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int t=sc.nextInt();
for(int j=0;j<t;j++)
{
int n=sc.nextInt();
int a=0,b=0,c=0,d=0,x=0,flag=0;
for(int i=2;i<=Math.sqrt(n);i++){
if(n%i==0){
a=i;
b=n/i;
break;
}
}
x=(int)Math.max(a,b);
for(int i=(int)Math.min(a,b)+1;i<Math.sqrt(x);i++){
if(x%i==0){
c=i;
d=x/i;
break;
}
}
if(flag==1 || a==0 || b==0 || c==0 || d==0)
System.out.println("NO");
else{
System.out.println("YES");
System.out.println(a+" "+c+" "+d);
}
}
}
}
| 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 | #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#from bisect import bisect_left as bl #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br #c++ upperbound br(array,element)
from collections import defaultdict
import math
def main():
for _ in range(int(input())):
n=int(input())
data=defaultdict(lambda:0)
for x in range(2,math.floor(math.sqrt(n))+1):
if n%x==0:
while n%x==0:
n=n//x
data[x]=data[x]+1
if n!=1:
data[n]+=1
ele=[]
#print(data)
if len(data.keys())>=3:
for x,y in data.items():
if len(ele)==3:
ele[2]*=(x**y)
else:
ele.append(x**y)
print("YES")
print(*ele)
elif len(data.keys())==2:
dat=sorted(data.items(),key=lambda x:x[0])
if dat[0][1]>=3:
ele.append(dat[0][0])
ele.append(dat[0][0]**(dat[0][1]-1))
ele.append(dat[1][0]**(dat[1][1]))
print("YES")
print(*ele)
elif dat[1][1]>=3:
ele.append(dat[1][0])
ele.append(dat[1][0]**(dat[1][1]-1))
ele.append(dat[0][0]**(dat[0][1]))
print("YES")
print(*ele)
elif dat[0][1]>=2 and dat[1][1]>=2:
ele.append(dat[0][0])
ele.append(dat[1][0])
ele.append(dat[1][0]**(dat[1][1]-1)*dat[0][0]**(dat[0][1]-1))
print("YES")
print(*ele)
else:
print("NO")
elif len(data.keys())==1:
done=False
for x,y in data.items():
if y>=6:
print("YES")
print(x,x**2,x**(y-3))
else:
print("NO")
else:
print("NO")
#-----------------------------BOSS-------------------------------------!
# 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")
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 | import java.util.*;
public class Main {
public static void main(String[] args){
Scanner s = new Scanner(System.in);
int t = s.nextInt();
while(t>0){
int a=0;
int b=0;
int c=0;
int n = s.nextInt();
for(int i =2; i*i<=n;i++ ){
a=0;
if(n%i==0){
a=i;
n=n/i;
for(int j=i+1;j*j<=n;j++){
b=0;
c=0;
if(n%j==0){
b=j;
c=n/j;
if(c!=b)
break;
}
b=0;
}
if(b!=0){
break;
}
}
}
if(b==0){
System.out.println("NO");
}else{
System.out.println("YES");
System.out.println(a+" "+b+" "+c);
}
t--;
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 |
for _ in range(int(input())):
n = int(input())
a, i, d = [], 0, 2
while d * d <= n and i < 2:
if n % d == 0:
a.append(d)
n = n // d
i += 1
d += 1
if n >= d and i == 2:
a.append(n)
print("YES")
print(" ".join(map(str, a)))
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t = int(input())
for _ in range(t):
n = int(input())
test = 2
out = []
while len(out) < 2 and test * test < n:
if n % test == 0:
out.append(test)
n //= test
test += 1
if len(out) == 2 and n > out[1]:
print('YES')
print(out[0], out[1], n)
else:
print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t=int(input())
for i in range(t):
n=int(input())
ok=True
if n<24:ok=False
i=1
j=1
for i in range(2,int(n**0.5)+1):
if n%i==0:
n=n//i
break
if i==int(n**0.5):ok=False
if (i+1)>int(n**0.5):ok=False
for j in range(i+1,int(n**0.5)+1):
if n%j==0:
n=n//j
break
if j==int(n**0.5):ok=False
if ok and n>j:
print('YES')
print(i,j,n)
else:print('NO')
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | t = int(input())
for a in range(t):
n = ori = int(input())
num = []
for b in range(2,int(ori**0.5)+1):
# print(n)
if n % b == 0:
num.append(b)
n = n//b
if len(num) == 2:
if n != 1:
num.append(n)
break
num = list(set(num))
if len(num) == 3:
print("YES")
print(" ".join(map(str, num)))
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 | pr = [1]*40000
primes = []
for i in range(2, 40000):
if pr[i]:
primes.append(i)
for j in range(i*i, 40000, i):
pr[j] = 0
def sl(a,b,kkk):
print("YES")
print(a,b,kkk//(a*b))
n = int(input())
for i in range(n):
k = int(input())
kk = k
f = []
for p in primes:
if k % p == 0:
f.append([p,1])
k //= p
while k % p == 0:
f[-1][1] += 1
k //= p
if len(f) > 2:
break
if p*p >= kk:
break
if k != 1:
f.append([k,1])
# print(f)
if len(f) >= 3:
# print("YES")
sl(f[0][0], f[1][0], kk)
elif len(f) == 2:
if f[0][1] >= 2 and f[1][1] >= 2:
sl(f[0][0], f[1][0], kk)
elif f[0][1] >= 3:
sl(f[0][0], f[0][0] * f[0][0], kk)
elif f[1][1] >= 3:
sl(f[1][0], f[1][0] * f[1][0], kk)
else:
print("NO")
else:
if f[0][1] >= 6:
sl(f[0][0], f[0][0] * f[0][0], kk)
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()
for _ in range(int(ri())):
n = int(ri())
p = 2
flag = False
ans = []
while p*p <= n:
if n%p == 0:
ans.append(p)
n = n//p
p+=1
while p*p <= n:
if n%p == 0 and n//p not in ans and n//p != p:
ans.append(p);ans.append(n//p)
flag = True
break
p+=1
if flag:
break
p+=1
if flag :
YES()
print(*ans)
else:
NO() | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import sys
from math import sqrt
inp = sys.stdin.readline
ans = ""
for i in range(int(inp())):
n = int(inp())
arr = ""
c = 0
flag = 0
for i in range(2, round(sqrt(n))+1):
if n % i == 0:
c += 1
arr += str(i)+" "
n = n//i
if c == 2 and n > i:
flag = 1
arr += str(n)+"\n"
break
if flag:
ans += ("YES\n" + arr)
else:
ans += ("NO\n")
print(ans) | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def factorize(n):
i = 2
s = int(math.sqrt(n))
f = dict()
while n > 1:
if i > s:
# print(i,s,n,f)
f[i] = 1
return f
if n % i == 0:
f[i] = f.get(i, 0) + 1
n //= i
else:
i += 1
return f
t = int(input())
for _ in range(t):
n = int(input())
f = factorize(n)
if len(f) == 1:
x = list(f.keys())[0]
if f[x] >= 6:
print("YES")
print(int(x), int(x**2), int(x**(f[x]-3)))
else:
print("NO")
elif len(f) == 2:
x = list(f.keys())
x1, x2 = x[0],x[1]
if (f[x1] == 2 and f[x2] == 2):
print("YES")
print(int(x1), int(x2), int(x1*x2))
elif f[x1] >= 3:
print("YES")
print(int(x1), int(x1*x1), int(n//(x1**3)))
elif f[x2] >= 3:
print("YES")
print(int(x2), int(x2*x2), int(int(n//(x2**3))))
else:
print("NO")
else:
print("YES")
x = list(f.keys())
print(int(x[0]), int(x[1]), (n//(x[0]*x[1])))
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 |
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
public class ProductOfThreeNumbers {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner s=new Scanner(System.in);
int t=s.nextInt();
while(t--!=0){
int n=s.nextInt();
int v=n;
Set<Integer> st=new HashSet<>();
for(int i=2;i<=Math.sqrt(v);i++){
if(v%i==0){
st.add(i);
v=v/i;
break;
}
}
for(int i=2;i<=Math.sqrt(v);i++){
if(v%i==0){
if(!st.contains(i)){
st.add(i);
v=v/i;
break;
}
}
}
if(st.size()!=2){
System.out.println("NO");
continue;
}
int r=1;
for(Integer i:st){
r*=i;
}
if(n%r==0){
int y=n/r;
st.add(y);
if(st.size()==3){
System.out.println("YES");
for(Integer i:st){
System.out.print(i+" ");
}
System.out.println();
}else{
System.out.println("NO");
}
}else{
System.out.println("NO");
}
}
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
long long int hcf(long long int a, long long int b) {
if (b == 0) return a;
return hcf(b, a % b);
}
long long int lcm(long long int a, long long int b) {
return (a * b) / hcf(a, b);
}
bool isprime(long long int n) {
if (n == 1) return false;
for (long long int i = 2; i * i <= n; ++i) {
if (n % i == 0) return false;
}
return true;
}
vector<long long int> primeFactors(long long int n) {
vector<long long int> ans;
while (n % 2 == 0) {
ans.push_back(2);
n = n / 2;
}
for (long long int i = 3; i <= sqrt(n); i = i + 2) {
while (n % i == 0) {
ans.push_back(i);
n = n / i;
}
}
if (n > 2) ans.push_back(n);
return ans;
}
void solve() {
long long int n;
cin >> n;
vector<long long int> a = primeFactors(n);
sort(a.begin(), a.end());
if (a.size() == 3 and a[0] != a[1] and a[1] != a[2]) {
cout << "YES"
<< "\n"
<< a[0] << " " << a[1] << " " << a[2] << "\n";
return;
}
if (a.size() > 3 and a.front() != a.back()) {
cout << "YES"
<< "\n"
<< a[0] << " ";
long long int temp = 1;
for (long long int i = 1; i <= a.size() - 2; i++) temp *= a[i];
cout << temp << " " << a.back() << "\n";
return;
}
if (a.size() > 5) {
cout << "YES "
<< "\n"
<< a[0] << " ";
long long int temp = 1;
long long int temp2 = 1;
for (long long int i = 1; i <= a.size() - 3; i++) temp *= a[i];
for (long long int i = a.size() - 2; i <= a.size() - 1; i++) temp2 *= a[i];
cout << temp << " " << temp2 << "\n";
return;
}
{
cout << "NO"
<< "\n";
return;
}
}
void onlinejudge() {}
int main() {
onlinejudge();
long long int ttt;
ttt = 1;
cin >> ttt;
cout << fixed << setprecision(16);
while (ttt--) solve();
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
import java.io.*;
public class Solution {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
public static void main(String args[]) throws IOException {
int t = Integer.parseInt(br.readLine());
while(t-- > 0) {
boolean flag = true;
int n = Integer.parseInt(br.readLine());
first : for(int i = 2; (i * i) <= n; i++) {
if(n % i == 0) {
for(int j = 2; (j * j) <= i; j++) {
if(i % j == 0) {
if(allDistinct(n / i, j, i / j)) {
bw.write("YES\n");
flag = false;
bw.write((n / i) + " " + j + " " + (i / j) + "\n");
break first;
}
}
}
for(int j = 2; (j * j) <= (n / i); j++) {
if((n / i) % j == 0) {
if(allDistinct(i, j, (n / i) / j)) {
bw.write("YES\n");
flag = false;
bw.write((i) + " " + j + " " + ((n / i) / j) + "\n");
break first;
}
}
}
}
}
if(flag) {
bw.write("NO\n");
}
}
bw.flush();
}
public static boolean allDistinct(int a, int b, int c) {
if(a == b || a == c || b == c) {
return false;
}
return true;
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
boolean[] arr = new boolean[32000];
for(int i=4;i<32000;i+=2) {
arr[i] = true;
}
for(int i=3;i*i<32000;i+=2) {
if(!arr[i]) {
for(int j=i+i;j<32000;j+=i) {
arr[j] = true;
}
}
}
int t = scan.nextInt();
while (t-- > 0) {
int n = scan.nextInt();
int pnt = 2;
int cnt = 0;
LinkedList<Integer> ans = new LinkedList<>();
while (n > 1 && pnt < 32000) {
if(!arr[pnt]) {
if(n % pnt == 0) {
n /= pnt;
ans.add(pnt);
cnt++;
if(cnt > 5) {
break;
}
} else {
pnt++;
}
} else {
while (pnt < 32000 && arr[pnt]) {
pnt++;
}
}
}
if(n > 1) {
ans.add(n);
}
if(ans.size() < 3) {
System.out.println("NO");
continue;
}
int diff = 1;
int now = ans.get(0);
for(int i=1;i<ans.size();i++) {
if(now != ans.get(i)) {
diff++;
}
now = ans.get(i);
}
if((diff == 1 && ans.size() < 6) || (diff == 2 && ans.size() < 4)) {
System.out.println("NO");
continue;
}
System.out.println("YES");
if(diff >= 3) {
System.out.print(ans.get(0)+" ");
int i = 1;
int loc = 1;
while (i < ans.size()-1) {
loc *= ans.get(i);
i++;
}
System.out.println(loc+" "+ans.get(ans.size()-1));
continue;
}
if(diff == 2) {
System.out.print(ans.get(0)+" ");
int loc = 1;
for(int i=1;i<ans.size()-1;i++) {
loc *= ans.get(i);
}
System.out.println(loc+" "+ans.get(ans.size()-1));
continue;
}
//diff 1
System.out.print(ans.get(0)+" ");
int loc = 1;
int i = 3;
while (i < ans.size()) {
loc *= ans.get(i);
i++;
}
System.out.println(ans.get(1)*ans.get(2)+" "+loc);
}
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def run():
num = int(input())
if num < 24:
print("NO")
return
else:
used = set()
i = 2
while i * i <= num:
if num % i == 0 and i not in used:
used.add(i)
num //= i
break
i += 1
while i * i <= num:
if num % i == 0 and i not in used:
used.add(i)
num //= i
break
i += 1
if len(used) < 2 or num in used or num == 1:
print("NO")
else:
print("YES")
print(used.pop(), used.pop(), num)
n = int(input())
for i in range(n):
run()
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible 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())
m = [0, 0, 0]
k = 0
for j in range(2, int(n ** 0.5) + 1):
if n % j == 0 and j not in m:
m[k] = j
k += 1
n //= j
if k == 2 or j > n:
break
if k == 2 and n not in m:
m[2] = n
if m[0] and m[1] and m[2]:
print("YES")
print(m[0], m[1], m[2])
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
n = int(input())
def check_prime(n, k):
for i in range(k, int(pow(n, 0.5)) + 1):
if n%i == 0:
return (0, i)
return (1, -1)
e = {}
for j in range(n):
m = int(input())
d = []
k = 2
for _ in range(2):
x = check_prime(m, k)
#print(x)
if x[0] != 0:
break
else:
m /= x[1]
k = x[1]+1
d.append(str(x[1]) + ' ')
if (len(d) == 2) and (x[1] != m):
d.append(str(int(m)))
#print(d)
e[j] = d
for k in range(n):
if k in e.keys():
print('YES')
print(''.join(e[k]))
else:
print('NO') | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t, k = 0;
cin >> t;
while (t > 0) {
k = 0;
long long n, a, b, c;
cin >> n;
for (long long i = 2; i <= sqrt(n); i++) {
if (n % i == 0) {
k = 0;
for (long long j = 2; j <= sqrt(n / i); j++) {
if (i != j && (n / (i * j)) != i && (n / (i * j)) != j &&
(n % (i * j)) == 0) {
cout << "YES\n";
cout << i << " " << j << " " << n / (i * j) << endl;
k++;
break;
}
}
if (k == 1) break;
}
}
if (k == 0) cout << "NO\n";
t--;
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
while (q--) {
long long int n, x;
cin >> n;
x = n;
vector<long long int> result;
int i = 1;
while (i * i <= x) {
if (x % i == 0) {
result.push_back(i);
if (x / i != i) {
result.push_back(x / i);
}
}
i++;
}
if (result.size() >= 5) {
long long int c = 0, p = 1;
vector<long long int> v;
sort(result.begin(), result.end());
for (int i = 0; i < result.size(); i++) {
if (result[i] != 1) {
if (n % result[i] == 0) {
n = n / result[i];
v.push_back(result[i]);
c++;
p = p * result[i];
}
if (c == 2) {
break;
}
}
}
v.push_back((x) / p);
if ((v[0] != v[1]) && v[0] != v[2] && v[1] != v[2] &&
(v[0] * v[1] * v[2] == x)) {
cout << "YES" << endl;
cout << v[0] << " " << v[1] << " " << v[2] << endl;
} else {
cout << "NO" << endl;
}
} else {
cout << "NO" << endl;
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math as m
t=int(input())
for i in range(t):
n=int(input())
a=0
b=0
c=0
for j in range(2,int(m.sqrt(n))+1):
if n%j==0:
a=j
n=n/j
break
for k in range(a+1,int(m.sqrt(n))+1):
if n%k==0:
b=k
c=n/k
break
if a>1 and b>1 and c>1 and ( a!=b and a!=c and b!=c) :
print("YES")
print(int(a),int(b),int(c))
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main(int argc, char *argv[]) {
std::ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
;
int t;
int n;
cin >> t;
while (t--) {
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 (int(used.size()) < 2 || n == 1 || used.count(n))
cout << "NO" << endl;
else {
cout << "YES" << endl;
set<int>::iterator iter;
iter = used.begin();
used.insert(n);
for (; iter != used.end(); iter++) {
cout << *iter << " ";
}
cout << endl;
}
}
return 0;
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
long long fpow(long long x, long long y, long long p = 1000000007) {
x = x % p;
long long sum = 1;
while (y) {
if (y & 1) sum = sum * x;
sum %= p;
y = y >> 1;
x = x * x;
x %= p;
}
return sum;
}
long long fact[3000007] = {0};
void facto() {
fact[0] = 1;
fact[1] = 1;
for (long long i = 2; i < 3000007; i++)
fact[i] = (fact[i - 1] * i) % 1000000007;
}
long long ncr(long long n, long long r) {
if (r > n) return 0;
long long res = 1;
res = fact[n];
res = (res * (fpow(fact[r], 1000000007 - 2))) % 1000000007;
res = (res * (fpow(fact[n - r], 1000000007 - 2))) % 1000000007;
return res;
}
long long npr(long long n, long long r) {
if (r > n) return 0;
long long res = 1;
res = fact[n];
res = (res * (fpow(fact[n - r], 1000000007 - 2))) % 1000000007;
return res;
}
long long mul(long long x, long long y) { return (x * y) % 1000000007; }
long long add(long long x, long long y) { return (x + y) % 1000000007; }
long long sub(long long x, long long y) {
return (x - y + 1000000007) % 1000000007;
}
long long expomod(long long x, long long y) {
long long result = 1;
x %= 1000000007;
while (y > 0) {
if (y & 1) {
result = (1ll * result * x) % 1000000007;
}
y = y >> 1;
x = (1ll * x * x) % 1000000007;
}
return result;
}
vector<long long> v;
void inline in(long long n) {
v.resize(n + 1);
for (long long i = 1; i <= n; i++) {
cin >> v[i];
}
}
long long f[35];
long long ans, f1;
void add(long long x) {
for (long long i = 31; i >= 0; i--) {
if (x & (1LL << i)) {
f[i] += 1;
}
}
}
void remove(long long x) {
for (long long i = 31; i >= 0; i--) {
if (x & (1LL << i)) {
f[i]--;
if (f[i] == 0) {
ans ^= (1LL << i);
}
}
}
}
void go() {
long long k;
cin >> k;
long long fg = 0;
for (long long i = 2; i * i * i <= (k); i++) {
if (k % i == 0) {
for (long long j = i + 1; j * j <= (k / i); j++) {
if ((k / i) % j == 0) {
if (j != (k / i) / j) {
cout << "YES"
<< "\n"
<< i << " " << j << " " << (k / i) / j << "\n";
fg = 1;
break;
}
}
}
}
if (fg) {
break;
}
}
if (!fg) {
cout << "NO"
<< "\n";
}
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t;
cin >> t;
while (t--) {
go();
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
long long int n, a, b, c, d, i, j, k, l, m, x, t;
cin >> t;
while (t--) {
cin >> n;
d = 0;
if (n % 2 == 0) {
d = 0;
a = 2;
n = n / 2;
x = (n / 2) - 1;
if (x > 999999) x = 999999;
for (i = 3; i <= x; i++) {
if (n % i == 0) {
b = i;
c = n / i;
if (c != b && c != a) {
d = 1;
break;
}
}
}
if (d == 1) {
cout << "YES" << endl;
cout << a << " " << b << " " << c << endl;
} else
cout << "NO" << endl;
} else if (n >= 3 && n % 2 != 0) {
d = 0;
a = 0;
for (i = 3; i <= 1111; i += 2) {
if (n % i == 0) {
a = i;
n = n / i;
break;
}
}
x = (n / 2) - 1;
if (x > 999999) x = 999999;
if (a == 0) {
cout << "NO" << endl;
continue;
}
for (i = a + 2; i <= x; i += 2) {
if (n % i == 0) {
b = i;
c = n / i;
if (c != b && c != a) {
d = 1;
break;
}
}
}
if (d == 1) {
cout << "YES" << endl;
cout << a << " " << b << " " << c << endl;
} else
cout << "NO" << endl;
} else
cout << "NO" << endl;
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.*;
import java.util.*;
import static java.lang.Double.parseDouble;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Math.abs;
import static java.lang.System.exit;
public class Main {
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
void Case() throws IOException {
int n = nextInt();
List<Integer> divs = new ArrayList<>();
for (int i = 2; i * i <= n; i++)
if (n % i == 0) {
divs.add(i);
divs.add(n / i);
}
for (int xxx : divs)
for (int x : divs)
for (int y : divs)
for (int z : divs)
if (x != y && x != z && y != z && x * y * z == n) {
out.println("Yes\n" + x + " " + y + " " + z);
return;
}
out.println("NO");
}
void solve() throws Exception {
int t = nextInt();
while (t-- > 0) Case();
}
// call it like this: lower_bound(a, x + 1) ( /!\ + 1 )
public static int lower_bound(Integer[] a, int v) {
int low = -1, high = a.length;
while (high - low > 1) {
int h = high + low >>> 1;
if (a[h] >= v) {
high = h;
} else {
low = h;
}
}
return high;
}
private String getFraction(int a, int b) {
assert b != 0;
String sign = (a > 0 && b > 0) || (a < 0) && (b < 0) ? "+" : "-";
a = abs(a);
b = abs(b);
int gcd = gcd(a, b);
return sign + (a / gcd) + "/" + (b / gcd);
}
private int gcd(int a, int b) {
while (b > 0) {
int temp = b;
b = a % b;
a = temp;
}
return a;
}
private int lcm(int a, int b) {
return a * (b / gcd(a, b));
}
public static int[] radixSort(int[] f) {
if (f.length < 100) {
Arrays.sort(f);
return f;
}
int[] to = new int[f.length];
{
int[] b = new int[65537];
for (int i = 0; i < f.length; i++) b[1 + (f[i] & 0xffff)]++;
for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
for (int i = 0; i < f.length; i++) to[b[f[i] & 0xffff]++] = f[i];
int[] d = f;
f = to;
to = d;
}
{
int[] b = new int[65537];
for (int i = 0; i < f.length; i++) b[1 + (f[i] >>> 16)]++;
for (int i = 1; i <= 65536; i++) b[i] += b[i - 1];
for (int i = 0; i < f.length; i++) to[b[f[i] >>> 16]++] = f[i];
int[] d = f;
f = to;
to = d;
}
return f;
}
public static long pow(long a, long n, long mod) {
long ret = 1;
int x = 63 - Long.numberOfLeadingZeros(n);
for (; x >= 0; x--) {
ret = ret * ret % mod;
if (n << 63 - x < 0)
ret = ret * a % mod;
}
return ret;
}
public static boolean nextPermutation(Integer[] a) {
int n = a.length;
int i;
for (i = n - 2; i >= 0 && a[i] >= a[i + 1]; i--) ;
if (i == -1)
return false;
int j;
for (j = i + 1; j < n && a[i] < a[j]; j++) ;
int d = a[i];
a[i] = a[j - 1];
a[j - 1] = d;
for (int p = i + 1, q = n - 1; p < q; p++, q--) {
d = a[p];
a[p] = a[q];
a[q] = d;
}
return true;
}
void print(Object x) {
out.print(String.valueOf(x));
out.flush();
}
void println(Object x) {
out.println(String.valueOf(x));
out.flush();
}
// for Map with custom key/value, override toString in your custom class
void printMap(Map map) {
if (map.keySet().size() == 0) return;
Object firstValue = map.keySet().iterator().next();
if (map.get(firstValue) instanceof Queue || map.get(firstValue) instanceof List) {
for (Object key : map.keySet()) {
out.print(String.valueOf(key) + ": ");
Collection values = (Collection) map.get(key);
for (Object value : values) out.print(String.valueOf(value) + " ");
out.println();
}
} else if (map.get(firstValue).getClass().isArray()) {
for (Object key : map.keySet()) {
out.print(String.valueOf(key) + ": ");
Object[] values = (Object[]) map.get(key);
for (Object value : values) out.print(String.valueOf(value) + " ");
out.println();
}
} else {
for (Object key : map.keySet()) {
out.println(String.valueOf(key) + ": " + map.get(key));
}
}
}
private int[] na(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) a[i] = nextInt();
return a;
}
private long[] nal(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++) a[i] = nextLong();
return a;
}
int nextInt() throws IOException {
return parseInt(next());
}
long nextLong() throws IOException {
return parseLong(next());
}
double nextDouble() throws IOException {
return parseDouble(next());
}
String next() throws IOException {
while (tok == null || !tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine());
}
return tok.nextToken();
}
public static void main(String[] args) throws Exception {
try {
boolean isLocal = false;
if (isLocal) {
in = new BufferedReader(new FileReader("solution.in"));
out = new PrintWriter(new BufferedWriter(new FileWriter("solution.out")));
} else {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(new OutputStreamWriter(System.out));
}
//long lStartTime = System.currentTimeMillis();
new Main().solve();
//long lEndTime = System.currentTimeMillis();
//out.println("Elapsed time in seconds: " + (double)(lEndTime - lStartTime) / 1000.0);
in.close();
out.close();
} catch (Throwable e) {
e.printStackTrace();
exit(1);
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | test_cases = int(input())
for z in range(test_cases):
n = int(input())
x=n
l =[]
for i in range(2,int(n**0.5)+2):
if x%i==0:
l.append(i)
x=x/i
if len(l)>=3 :
if l[0]*l[1]*l[2]<=n:
print('YES')
print(l[0],l[1],int(n/(l[0]*l[1])))
break
elif len(l)==2 and (l[0]*l[1])<=(n**0.5):
print('YES')
print(l[0], l[1], int(n / (l[0] * l[1])))
break
if len(l)<2:
print('NO')
if len(l)==2:
if (l[0]*l[1])>(n**0.5) :
print('NO')
elif len(l)>=3:
if l[0]*l[1]*l[2]>n:
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 static java.lang.Math.*;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.math.BigInteger;
public class Main
{
static int mod = 1000000007;
static int MOD = 1000000007;
static int temp = 998244353;
static final long M = (int)1e9+7;
static class Pair implements Comparable<Pair>
{
int first, second;
public Pair(int aa, int bb)
{
first = aa; second = bb;
}
public int compareTo(Pair p)
{
// if(a == p.a) return b - p.b;
// return a - p.a;
if(first == p.first) return second - p.second;
return first - p.first;
}
}
/*
* IO FOR 2D GRID IN JAVA
* char[][] arr = new char[n][m]; //grid in Q.
for(int i = 0;i<n;i++)
{
char[] nowLine = sc.next().toCharArray();
for(int j = 0;j<m;j++)
{
arr[i][j] = nowLine[i];
}
}
* */
static class Reader
{
final private int BUFFER_SIZE = 1 << 16;
private DataInputStream din;
private byte[] buffer;
private int bufferPointer, bytesRead;
public Reader()
{
din = new DataInputStream(System.in);
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public Reader(String file_name) throws IOException
{
din = new DataInputStream(new FileInputStream(file_name));
buffer = new byte[BUFFER_SIZE];
bufferPointer = bytesRead = 0;
}
public String next() 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;
}
int[] readArray(int n) throws IOException {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
public long nextLong() throws IOException
{
long ret = 0;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (neg)
return -ret;
return ret;
}
public double nextDouble() throws IOException
{
double ret = 0, div = 1;
byte c = read();
while (c <= ' ')
c = read();
boolean neg = (c == '-');
if (neg)
c = read();
do {
ret = ret * 10 + c - '0';
}
while ((c = read()) >= '0' && c <= '9');
if (c == '.')
{
while ((c = read()) >= '0' && c <= '9')
{
ret += (c - '0') / (div *= 10);
}
}
if (neg)
return -ret;
return ret;
}
private void fillBuffer() throws IOException
{
bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1)
buffer[0] = -1;
}
private byte read() throws IOException
{
if (bufferPointer == bytesRead)
fillBuffer();
return buffer[bufferPointer++];
}
public void close() throws IOException
{
if (din == null)
return;
din.close();
}
public BigInteger nextBigInteger() {
// TODO Auto-generated method stub
return null;
}
}
public static boolean isPrime(long n) {
if(n == 1)
{
return false;
}
for(long i = 2;i*i<=n;i++)
{
if(n%i == 0)
{
return false;
}
}
return true;
}
public static List<Integer> Sieve(int n)
{
boolean prime[] = new boolean[n+1];
Arrays.fill(prime, true);
List<Integer> l = new ArrayList<>();
for (int p=2; p*p<=n; p++)
{
if (prime[p] == true)
{
for(int i=p*p; i<=n; i += p)
{
prime[i] = false;
}
}
}
for (int p=2; p<=n; p++)
{
if (prime[p] == true)
{
l.add(p);
}
}
return l;
}
public static int gcd(int a, int b)
{
if(b == 0)
return a;
else
return gcd(b,a%b);
}
public static long LongGCD(long a, long b)
{
if(b == 0)
return a;
else
return LongGCD(b,a%b);
}
public static int lcm(int a, int b)
{
return (a / gcd(a, b)) * b;
}
public static int phi(int n) //euler totient function
{
int result = 1;
for (int i = 2; i < n; i++)
if (gcd(i, n) == 1)
result++;
return result;
}
public static int[] computePrefix(int arr[], int n)
{
int[] prefix = new int[n];
prefix[0] = arr[0];
for(int i = 1;i<n;i++)
{
prefix[i] = prefix[i-1]+arr[i];
}
return prefix;
}
public static int fastPow(int x, int n) //include mod at each step if asked and in args of fn too
{
if(n == 0)
return 1;
else if(n%2 == 0)
return fastPow(x*x,n/2);
else
return x*fastPow(x*x,(n-1)/2);
}
public static long power(long x, long y, long p)
{
long res = 1;
x = x % p;
while (y > 0) {
if (y % 2 == 1)
res = (res * x) % p;
y = y >> 1;
x = (x * x) % p;
}
return res;
}
static long modInverse(int n, int p)
{
return power(n, p - 2, p);
}
// Returns nCr % p using Fermat's
// little theorem.
public static long nCr(int n, int r,
int p)
{
if (n<r)
return 0;
if (r == 0)
return 1;
int[] fac = new int[n + 1];
fac[0] = 1;
for (int i = 1; i <= n; i++)
fac[i] = fac[i - 1] * i % p;
return (fac[n] * modInverse(fac[r], p)
% p * modInverse(fac[n - r], p)
% p)
% p;
}
public static int LowerBound(int a[], int x) {
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]>=x) r=m;
else l=m;
}
return r;
}
public static int UpperBound(int a[], int x) {
int l=-1,r=a.length;
while(l+1<r) {
int m=(l+r)>>>1;
if(a[m]<=x) l=m;
else r=m;
}
return l+1;
}
public static void Sort(int[] a) {
List<Integer> l=new ArrayList<>();
for (int i:a) l.add(i);
Collections.sort(l);
//Collections.reverse(l); //Use to Sort decreasingly
for (int i=0; i<a.length; i++) a[i]=l.get(i);
}
//MODULO OPS for addition and multiplication
public static long perfomMod(long x){
return ((x%M + M)%M);
}
public static long addMod(long a, long b){
return perfomMod(perfomMod(a)+perfomMod(b));
}
public static long mulMod(long a, long b){
return perfomMod(perfomMod(a)*perfomMod(b));
}
public static void main(String[] args) throws IOException
{
Reader sc = new Reader();
PrintWriter out = new PrintWriter(System.out);
int t = sc.nextInt();
while(t-- > 0)
{
int n = sc.nextInt();
int c = 0;
List<Integer> l = new ArrayList<>();
for(int i = 2;i*i<=n;i++)
{
if(n%i == 0)
{
if(c == 0)
{
c++;
l.add(i);
n /= i;
}
else if(c == 1)
{
c++;
l.add(i);
if(n/i != i)
{
l.add((n/i));
c++;
break;
}
else {
break;
}
}
}
}
if(c == 3)
{
System.out.println("YES");
for(int x : l)
{
System.out.print(x + " ");
}
System.out.println();
}
else {
System.out.println("NO");
}
}
out.close();
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.util.Scanner;
public class cfTaskC1{
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int t = input.nextInt();
int num;
int[] arr = new int[3];
arr[0] = 0;
arr[1] = 0;
arr[2] = 0;
for(int i = 0; i < t; i++){
num = input.nextInt();
int realnum = num;
int min = 2;
for(int z = min; z*z <= num; z++){
if(num%z == 0){
arr[0] = z;
min = z+1;
num /= z;
break;
}
}
for(int z = min; z*z <= num; z++){
if(num%z == 0){
arr[1] = z;
min = z+1;
break;
}
}
if(arr[0] != 0 && arr[1] != 0){
if(realnum % (arr[0] * arr[1]) == 0 && realnum / (arr[0] * arr[1]) != arr[0] && realnum / (arr[0] * arr[1]) != arr[1]){
arr[2] = realnum / (arr[0] * arr[1]);
}
}
if(arr[2] != 0){
System.out.println("YES");
System.out.println(arr[0] + " " + arr[1] + " " + arr[2]);
}
else{
System.out.println("NO");
}
arr[0] = 0;
arr[1] = 0;
arr[2] = 0;
}
}
} | JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int t, n, fl = 0, fl2;
cin >> t;
while (t--) {
fl = 0, fl2 = 0;
cin >> n;
vector<int> v;
int p = n;
for (int i = 2; i * i <= n; i++) {
if (p % i == 0 && fl <= 1) {
v.push_back(i);
p /= i;
fl++;
}
}
if (v.size() == 2 && v[0] != v[1] && v[0] != p && v[1] != p) {
cout << "YES" << endl;
cout << v[0] << " " << v[1] << " " << p << endl;
} else
cout << "NO" << endl;
}
}
| CPP |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
def dell(num):
global ans
for i in range(2, 2 + int(math.sqrt(num))):
if num % i == 0:
ans.append(i)
return dell(num // i)
if num >= 2:
ans.append(num)
t = int(input())
for _ in range(t):
num = int(input())
ans = []
dell(num)
ans = sorted(ans)
# print(ans)
if len(ans) < 3:
print('NO')
continue
ch1 = ans[0]
ch2 = ans[1]
ind = 2
if ch2 == ch1:
ch2 *= ans[2]
ind = 3
ch3 = 1
for j in range(ind, len(ans)):
ch3 *= ans[j]
if min(ch3, ch1, ch2) >= 2 and ch1 != ch2 and ch1 != ch3 and ch2 != ch3:
print('YES')
print(ch1, ch2, ch3)
else:
print('NO') | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | from math import sqrt
t = int(input())
for i in range(t):
n = int(input())
sol = {}
j = 2
sqroot = {}
sqroot[n] = int(sqrt(n))
while(j<=sqroot[n]):
if len(sol)==2:
break
if n%j==0:
sol[j] = 1
n = n//j
sqroot[n] = int(sqrt(n))
j += 1
if len(sol)==2 and (n not in sol):
print("YES")
for j in sol:
print(j,end=" ")
print(n)
else:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import java.io.*;
import java.util.*;
public class R615C {
public static void main(String[] args) {
JS scan = new JS();
int t = scan.nextInt();
PrintWriter out = new PrintWriter(System.out);
loop:while(t-->0) {
int n = scan.nextInt();
int r = n;
ArrayDeque<Integer> factors = new ArrayDeque<>();
while(n%2==0) {
factors.add(2);
n/=2;
}
for(int i = 3;i*i<=n;i+=2) {
while(n%i==0) {
n/=i;
factors.add(i);
}
}
if(n>2) {
factors.add(n);
}
if(factors.size()<3) {
System.out.println("NO");
continue;
}
int a = factors.poll();
int b = factors.poll();
int c = 1;
while(!factors.isEmpty() && a==b)b*=factors.poll();
while(!factors.isEmpty())c*=factors.poll();
if(a>1 && b>1 && c>1 && a!=b && a!=c && b!=c && a*b*c==r) {
System.out.println("YES");
System.out.println(a+" "+b+" "+c);
}else {
System.out.println("NO");
}
}
out.flush();
out.close();
}
static class JS{
public int BS = 1<<16;
public char NC = (char)0;
byte[] buf = new byte[BS];
int bId = 0, size = 0;
char c = NC;
double num = 1;
BufferedInputStream in;
public JS() {
in = new BufferedInputStream(System.in, BS);
}
public JS(String s) throws FileNotFoundException {
in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
}
public char nextChar(){
while(bId==size) {
try {
size = in.read(buf);
}catch(Exception e) {
return NC;
}
if(size==-1)return NC;
bId=0;
}
return (char)buf[bId++];
}
public int nextInt() {
return (int)nextLong();
}
public long nextLong() {
num=1;
boolean neg = false;
if(c==NC)c=nextChar();
for(;(c<'0' || c>'9'); c = nextChar()) {
if(c=='-')neg=true;
}
long res = 0;
for(; c>='0' && c <='9'; c=nextChar()) {
res = (res<<3)+(res<<1)+c-'0';
num*=10;
}
return neg?-res:res;
}
public double nextDouble() {
double cur = nextLong();
return c!='.' ? cur:cur+nextLong()/num;
}
public String next() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c>32) {
res.append(c);
c=nextChar();
}
return res.toString();
}
public String nextLine() {
StringBuilder res = new StringBuilder();
while(c<=32)c=nextChar();
while(c!='\n') {
res.append(c);
c=nextChar();
}
return res.toString();
}
public boolean hasNext() {
if(c>32)return true;
while(true) {
c=nextChar();
if(c==NC)return false;
else if(c>32)return true;
}
}
}
}
| JAVA |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t=int(input())
for i in range(t):
n=int(input())
c1,c2=0,0
arr=[]
for j in range(2,int(math.sqrt(n))+1):
if(n%j==0):
arr.append(j)
c1=1
n=n//j
store=j
break
if(c1==1):
for j in range(store+1,int(math.sqrt(n))+1):
if(n%j==0):
arr.append(j)
arr.append(n//j)
if(arr[2]==arr[1]):
arr.pop()
break
if(len(arr)==3):
print("YES")
print(arr[0],end=' ')
print(arr[1],end=' ')
print(arr[2])
else:
print("NO")
| PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
for _ in range(int(input())):
n=int(input())
flag=0
for i in range(2,math.ceil(math.sqrt(n))+1):
l=[]
if n%i==0:
l.append(i)
a=n//i
for j in range(2,math.ceil(math.sqrt(a))+1):
if a%j==0 and j!=l[-1]:
l.append(j)
break
if len(l)<2:
continue
b=n//(l[0]*l[1])
if b!=l[0] and b!=l[1] and b!=1:
l.append(b)
print("YES")
print(*l)
flag=1
break
else:
continue
if flag==0:
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
t=int(input())
for i in range(t):
n=int(input())
flag=0
for i in range(2,int(math.sqrt(n))+1):
if(n%i==0):
t=n//i
for j in range(2,int(math.sqrt(t))+1):
if(t%j==0):
if(j!=i and t//j!=i and j!=t//j):
flag=1
print("YES")
print(str(i)+" "+str(j)+" "+str(t//j))
break
if(flag==1):
break
if(flag==0):
print("NO") | PYTHON3 |
1294_C. Product of Three Numbers | You are given one integer number n. Find three distinct integers a, b, c such that 2 β€ a, b, c and a β
b β
c = n or say that it is impossible to do it.
If there are several answers, you can print any.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 100) β the number of test cases.
The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 β€ n β€ 10^9).
Output
For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β
b β
c for some distinct integers a, b, c such that 2 β€ a, b, c.
Otherwise, print "YES" and any possible such representation.
Example
Input
5
64
32
97
2
12345
Output
YES
2 4 8
NO
NO
NO
YES
3 5 823 | 2 | 9 | import math
for _ in range(int(input())):
n=int(input())
a=[]
for i in range(2,int(math.sqrt(n))+1):
if n%i==0 and not(i in a):
a.append(i)
n/=i
break
for i in range(2,int(math.sqrt(n))+1):
if n%i==0 and not(i in a):
a.append(i)
n/=i
break
if len(a)<2 or n==1 or (n in a):
print("NO")
else:
a.append(int(n))
print("YES")
print(*a) | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.