Search is not available for this dataset
name
stringlengths
2
112
description
stringlengths
29
13k
source
int64
1
7
difficulty
int64
0
25
solution
stringlengths
7
983k
language
stringclasses
4 values
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin, stdout from collections import defaultdict import math rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() def main(): cases = int(input()) for line in stdin: n = int(line) ans = [] f1 = 2 while f1**2 <= 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**2 <= 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") 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 math def primefactorisation(n): p=[] while(n%2==0): n//=2 p.append(2) i=3 while(i<=math.sqrt(n)): while(n%i==0): n//=i p.append(i) i+=2 if n>2: p.append(n) return p for _ in range(int(input())): n=int(input()) A=primefactorisation(n) if len(A)>=3: a=A[0] b=A[1] if b==a: b=A[1]*A[2] c=n//(a*b) if c==a or c==b or c==1: print("NO") else: print("YES") print(a," ",b," ",c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long int t = 1; cin >> t; while (t--) { long long int n; cin >> n; vector<long long int> v; long long int x = n; while (n % 2 == 0) { v.push_back(2); n /= 2; } for (long long int i = 3; i * i <= n; i += 2) { while (n % i == 0) { v.push_back(i); n /= i; } } if (n > 2) v.push_back(n); map<long long int, long long int> mp; for (long long int i = 0; i < v.size(); i++) mp[v[i]]++; vector<long long int> v1; if (mp.size() > 2) { cout << "YES\n"; map<long long int, long long int>::iterator it; long long int cnt = 0; for (it = mp.begin(); it != mp.end(); it++) { if (cnt == 2) break; cout << (long long int)pow(it->first, it->second) << " "; cnt++; } long long int x = 1; for (; it != mp.end(); it++) x = (x * pow(it->first, it->second)); cout << x << '\n'; } else if (mp.size() == 2) { map<long long int, long long int>::iterator it = mp.begin(); long long int cnt = it->second; it++; cnt += it->second; if (cnt < 4) cout << "NO\n"; else { cout << "YES\n"; it = mp.begin(); long long int x, y, z; x = it->first; y = pow(it->first, it->second - 1); it++; z = it->first; y *= pow(it->first, it->second - 1); cout << x << " " << y << " " << z << '\n'; } } else { map<long long int, long long int>::iterator it = mp.begin(); if (it->second >= 6) { cout << "YES\n"; cout << it->first << " " << (long long int)pow(it->first, 2) << " " << (long long int)pow(it->first, it->second - 3) << '\n'; } else cout << "NO\n"; } } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from collections import Counter, defaultdict from sys import stdin, stdout raw_input = stdin.readline for t in xrange(input()): n=input() l=[] f=0 for i in xrange(2,min(n+1,10001)): if n%i==0: l.append(i) n/=i if len(l)==2 and n not in l and n>1: f=1 break elif len(l)==2: break if f: stdout.write('YES\n') for j in l: stdout.write(str(j)+' ') stdout.write(str(n)+'\n') else: stdout.write('NO\n')
PYTHON
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math from itertools import permutations def divisores(n): large_divisors = [] for k in range(1, int(math.sqrt(n) + 1)): if(n % k == 0): yield k if(k*k != n): large_divisors.append(n//k) for d in reversed(large_divisors): yield d t = int(input()) for k in range(t): q = int(input()) divisoresL = (list(divisores(q))) if(len(divisoresL) < 5): print("NO") else: flag = 0 divisoresL.remove(divisoresL[0]) divisoresL.remove(divisoresL[len(divisoresL)-1]) for subset in permutations(divisoresL, 3): if(subset[0]*subset[1]*subset[2] == q): print("YES") print("{} {} {}".format(subset[0], subset[1], subset[2])) 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 collections class Solution: def solve(self, n): used = set() a = 2 while a*a <= n: if n % a == 0 and a not in used: used.add(a) n //= a break a += 1 b = 2 while b*b <= n: if n % b == 0 and b not in used: used.add(b) n //= b break b += 1 # print(used) if len(used) < 2 or n in used or n == 1: return (False, None) else: return (True, list(used) + [n]) # Gets Time limit exceeded # for a in range(2,n//(2**2)+1): # for b in range(2, a): # for c in range(2, b): # res = a*b*c # if res == n: # return (True, sorted([c,b,a])) # elif res > n: # break # if a*b > n//2: # break # return (False, None) sol = Solution() t = int(input().strip()) for i in range(t): n = int(input().strip()) answer = sol.solve(n) if answer[0]: print("YES") print(" ".join(map(str, answer[1]))) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for _ in range(int(input())): n = int(input()) flag = False if n < 24: print('NO') elif n == 24: print('YES') print(2, 3, 4) else: for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: a = i n = n / i for j in range(a + 1, int(math.sqrt(n)) + 1): if n % j == 0: b = j c = int(n / j) if c != b and a != c: print('YES') print(a, b, c) flag = True break if flag is True: break if flag is False: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; bool test(void) { long long N; scanf("%lld", &N); long long u = N; vector<pair<long long, int>> A; for (long long i = 2; i * i <= u; ++i) { int q = 0; while (u % i == 0) { ++q; u /= i; } if (q) { A.push_back({i, q}); } } if (u > 1) A.push_back({u, 1}); vector<long long> D{1}; for (auto [p, q] : A) { int s = D.size(); for (int i = 0; i < s; ++i) { long long u = D[i]; for (int k = 0; k < q; ++k) { u *= p; D.push_back(u); } } } int s = D.size(); for (int i = 0; i < s; ++i) { long long a = D[i]; if (a == 1) continue; for (int j = 0; j < i - 1; ++j) { long long b = D[j]; if (b == 1) continue; if (N % (a * b) == 0) { long long c = N / (a * b); if (c == 1) continue; if (a != c && b != c) { printf("YES\n"); printf("%lld %lld %lld\n", a, b, c); return true; } } } } return false; } int main(void) { int T; scanf("%d", &T); while (T--) { if (!test()) printf("NO\n"); } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for _ in range(int(input())): n = int(input()) t = n a1 = [] while n % 2 == 0: a1.append(2), n = n / 2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: a1.append(int(i)), n = n / i if n > 2: a1.append(int(n)) l = len(a1) a = list(set(a1)) p = len(a) if p == 1 and l >= 6: if a[0] != t//(a[0]**3) and a[0]**2 != t//(a[0]**3): print("YES") print(a[0],a[0]**2,t//(a[0]**3)) else: print("NO") elif (p >= 2 )and (l>= 3): if a[0] != t//(a[0]*a[1]) and a[1] != t//(a[0]*a[1]): print("YES") print(a[0],a[1],t//(a[0]*a[1])) else: print("NO") else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for qwe in range(t): # n1 = int(f.readline()) n1 = int(input()) flag = False for i1 in range(2, int(n1**0.5) + 1): if n1 % i1 == 0: a = i1 n2 = n1 // i1 for i2 in range(2, int(n2**0.5) + 1): if n2 % i2 == 0 and i2 != a: b = i2 c = n2 // i2 if c != a and c != b: flag = True if flag: break if flag: break if flag: print("YES") print(a, b, c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, arr[10]; cin >> n; int cnt = 0; for (int i = 2; i < sqrt(n); i++) { if (n % i == 0 && ((n / i) != i)) { arr[0] = i; n = n / i; cnt = 5; break; } } if (cnt != 5) cout << "NO" << endl; else { for (int i = 2; i < sqrt(n); i++) { if (n % i == 0 && ((n / i) != i) && (arr[0] != i) && (arr[0] != n / i)) { arr[1] = i; arr[2] = n / i; cnt = 10; break; } } if (cnt != 10) cout << "NO" << endl; else { cout << "YES" << endl; cout << arr[0] << " " << arr[1] << " " << arr[2] << 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
#Codeforces - Product of Three Numbers t = int(input()) while t != 0: n = int(input()) i = 2 result = 'NO' while i * i * i < n: if n % i == 0: j = i + 1 while j * j < int(n/i): if n % (i * j) == 0: result = '{} {} {}'.format(i, j, int(n/(i*j))) break j += 1 break i += 1 if result != 'NO': print('YES') print(result) 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
ans="" for _ in range(int(input())): n=nn=int(input()) l1=[]; i=2 while len(l1)<2 and i*i<=nn: if n%i==0: l1.append(i); n//=i i+=1 if len(l1)<2 or l1[1]==n or l1[0]==n: ans+="NO\n" else: ans+="YES\n"; ans+=f"{l1[0]} {l1[1]} {n}\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 for _ in range(int(input())): n=int(input()) l=[] x=n for i in range(2,int(math.sqrt(n))+1): if(len(l)<2): if(x%i==0): l.append(int(i)) x/=i else: break if((x not in l) and (len(l)==2)): print('YES') print(str(l[0])+' '+str(l[1])+' '+str(int(x))) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys sys.setrecursionlimit(10**9) import atexit import io from collections import defaultdict, Counter _INPUT_LINES = sys.stdin.read().splitlines() input = iter(_INPUT_LINES).__next__ _OUTPUT_BUFFER = io.StringIO() sys.stdout = _OUTPUT_BUFFER @atexit.register def write(): sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) IA =lambda: map(int,input().split()) ans=[0,0,0,0] def solve(n): num=int(0) i=int(2) tmp=1 m=n while i*i<=n: if n%i==0: n=n//i tmp*=i if tmp not in ans: num+=1 ans[num]=tmp tmp=1 if num>=3: ans[num]*=n return 1 i+=1 if n>1: if tmp*n not in ans: num+=1 ans[num]=n*tmp if num>=3: return 1 else:return -1 T=int(input()) for t in range(0,T): ans=[0,0,0,0] n=int(input()) if solve(n)==1: print("YES") for i in range(1,4): print(ans[i],end=" ") print() else:print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def solve(): n = int(input()) divs = [] for i in range(2, int(n**0.5) + 2): if n % i == 0: n //= i divs.append(i) if len(divs) == 2: if n > divs[1]: print ("YES") print (*divs, n) return else: print ("NO") return print ("NO") t = int(input()) for _ in range(t): solve()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; while (t--) { cin >> n; set<int> values; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { values.insert(i); n /= i; break; } } for (int i = 2; i * i <= n; i++) { if (n % i == 0 && !values.count(i)) { values.insert(i); n /= i; break; } } if ((int)values.size() < 2 || n == 1 || values.count(n)) { cout << "NO" << endl; } else { values.insert(n); cout << "YES" << endl; for (auto it : values) cout << it << " "; cout << endl; } } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for _ in range(int(input())): n = int(input()) dic = {} x = n if x%2==0: dic[2] = 0 while x%2==0: x//=2 dic[2] += 1 for i in range(3,int(math.sqrt(x))+1,2): if x%i==0: dic[i] = 0 while x%i==0: x//=i dic[i] += 1 if x>2: dic[x] = 1 # print(dic) if len(dic)==3: print('YES') ans = [] for i in dic: ans += [pow(i,dic[i])] print(*ans) elif len(dic)>3: print('YES') ans = [] c = 0 for i in dic: ans += [pow(i,dic[i])] c+=1 dic[i] = 0 if c==3: break t = 1 for i in dic: t*= pow(i,dic[i]) ans[-1]*=t print(*ans) elif len(dic)==2: s = 0 for i in dic: s+=dic[i] if s>=4: print('YES') ans = [] b = 1 for i in dic: ans += [i] b*= pow(i,dic[i]-1) ans+=[b] print(*ans) else: print('NO') else: for i in dic: if dic[i]>=6: print('YES') print(i,pow(i,2),pow(i,dic[i]-3)) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using ll = long long; using namespace std; const int N = 1e6 + 1, mod = 1e9 + 7; int t; int main() { cin.tie(0)->sync_with_stdio(0); cin >> t; while (t--) { int n; cin >> n; vector<int> divisors; int d = n, s = sqrt(n); for (int i = 2; i <= s; i++) { if (d % i == 0) { divisors.push_back(i); d /= i; } } if (d > 1) { divisors.push_back(d); } if (divisors.size() == 1) { int a = divisors[0], cnt = 0; while (n % a == 0) { n /= a; cnt++; } if (cnt >= 6) { cout << "YES\n"; cout << a << ' ' << a * a << ' ' << n / (a * a * a) << '\n'; } else { cout << "NO\n"; } } else if (divisors.size() >= 3) { int a = divisors[0], b = divisors[1]; int c = n / divisors[0] / divisors[1]; if (a == c || b == c) { cout << "NO\n"; } else { cout << "YES\n"; cout << 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
for _ in range(int(input())): n=int(input()) a=b=c=1 for i in range(2,int(n**0.5)+1): if(n%i == 0): a=i n//=i break for i in range(2,int(n**0.5)+1): if(n%i == 0): if(i!=a): b=i n//=i break if(n!=1 and n!=a and n!=b): c=n if(a==1 or b==1 or c==1): print("NO") else: print("YES") print(a,b,c,sep=" " )
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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 yyy : divs) for (int xxx : divs) if(xxx != 1 && yyy != 1) 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
t=int(input()) for _ in range(t): n=int(input()) fin=[] for i in range(2,40000): if(n%i==0): n=n//i fin.append(i) break if(len(fin)==0): print("NO") else: for i in range(2,40000): if(n%i==0 and i!=fin[0] ): n=n//i fin.append(i) break if(len(fin)<=1 or n==fin[0] or n==1 or n==fin[1]): print("NO") else: fin.append(n) print("YES") print(*fin)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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 p3n(cur): j = 2 while j * j <= cur: if cur % j == 0: # print(cur, j) oth = cur // j k = 2 while k * k <= oth: if oth % k == 0 and j != k != oth // k != j: print('YES') print(j, k, oth // k) return k += 1 j += 1 print('NO') t = int(input()) tc = [] for i in range(t): tc.append(int(input())) for i in range(t): p3n(tc[i])
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for _ in range(int(input())): n = int(input()) a = -99 t = 0 if(n < 24): print("NO") else: for i in range(2, (int)(math.sqrt(n)) + 1): if(n%i == 0): if(a > 0): if(n%(i*a) == 0): if(a != i) and (i != (n//(i*a))) and (n//(i*a) > 2) and (a != (n//(i*a))): print("YES") print(a,end=' ') print(i, end=' ') print((n//(i*a))) t = 1 break else: a = i if(n%(i*a) == 0): if(a != i) and (i != (n//(i*a))) and (n//(i*a) > 2) and (a != (n//(i*a))): print("YES") print(a,end=' ') print(i, end=' ') print((n//(i*a))) t = 1 break if(t == 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; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; long long t; cin >> t; while (t--) { long long n, f = 0; cin >> n; long long i = 2; while (i * i < n) { if (n % i == 0) { f = 1; break; } i++; } n = n / i; if (n > i && f) { f = 0; long long j = i + 1; while (j * j < n) { if (n % j == 0) { f = 1; break; } j++; } n /= j; if (f && n > j) cout << "YES\n" << i << " " << j << " " << n << "\n"; } if (f == 0) cout << "NO\n"; } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int n; while (t--) { cin >> n; vector<int> v; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { v.push_back(i); n /= i; } if (v.size() == 2) break; } if (n != 1) v.push_back(n); if (v.size() == 3 && v[0] != v[1] && v[0] != v[2] && v[1] != v[2]) { printf("YES\n"); for (auto x : v) cout << x << ' '; cout << endl; } else { printf("NO\n"); } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for i in range(int(input())): q=int(input()) k=[] t=0 for i in range(2,int(math.sqrt(q))+1): if q%i==0: q=q//i t=1 k.append(str(i)) break if t==1: for i in range(2,int(math.sqrt(q))+1): if q%i==0 and (str(i) not in k): q=q//i t=2 k.append(str(i)) break else: print('NO') if t==2 and str(q) not in k: k.append(str(q)) print('YES') print(' '.join(k)) elif t!=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
t=int(input()) for _ in range(t): n=int(input()) a=[] append=a.append for i in range(2,int(n**0.5)+1): if(n%i==0): append(i) n=n//i if(len(a)==2): if n!=1: append(n) break a=list(set(a)) if(len(a)==3): print("YES") print(a[0],a[1],a[2]) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.*; import java.util.*; public class main { public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw= new PrintWriter(System.out); int t= Integer.parseInt(br.readLine()); for (int i = 0; i < t; i++) { int n = Integer.parseInt(br.readLine()); boolean possible=false; o:for (int j = 2; j <= Math.sqrt(n); j++) { if(n%j==0) { int temp=n/j; for (int k = j+1; k <= Math.sqrt(temp); k++) { if(temp%k==0) { if(j!= k && k!=temp/k && j!=temp/k) { pw.println("YES"); pw.println(temp/k + " " + k + " " + j); possible=true; } break o; } } } } if(!possible)pw.println("NO"); } pw.close(); } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t = int(input()) for _ in range(t): n = int(input()) nn = n fact = dict() i = 2 while i <= math.sqrt(nn): if n % i == 0: n //= i try: fact[i] += 1 except: fact[i] = 1 else: i += 1 if n != 1: fact[n] = 1 if len(fact) == 0: print("NO") continue if len(fact) > 3: k = list(fact.keys()) print("YES") print(k[0]**fact[k[0]], k[1]**fact[k[1]], end=" ") num = 1 for i in range(2, len(k)): num *= k[i] ** fact[k[i]] print(num) if len(fact) == 3: print("YES") a, b, c = list(fact.keys()) print(a**fact[a], b**fact[b], c**fact[c]) if len(fact) == 1: k = list(fact.keys())[0] if fact[k] < 6: print("NO") else: print("YES") print(k, k*k, k**(fact[k]-3)) continue if len(fact) == 2: a, b = list(fact.keys()) if fact[a] >= 2 and fact[b] >= 2: print("YES") print(a, b, (a ** (fact[a] - 1)) * (b ** (fact[b] - 1))) elif fact[a] == 1 and fact[b] >= 3: print("YES") print(a, b, b ** (fact[b]-1)) elif fact[b] == 1 and fact[a] >= 3: print("YES") print(a, b, a ** (fact[a]-1)) else: print("NO") continue
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; using vi = vector<long long int>; using vvi = vector<vi>; using vb = vector<bool>; using vc = vector<char>; using vs = vector<string>; using vld = vector<long double>; using pii = pair<long long int, long long int>; using psi = pair<string, long long int>; using pci = pair<char, long long int>; using vpii = vector<pii>; long long int mod = 1e9 + 7; long long int const maxn = 1e5 + 5; long long int const inf = 1e18; long long int add(long long int a, long long int b) { return ((a % mod) + (b % mod)) % mod; } long long int mul(long long int a, long long int b) { return ((a % mod) * (b % mod)) % mod; } long long int powm(long long int x, long long int n, long long int M) { long long int result = 1; while (n > 0) { if (n % 2 == 1) result = (result * x) % M; x = (x * x) % M; n = n / 2; } return result; } long long int modinverse(long long int a, long long int m) { return powm(a, m - 2, m); } bool prime(long long int x) { if (x <= 1) return false; for (int i = 2; i <= sqrt(x); i++) if (x % i == 0) return false; return true; } long long int divisor(long long int x) { long long int cnt = 0; for (int i = 1; i <= sqrt(x); i++) { if (x % i == 0) { if (i != x / i) cnt += 2; else cnt += 1; } } return cnt; } vector<long long int> sieve(long long int n) { bool prim[n + 1]; memset(prim, true, sizeof(prim)); for (long long int p = 2; p * p <= n; p++) { if (prim[p] == true) { for (int i = p * p; i <= n; i += p) prim[i] = false; } } vector<long long int> v; for (int i = 2; i <= n; i++) if (prim[i]) v.push_back(i); return v; } void solve() { set<long long int> st; long long int x = 0; long long int n; cin >> n; long long int m = n; for (int i = 2; i * i <= m and x < 2; i++) { if (n % i == 0) { st.insert(i); x++; n /= i; } } st.insert(n); if ((long long int)st.size() == 3) { cout << "YES\n"; for (auto it = st.begin(); it != st.end(); it++) cout << *it << " "; cout << endl; } else cout << "NO\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long int t; t = 1; cin >> t; while (t--) { solve(); } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math from functools import reduce t = int(input()) for cas in range(t): n = int(input()) ans = [] m = n sqrt_n = int(math.sqrt(m)) for i in range(2, sqrt_n): cal = 0 if n == 1: break while n % i == 0 and n > 1: n //= i ans.append(i) if n > 1: ans.append(n) if len(ans) < 3: print("NO") elif len(ans) == 3: if len(set(ans)) < 3: print("NO") else: print("YES") print(ans[0], ans[1], ans[2]) elif len(ans) == 4: if len(set(ans)) == 1: print("NO") else: print("YES") print(ans[0], ans[1] * ans[2], ans[3]) elif len(ans) == 5: if len(set(ans)) == 1: print("NO") else: print("YES") print(ans[0], ans[1] * ans[2] * ans[3], ans[4]) else: print("YES") print(ans[0], ans[1] * ans[2], m//(ans[0]*ans[1]*ans[2])) #reduce(lambda x, y: x * y, ans[3:])
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#!/usr/bin/env pypy rr= lambda: input().strip() rri= lambda: int(rr()) rrm= lambda: [int(x) for x in rr().split()] def fact(n): res=[] for i in range(2, int(n**.5)+1): if n%i==0: res.append(i) res.append(n//i) if (int(n**.5)**2==n): res.pop() return res def sol(): n=rri() f=fact(n) #print(f) if (len(f)<3): print("NO") return f.sort() a=f[0] d=n//a for i in range(1, len(f)): for j in range(i+1, len(f)): if f[i]*f[j]==d: print("YES") print (a, f[i], f[j]) return print("NO") return t=rri() for _ in range(t): #a,b,c=rrm() sol() #print(ans)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin input = lambda: stdin.readline().strip() for _ in range(int(input())): n = int(input()) a = [] for i in range(2,n//2): if(n%i==0): n //= i a.append(i) if(len(a)==2 or n<i*i): break if(len(a)==2 and n not in a and n>=2): print("YES") print(*a,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
tests = int(input()) for t in range(tests): n = int(input()) initN = n i = 2 a,b = 0,0 while True: if i**2 > initN: print("NO") break if n%i == 0: n=n/i if a == 0: a=i elif b==0: b=i if a > 0 and b > 0 and n > 1 and a != b and b !=n and a!=n: print("YES") print(str(a)+" "+str(b)+" "+str(int(n))) break i+=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 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') def inp(): return sys.stdin.readline().rstrip() def mpint(): return map(int, inp().split(' ')) def itg(): return int(inp()) # ############################## import # ############################## main def solve(): n = itg() ans = [] a = 2 while a * a <= n: if not n % a: ans.append(a) n //= a if len(ans) == 2: ans.append(n) break a += 1 if len(ans) == 3 and ans[0] < ans[1] < ans[2]: print("YES") print(*ans) else: print("NO") def main(): # solve() # print(solve()) for _ in range(itg()): # print(solve()) solve() # print("yes" if solve() else "no") # print("YES" if solve() else "NO") DEBUG = 0 URL = '' if __name__ == '__main__': # 0: normal, 1: runner, 2: interactive, 3: debug if DEBUG == 1: import requests from ACgenerator.Y_Test_Case_Runner import TestCaseRunner runner = TestCaseRunner(main, URL) inp = runner.input_stream print = runner.output_stream runner.checking() else: if DEBUG != 3: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) if DEBUG: _print = print def print(*args, **kwargs): _print(*args, **kwargs) sys.stdout.flush() main() # Please check!
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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.io.*; import java.math.BigInteger; public class CF { private static FS sc = new FS(); private static class FS { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) try { st=new StringTokenizer(br.readLine()); } catch (IOException e) {} return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } } private static class extra { static int[] intArr(int size) { int[] a = new int[size]; for(int i = 0; i < size; i++) a[i] = sc.nextInt(); return a; } static long[] longArr(int size) { long[] a = new long[size]; for(int i = 0; i < size; i++) a[i] = sc.nextLong(); return a; } static long intSum(int[] a) { long sum = 0; for(int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } static long longSum(long[] a) { long sum = 0; for(int i = 0; i < a.length; i++) { sum += a[i]; } return sum; } static LinkedList[] graphD(int vertices, int edges) { LinkedList[] temp = new LinkedList[vertices+1]; for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>(); for(int i = 0; i < edges; i++) { int x = sc.nextInt(); int y = sc.nextInt(); temp[x].add(y); } return temp; } static LinkedList[] graphUD(int vertices, int edges) { LinkedList[] temp = new LinkedList[vertices+1]; for(int i = 0; i <= vertices; i++) temp[i] = new LinkedList<>(); for(int i = 0; i < edges; i++) { int x = sc.nextInt(); int y = sc.nextInt(); temp[x].add(y); temp[y].add(x); } return temp; } static void printG(LinkedList[] temp) { for(LinkedList<Integer> aa:temp) System.out.println(aa); } } static LinkedList[] temp; static int mod = (int)Math.pow(10, 9) + 7; public static void main(String[] args) { int t = sc.nextInt(); // int t = 1; StringBuilder ret = new StringBuilder(); while(t-- > 0) { int n = sc.nextInt(); int a = 0, b = 0; for(int i = 2; i*i <= n; i++) { if(n%i == 0) { n /= i; a = i; break; } } for(int i = 2; i*i <= n; i++) { if(n%i == 0 && i != a) { n /= i; b = i; break; } } if(a == 0 || b == 0 || a == n || b == n || n == 1) ret.append("NO\n"); else { ret.append("YES\n"); ret.append(a + " " + b + " " + n + "\n"); } } System.out.println(ret); } }
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> const long long int mod = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int t = 0; cin >> t; while (t--) { long long int n = 0; cin >> n; if (n < 24) { cout << "NO\n"; continue; } else { vector<long long int> f; for (long long int i = 2; i * i <= n; ++i) { if (n % i == 0) { f.push_back(i); n /= i; } } f.push_back(n); sort(f.begin(), f.end()); if (f.size() > 3) { for (long long int i = 3; i < f.size(); ++i) { f[2] *= f[i]; } } if (f.size() < 3) cout << "NO\n"; else if (f[0] != f[1] && f[0] != f[2] && f[1] != f[2]) { cout << "YES\n"; cout << f[0] << " " << f[1] << " " << f[2] << "\n"; } else cout << "NO\n"; } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; using lli = long long int; using ulli = unsigned long long int; using db = double; using vint = vector<int>; using vlli = vector<vint>; using vvint = vector<vint>; using vvlli = vector<vlli>; using cd = complex<double>; const int inf = 1e9 + 5; const lli infl = 1e18 + 5; void solve() { int n; cin >> n; int sqn = sqrt(n); for (int a = 2; a <= sqn; ++a) { if (n % a == 0) { int sqna = sqrt(n / a); for (int b = 2; b <= sqna; ++b) { if ((n / a) % b == 0 and (a != b and b != (n / a) / b and a != (n / a) / b and (n / a) / b >= 2)) { cout << "YES" << "\n"; cout << a << " " << b << " " << (n / a) / b << "\n"; return; } } } } cout << "NO" << "\n"; return; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) solve(); return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t=int(input()) j=0 while j<t: n=int(input()) i=1 var1='NO' var2='NO' while i<(n**(1/3)) and var1=='NO': i+=1 if n%i==0: var1='YES' a=i if var1=='YES': product=(n/a) i=(a+1) while i<(product**(0.5)) and var2=='NO': if product%i==0: var2='YES' b=i c=product/b i+=1 if var1=='YES' and var2=='YES': print('YES') print(a,b,int(c)) else: print('NO') j+=1
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def solve(n): for a in range(2, math.ceil(n ** (1 / 3))): if n % a == 0: for b in range(a + 1, math.ceil(math.sqrt(n // a))): c = n // a // b if c * a * b == n: print('YES') print('%d %d %d' % (a, b, c)) return False return True t = int(input()) for i in range(t): n = int(input()) if solve(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
# lines = [int(line) for line in open('CodeForces_1294C.in', 'r').readlines()[1:]] lines = [int(line) for line in [*open(0)][1:]] for n in lines: sol = [] d = 2 done = False while d * d <= n: if n % d == 0: n //= d sol.append(d) if len(sol) == 2: done = True if n not in sol: sol.append(n) print("YES") print(' '.join(map(str, sol))) else: print("NO") break d += 1 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
from collections import Counter from collections import defaultdict import math # method to print the divisors def factors(n) : l=list() # Note that this loop runs till square root i = 1 while i <= math.sqrt(n): if (n % i == 0) : # If divisors are equal, print only one if (n / i == i) : l.append(i) else : # Otherwise print both l.append(i) l.append(n//i) i = i + 1 return l t=int(input()) for _ in range(0,t): n=int(input()) l=factors(n) #print(l,t) if(len(l)==2): print("NO") continue else: a=l[2] b=n//a l2=factors(b) f=0 #print(a,l2) if(len(l2)==2): print("NO") continue for i in range(2,len(l2)): if(a!=l2[i] and l2[i]!=b//l2[i] and b//l2[i]!=a and a>=2 and l2[i]>=2 and b//l2[i]>=2): f=1 print("YES") print(a,l2[i],b//l2[i]) 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
#right preference q = int(input()) for rwre in range(q): n = int(input()) dz = [] nn = n kan = 2 while nn > 1 and kan**2 <= n: if nn%kan == 0: nn//= kan dz.append(kan) else: kan += 1 if nn > 1: dz.append(nn) dz.append(52525425542542) roz = [] for i in range(1,len(dz)): if dz[i] != dz[i-1]: roz.append(dz[i-1]) dz.pop(-1) if len(roz) >= 3: print("YES") print(roz[0],roz[1],n//(roz[0]*roz[1])) else: if len(roz) == 1: a = roz[0] b = roz[0]**2 c = n//(roz[0]**3) if c > 1 and c != b and c != a: print("YES") print(a,b,c) else: print("NO") if len(roz) == 2: c = n//(roz[1]*roz[0]) if c != roz[1] and c!= roz[0] and c > 1: print("YES") print(roz[0],roz[1],c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt t=int(input()) while t>0: d=list() n=int(input()) imp=int(n) ctr=0 for i in range (2,int(sqrt(n))): while(n%i==0): n//=i d.append(i) if(n>1): d.append(n) if(len(set(d))==2 and len(d)>=4): print("YES") print(d[0],d[-1],int(imp/(d[0]*d[-1]))) ctr+=1 if(len(set(d))>=3 or len(d)>=6 and ctr!=1 ): print("YES") if(len(set(d))>=3): print(d[0],d[-1],int(imp/(d[0]*d[-1]))) ctr+=1 else: print(d[0],d[0]**2,int(imp/(d[0]**3))) ctr+=1 if(ctr==0): 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
from collections import deque from math import sqrt def factors(n): d=deque() for x in range(2,int(sqrt(n)+1)): if n%x==0 : d.append(x) if n//x!=x : d.append(n//x) return d,set(d) t=int(input()) while(t): n=int(input()) f,m=factors(n) flag=a=b=c=0 for x in range(len(f)): fa,ma=factors(f[x]) for y in range(len(fa)): if f[x]//fa[y]!=fa[y] and fa[y]!=n//f[x] and f[x]//fa[y]!=n//f[x]: # print(y,x,f[x],fa[y]) flag=1 a,b,c=fa[y],n//f[x],f[x]//fa[y] break if flag : break if flag: print("YES") print(a,b,c) else: print("NO") t-=1
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.Scanner; public class C1294 { public static void main(String[] args) { Scanner in = new Scanner(System.in); int T = in.nextInt(); main: for (int t=0; t<T; t++) { long N = in.nextLong(); for (long a=2; a*a*a<N; a++) { if (N%a == 0) { for (long b=a+1; b*b<N/a; b++) { if (N%(a*b) == 0) { System.out.println("YES"); System.out.println(a + " " + b + " " + N/(a*b)); continue main; } } } } 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, ceil def primesfrom2to(n): """ Returns a list of primes < n """ sieve = [True] * (n//2) for i in range(3,int(n**0.5)+1,2): if sieve[i//2]: sieve[i*i//2::i] = [False] * ((n-i*i-1)//(2*i)+1) return [2] + [2*i+1 for i in range(1,n//2) if sieve[i]] primedin105 = primesfrom2to(10 ** 5) def primedec(n): ret = dict() if n == 1: return ret s = ceil(sqrt(n)) for i in primedin105: if s < i: return {n : 1} if not (n % i): d = primedec(n // i) ret = d try: ret[i] += 1 except Exception: ret[i] = 1 return ret def solution(n): p = primedec(n) k = sorted(p.keys()) a = k[0]; if p[a] == 1: if len(k) == 1: print('NO') return b = k[1] elif p[a] == 2: if len(k) == 1: print('NO') return b = k[0] * k[1] else: b = k[0] ** 2 c = n // (a * b) if c == 1 or c == a or c == b: print("NO") return print("YES") print(a, b, c) t = int(input()) for i in range(t): solution(int(input()))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for i in range(int(input())) : n = int(input()) a,b = 0,0 for i in range(2, math.floor(math.sqrt(n))+1) : if n%i == 0 : a = i break if a != 0 : for j in range(a+1, math.floor(math.sqrt(n//a))+1) : if (n//i)%j == 0 : b = j break if b != 0 and a != b and b != n//(a*b) : print('YES') print(a, b, n//(a*b)) else : print('NO') else : print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools # import time,random,resource sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 10**9+7 mod2 = 998244353 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def pe(s): return print(str(s), file=sys.stderr) def JA(a, sep): return sep.join(map(str, a)) def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a) def IF(c, t, f): return t if c else f class Prime(): def __init__(self, n): self.M = m = int(math.sqrt(n)) + 10 self.A = a = [True] * m a[0] = a[1] = False self.T = t = [2] for j in range(4, m, 2): a[j] = False for i in range(3, m, 2): if not a[i]: continue t.append(i) for j in range(i*i,m,i): a[j] = False self.ds_memo = {} self.ds_memo[1] = set([1]) def is_prime(self, n): return self.A[n] def division(self, n): d = collections.defaultdict(int) for c in self.T: while n % c == 0: d[c] += 1 n //= c if n < 2: break if n > 1: d[n] += 1 return d.items() # memo def divisions(self, n): if n in self.ds_memo: return self.ds_memo[n] for c in self.T: if n % c == 0: rs = set([c]) for cc in self.divisions(n // c): rs.add(cc) rs.add(cc * c) self.ds_memo[n] = rs return rs rs = set([1, n]) self.ds_memo[n] = rs return rs def sowa(self, n): r = 1 for k,v in self.division(n): t = 1 for i in range(1,v+1): t += math.pow(k, i) r *= t return r def main(): t = I() pr = Prime(10**10) rr = [] for _ in range(t): n = I() ds = sorted(pr.division(n)) r = [] if len(ds) == 1: k,v = ds[0] if v < 6: rr.append("NO") continue r = [k, k**2, k**(v-3)] else: t = n // ds[0][0] t //= ds[1][0] if t < 2 or t == ds[0][0] or t == ds[1][0]: rr.append("NO") continue r = [ds[0][0], ds[1][0], t] rr.append("YES") rr.append(JA(r, " ")) return JA(rr, "\n") print(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
__author__ = 'Devesh Bajpai' ''' https://codeforces.com/problemset/problem/1294/C Solution: We first find the factor for n using a standard sqrt time complexity stub. If we could find one, that becomes a. And then we find factor for n/a which is not equal to a. If we could find oen, that becomes b. By then, the value of n is made (n/a)/b or n/ab. Hence if that value of n is not equal to a,b or 1 then it is c. We add it to the distinct factor's set and return the result. At any step if we fail, the answer returned is NO. ''' def solve(n): distinct_factors = set() done, a = find_factors(n, distinct_factors) if not done: return "NO" else: n /= a done, b = find_factors(n, distinct_factors) if not done: return "NO" else: n /= b if n in distinct_factors or n == 1: return "NO" else: distinct_factors.add(n) return "YES" + "\n" + " ".join(str(_) for _ in distinct_factors) ''' Helper to find distinct factor for the current value of n Time Complexity: O(sqrt(n)) ''' def find_factors(n, distinct_factors): factor = 2 f = 2 done = False while f * f <= n and not done: if n % f == 0 and f not in distinct_factors: distinct_factors.add(f) factor = f done = True f += 1 return done, factor if __name__ == "__main__": t = int(raw_input()) results = list() for _ in xrange(0, t): n = int(raw_input()) results.append(solve(n)) for result in results: print result
PYTHON
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for i in range(0,t): n = int(input()) tmp = n lst = [] j = 2 while(j*j<=n) : if(tmp%j==0): tmp = int(tmp/j) lst.append(j) if(len(lst)>=2): if(tmp>j): lst.append(tmp) break j = j+1 if(len(lst)==3): print("YES") print(lst[0]," ",lst[1]," ",lst[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
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; int cnt = 0; vector<long long> ans; for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { if (cnt == 0) { ans.push_back(i); n = n / i; cnt++; } else { ans.push_back(i); ans.push_back(n / i); break; } } } if ((ans.size() == 3) && (ans[0] != ans[1]) && (ans[1] != ans[2]) && (ans[0] != ans[2])) { cout << "YES" << endl; cout << ans[0] << " " << ans[1] << " " << ans[2] << endl; } else cout << "NO" << endl; } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for x in range(int(input())): n = int(input()) a = 1 for i in range(2, int(n ** 0.5) + 2): if n % i == 0: a = i n /= i break if a != 1: b = 1 for i in range(a + 1, int(n ** 0.5) + 2): if n % i == 0: if n // i != a and n // i != i: b = i n /= i break if b != 1: if n != 1: print('YES') print(a, b, int(n)) else: print('NO') else: print('NO') else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from collections import defaultdict def solve(n): table = set() i = 2 while i*i <= n: if n % i == 0: table.add(i) n /= i break i += 1 i = 2 while i*i <= n: if n % i == 0 and i not in table: table.add(i) n /= i break i += 1 if len(table) < 2 or n == 1 or n in table: print("NO") else: print("YES") table.add(int(n)) print(" ".join([str(t) for t in table])) T = int(input()) for t in range(T): n = int(input()) solve(n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while (t-- > 0) { long n=sc.nextLong(); long a=0L,b=0L,c=0L; boolean found=false; for (long i=2L;i<=Math.sqrt((long)n);i++) { if (n % i == 0) { n=n/i; a=i; found=true; break; } } if (found) { found=false; for (long i=2;i<=Math.sqrt((long)n);i++) { if (n%i==0 && i!=a) { b=i; c=n/i; if (c!=a && c!=b) { found=true; break; } } } if (found) { System.out.println("YES"); System.out.println(a + " " + b + " " + c); } 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
cases = int(input()) def prime(n): for i in range(2,int((n+1)**0.5)): if n%i == 0: return False return True for i in range(cases): num = int(input()) if prime(num): print("NO") continue if num < 24: print("NO") continue n = num d = {} for j in range(2, int((n+1)**0.5)): while num%j == 0: if j not in d: d[j] = 1 else: d[j] += 1 num /= j if num > 1: if num not in d: d[num] = 1 else: d[num] += 1 ans = [] if len(d) >= 3: two = 2 print("YES") for key in d: if two == 0: break ans.append(key) d[key] -= 1 two -= 1 c = 1 for ele in d: val = d[ele] c *= (ele**val) ans.append(int(c)) print(int(ans[0]),int(ans[1]),int(ans[2])) elif len(d) == 2: for key in d: ans.append(key) d[key] -= 1 c = 1 for key in d: val = d[key] c *= key**val if c not in ans and c != 1: ans.append(int(c)) print("YES") print(int(ans[0]),int(ans[1]),int(ans[2])) elif c in ans or c == 1: print("NO") elif len(d) == 1: val = list(d.values()) if val[0] < 6: print("NO") else: a = int(list(d.keys())[0]) b = int(list(d.keys())[0]**2) c = int(list(d.keys())[0]**(val[0]-3)) print("YES") print(a,b,c)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t=int(input()) for _ in range(t): n=int(input()) a=[] i=2 while len(a)<2 and i*i<n: if n%i==0: a.append(i) n//=i i+=1 if len(a)==2 and n not in a: print('YES') print(*a,n) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import * for _ in range(int(input())): n = int(input()) nn = n l = [] now = 2 m = [] sq = int(sqrt(n)) while n > 1: if n % now == 0: while n % now == 0: l.append(now) n //= now else: now += 1 if now > sq: break if len(l) < 2: print("NO") continue m.append(l[0]) if l[0] != l[1]: m.append(l[1]) elif len(l) == 2: print("NO") continue else: m.append(l[1] * l[2]) t = nn // (m[0] * m[1]) if (t == 1) or (t in m): print("NO") continue else: print("YES") print(m[0], m[1], t)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n=int(input()) a=n i=2 while i**2<n: if n%i==0: a=i n//=i break i+=1 if a==n: print('NO') continue b=n i=a+1 while i**2<n: if n%i==0: b=i n//=i break i+=1 if b==n: print('NO') continue print('YES') print(a,b,n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from functools import reduce def fac(n): return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) t=int(input()) for i in range(t): n=int(input()) x=fac(n) x=x[1:-1] flag=1 if len(x)<3: flag=0 else: a,b=x[0],0 for j in range(1,len(x)): if n%(a*x[j])==0: b=x[j] break if b: te=a*b if n%te==0: c=n//te if a!=b and a!=c and b!=c and a>=2 and b>=2 and c>=2: pass else: flag=0 else: flag=0 else: flag=0 if flag: pass print("YES") print(a,b,c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; using namespace std; string chk[10] = {"1110111", "0010010", "1011101", "1011011", "0111010", "1101011", "1101111", "1010010", "1111111", "1111011"}; void solve() { long long n; cin >> n; for (int a = 2; a * (a + 1) * (a + 2) <= n; a++) if (n % a == 0) { int num = n / a; for (int b = a + 1; b * (b + 1) <= num; b++) if (num % b == 0) { int c = num / b; printf("YES\n"); printf("%d %d %d\n", a, b, c); return; } } printf("NO\n"); } int main() { int t; cin >> t; while (t--) { solve(); } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from functools import reduce def factors(n): return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))) t = int(input()) #for each test cases for i in range(t): n=int(input()) def x(n): x=factors(n) counter=1 if (len(x)<5): return True else: x=x-set([1])-set([n]) x=list(x) for i in range(len(x)-2): for j in range (i+1,len(x)-1): for k in range (j+1,len(x)): if(x[i]*x[j]*x[k]==n): print("YES") print(x[i],x[j],x[k]) return False return True if x(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
from sys import stdin from _collections import deque mod = 10**9 + 7 import sys sys.setrecursionlimit(10**5) from queue import PriorityQueue from bisect import bisect_right from bisect import bisect_left from _collections import defaultdict from math import sqrt,factorial,gcd,log2,inf,ceil import heapq input = lambda : sys.stdin.readline().rstrip() from sys import stdin, stdout from heapq import heapify,heappush,heappop # min = 0 # n,m = map(int,input().split()) # maxi = n # z = m # while z>0: # # yo = (1+sqrt(1+8*z))//2 # maxi-=yo # print(yo) # z-=((yo)*(yo+1))//2 # # # maxi = max(int(maxi),0) # # # # if m>=n-1: # min = 0 # else: # min = (n)-2*(m) # # # if m == 0: # print(n,n) # exit() # if n == 1 and m == 1: # min = 1 # print(min,maxi) # t = int(input()) # # for _ in range(t): # # a,b,c,n = map(int,input().split()) # if (a+b+c+n)%3 == 0: # print('YES') # else: # print('NO') # # t = int(input()) # for _ in range(t): # # n = int(input()) # la = [] # for i in range(n): # # a,b = map(int,input().split()) # la.append([a,b]) # # la.sort() # flag = 0 # for i in range(1,n): # if la[i][1]<la[i-1][1]: # flag = 1 # break # # if flag: # print('NO') # else: # x1,y1 = 0,0 # ans = [] # while la!=[]: # x,y = la.pop(0) # z1 = x-x1 # z2 = y-y1 # for i in range(z1): # ans.append('R') # for i in range(z2): # ans.append('U') # # x1,y1 = x,y # print('YES') # print(''.join(ans)) def solve(n): la = [] for i in range(2,int(sqrt(n))+1): if n%i == 0: if n//i!=i: la.append((i,n//i)) return la t = int(input()) for _ in range(t): n = int(input()) l = solve(n) flag = 0 x,y,z = -1,-1,-1 for a,b in l: la = solve(a) flag = 0 for c,d in la: if b!=c and b!=d: x = b y = c z = d flag = 1 break if flag: break la = solve(b) for c,d in la: if a!=c and a!=d: x = a y = c z = d flag = 1 break if flag: break if x*y*x>0: print('YES') print(x,y,z) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n=int(input()) l=[] if(n%2==0): l.append(2) for i in range(3,int(pow(n,0.5))+1): if(n%i==0): if(n//i==i): l.append(i) else: l.append(i) l.append(n//i) f=0 for i in range(0,len(l)): for j in range(i+1,len(l)): for k in range(j+1,len(l)): if(l[i]*l[j]*l[k]==n): f=1 break if(f==1): break if(f==1): break if(f==1): print("YES") print(l[i],l[j],l[k]) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def fin(n): for a in range(2,int(n**(1/3))+1): if n%a==0: x=n/a for b in range(2,int(x**(1/2))+1): if x%b==0: y=int(x/b) if a!=b and b!=y and y!=a: return a,b,y return 0,0,0 for _ in range(int(input())): n=int(input()) p,q,r=0,0,0 p,q,r=fin(n) if p!=0: print("YES") print(p,q,r) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
n=int(input()) for i in range (n): a=int(input()) k=a p=[] j=2 while (j*j<k): if (k%j==0 and j not in p): p.append(j) k=k//j if (len(p)==2): g=a//(p[0]*p[1]) if (g!=p[0] and g!=p[1]): break j+=1 if len(p)<2: print ("NO") elif len (p)==2 and p[0]*p[1]==a: print ("NO") elif p[0]!=a//(p[0]*p[1]) and p[1]!=a//(p[0]*p[1]): print ("YES") print(p[0],p[1],a//(p[0]*p[1])) else : print ("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import gcd,sqrt t = int(input()) for _ in range(t): n = int(input()) flag = 0 for i in range(2,int(sqrt(n))+1): if flag: break if n%i==0: divided = n//i for j in range(2,int(sqrt(n))+1): if divided%j==0 and divided//j > 1 and j!=i and j!= divided//j and i!=divided//j: print("YES") print(j,i,divided//j) flag = 1 break if not flag: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int T, t; cin >> T; for (t = 0; t < T; t++) { int n, i; cin >> n; int numPrime = 0; int num = n; int f = 1; vector<int> v; map<int, int> mp; for (i = 2; i <= sqrt(n); i++) { f = 1; if (num % i == 0) { f = f * i; while (num % i == 0) { if (f != 1 && mp[f] == 0) { v.push_back(f); mp[f] = 1; f = 1; } else { f = f * i; } num = num / i; } } } if (mp[num] == 0 && num != 1) { v.push_back(num); mp[num] = 1; } if (v.size() == 2) { int r = n / (v[0] * v[1]); if (mp[r] == 0 && r != 1) v.push_back(r); } sort(v.begin(), v.end()); if (v.size() > 2) { cout << "YES" << endl; cout << v[0] << " " << v[1] << " " << n / (v[0] * v[1]) << endl; } else cout << "NO" << endl; } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin t = int(stdin.readline()) for _ in range(t): n = int(stdin.readline()) if n < 24: print("NO") continue a = [] for i in range(2, int(n**0.5)+1): if n%i == 0: n//=i a.append(i) break if len(a) == 1: for i in range(a[0]+1, int(n**0.5)+1): if n%i == 0: n//=i a.append(i) 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
t = int(input()) for i in range(t): f = 0 n = int(input()) if n % 2 == 0: a = 2 f = 1 else: for j in range(3 ,int((n**(1/3)) + 2), 2): if (n % j == 0): a = j f = 1 break if (f == 0): print("NO") else: n = n // a f = 0 for j in range(a ,int((n**(1/2)) + 2)): c = n // j if (n % j == 0) and (j != a) and (c) != 1: b = j f = 1 break if (f == 0) or (b == c) or (a == c): print("NO") else: print("YES") print(a, b, c)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for _ in range(int(input())): n = int(input()) def prime(n): primes = {2:0} while n % 2 == 0: primes[2] += 1 n = n // 2 for i in range(3, int(math.sqrt(n)+1), 2): while n % i == 0: if i in primes: primes[i] += 1 else: primes[i] = 1 n = n // i if n > 2: if n in primes: primes[n] += 1 else: primes[n] = 1 return primes def prod(l): p = 1 for x in l: p *= x return p primes = prime(n) # print(primes) ar = [] keys = sorted(primes.keys()) for key in keys: ar.extend([key]*primes[key]) # print(ar) if len(ar) < 3: print('NO') else: a = ar[0] i = 1 b = ar[1] if ar[0] == ar[1]: b *= ar[2] i += 1 c = prod(ar[i+1:]) if i == len(ar) - 1 or b == c or len(set([a, b, c])) < 3: 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 sys ip = lambda : sys.stdin.readline().rstrip() for _ in range(int(ip())): n=int(ip()) ans=[] for i in range(2,int(n**0.5)+1): if n%i==0: v=n//i for j in range(2,int(v**0.5)+1): if v%j==0: st=set([i,j,v//j]) if len(st)==3: ans=sorted([i,j,v//j]) break if ans!=[]: break if ans!=[]: print("YES") print(*ans) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for i in range(t): n = int(input()) f = 2 li = [] c = 0 while c < 2 and n >= f * f: if n % f == 0: n = n // f c += 1 li.append(f) if c == 2: if n not in li and n >= 2: li.append(n) f += 1 if len(li) == 3: print("YES") print(li[0], li[1], li[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 collections,math for _ in range(int(input())): n=int(input()) factors=[] flag=False d=collections.defaultdict(int) for i in range(2,int(math.sqrt(n))+1): if n%i==0: d[i]=1 factors.append(i) if (n//i) != i: d[n//i]=1 factors.append(n//i) factors.sort() for i in range(len(factors)-1): for j in range(i+1,len(factors)): k=n//(factors[i]*factors[j]) if d[k]==1 and factors[i]*factors[j]*k==n and factors[i]!=k and factors[j]!=k: flag=True print('YES') print(factors[i],factors[j],k) break if flag: break if not flag: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; import java.io.*; public class Main { static class pair implements Comparable<pair>{ int a; int b; public pair(int a, int b){ this.a=a; this.b=b; } public int compareTo(pair p){ return (a-p.a==0)?b-p.b:a-p.a; } } public static void main(String[] args) throws IOException,InterruptedException{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); // String s = br.readLine(); // char[] arr=s.toCharArray(); // ArrayList<Integer> arrl = new ArrayList<Integer>(); // TreeSet<Integer> ts1 = new TreeSet<Integer>(); // HashSet<Integer> h = new HashSet<Integer>(); // HashMap<Integer, Integer> map= new HashMap<>(); // PriorityQueue<String> pQueue = new PriorityQueue<String>(); // LinkedList<String> object = new LinkedList<String>(); // StringBuilder str = new StringBuilder(); //*******************************************************// // StringTokenizer st = new StringTokenizer(br.readLine()); // int t = Integer.parseInt(st.nextToken()); // while(t-->0){ // st = new StringTokenizer(br.readLine()); // int n = Integer.parseInt(st.nextToken()); // int[] arr = new int[n]; // st = new StringTokenizer(br.readLine()); // for(int i=0; i<n; i++){ // arr[i] =Integer.parseInt(st.nextToken()); // } // int ans =0; // out.println(ans); // } StringTokenizer st = new StringTokenizer(br.readLine()); int t = Integer.parseInt(st.nextToken()); loop: while(t-->0){ st = new StringTokenizer(br.readLine()); int n = Integer.parseInt(st.nextToken()); Factors(n); } out.flush(); } static void Factors(int n) { int k =n; ArrayList<Integer> P = new ArrayList<Integer>(); while (n % 2 == 0) { P.add(2); n /= 2; } for (int i = 3; i * i <= n; i = i + 2) { while (n % i == 0) { n = n / i; P.add(i); } } if (n > 2) P.add(n); if (P.size() < 3) { System.out.println("NO"); return; } HashSet<Integer> h = new HashSet<Integer>(); int pro = 1; int i =0; for (; i<P.size()&&h.size()<2; i++) { pro*=(int)P.get(i); if(!h.contains(pro)){h.add(pro); pro =1;} } int product = 1; for (; i < P.size(); i++) product = product * (int)P.get(i); if(product!=1)h.add(product); if(h.size()==3){ Iterator value = h.iterator(); StringBuilder str = new StringBuilder(); int check =1; while (value.hasNext()) { int x =(int)value.next(); check*=x; str.append(x+" "); } if(check==k){System.out.println("YES");System.out.println(str);} else System.out.println("NO"); }else System.out.println("NO"); } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; import java.io.*; public class Main { public static void solve(InputReader in) { int n = in.readInt(); HashSet<Integer> set = new HashSet<>(); for(int i = 2; i*i <= n; i++) { if(n % i == 0) { set.add(i); set.add(n/i); } } for(Integer i : set) { int a = i; for(Integer b : set) { if((b != a) && n / (a*b) != 0 && n /(a*b) != a && n/(a*b) != b && n/(a*b) != 1 && n%(a*b) == 0) { System.out.println("YES"); System.out.println(a + " " + b + " " + n/(a*b)); return; } } } System.out.println("NO"); } public static void main(String ...strings) { InputReader in = new InputReader(System.in); int t = in.readInt(); while(t-- > 0) { solve(in); } } } class InputReader{ private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private SpaceCharFilter filter; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public int readInt() { int c = read(); while (isSpaceChar(c)) c = read(); int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public String readString() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public long readLong() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { if (c < '0' || c > '9') { throw new InputMismatchException(); } res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public boolean isSpaceChar(int c) { if (filter != null) return filter.isSpaceChar(c); return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } }
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 def main(): def solve(): n = int(input()) a = 0 if n%2 == 0: a = 2 else: for i in range(3, int(n ** (1./3))+1, 2): if n%i == 0: a = i break if a == 0: print("NO") return b = 0 for i in range(a+1, int(sqrt(n//a))+1): if (n//a)%i == 0: b = i break if b == 0: print("NO") return c = n//(a*b) if b == c: print("NO") return print("YES") print(a, b, c) q = int(input()) for _ in range(q): solve() if __name__ == "__main__": main()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; public class ProductOfThreeNumbers { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int k=n; int ans=0; int count=0; outer: for(int i=2;i<Math.sqrt(n)+1;i++) { n=k; if(n%i==0 && i!=n) { ans=i; n=n/i; for(int j=2;j<Math.sqrt(n)+1;j++) { //System.out.println(i+" "+j+" "+n+" "+(n/j)); if(j!=i && n%j==0 && (n/j)!=j && (n/j)!=i) { count++; System.out.println("YES"); System.out.println(ans+" "+j+" "+(n/j)); break outer; } } } } if(count==0) { 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 math for _ in range(int(input())): n=int(input()) a=[] s=round(math.sqrt(n)) for i in range(2,s+1): if len(a)==2: if n not in a: a.append(n) break else: if n%i==0: a.append(i) n=n//i if len(a)==3: print("Yes") for j in range(0,3): print(a[j],end=" ") 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
num = int(input()) answer = [] for i in range(num): target = int(input()) lis = [] k = 2 while len(lis)<2 and k**2<target: if target % k == 0: target = target //k lis.append(k) k += 1 if len(lis) == 2 and target not in lis: answer.append([lis[0],lis[1],target]) else: answer.append('NO') for i in answer: if i == "NO": print(i) else: print('YES') print(i[0],i[1],i[2])
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; import java.io.*; import java.math.*; public class Main { final static int mod = 1000000007; static FastReader sc; static PrintWriter out; static boolean test_case_input = true; public static void solution() throws IOException { int n = sc.nextInt(); int a = -1, b = -1, c = -1; int temp = n; for(int i=2; (long) i*i <= temp; i++) { if(n == 1) break; if(n % i == 0) { if(a == -1) { a = i; n /= i; } while(n % i == 0) { if(b == -1) { b = i; n /=i; } else if(b == a) { b *= i; n /= i; } else { if(c == -1) { c = i; n /=i; } else { c *= i; n /= i; } } } } } if(n != 1) { if(c == -1) c = n; else c *= n; } if(a != b && b != c && a != c && a != -1 && b != -1 && c != -1) { out.println("YES\n" + a + " " + b + " " + c); } else out.println("NO"); } // GCD public static int __gcd(int a, int b) { BigInteger n1 = BigInteger.valueOf(a); BigInteger n2 = BigInteger.valueOf(b); BigInteger gcd = n1.gcd(n2); return gcd.intValue(); } public static long __gcd(long a, long b) { BigInteger n1 = BigInteger.valueOf(a); BigInteger n2 = BigInteger.valueOf(b); BigInteger gcd = n1.gcd(n2); return gcd.longValue(); } public static void main(String args[]) throws IOException { long start = 0, end = 0; try { File output = new File("output.txt"); sc = new FastReader(); if (output.exists()) { out = new PrintWriter(new FileOutputStream("output.txt")); start = System.nanoTime(); } else { out = new PrintWriter(System.out); } int test_cases = 1; if (test_case_input) test_cases = sc.nextInt(); while (test_cases-- > 0) { solution(); } if (output.exists()) { end = System.nanoTime(); out.println("Execution time: " + (end - start) / 1000000 + " ms"); } out.flush(); out.close(); } catch (Exception e) { out.println("Exception: " + e); out.flush(); out.close(); return; } } // Fast IO static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() throws FileNotFoundException { File in = new File("input.txt"); if (in.exists()) { br = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))); } else { 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()); } float nextFloat() { return Float.parseFloat(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys import math import heapq import collections def inputnum(): return(int(input())) def inputnums(): return(map(int,input().split())) def inputlist(): return(list(map(int,input().split()))) def inputstring(): return([x for x in input()]) def inputstringnum(): return([ord(x)-ord('a') for x in input()]) def inputmatrixchar(rows): arr2d = [[j for j in input().strip()] for i in range(rows)] return arr2d def inputmatrixint(rows): arr2d = [] for _ in range(rows): arr2d.append([int(i) for i in input().split()]) return arr2d t = int(input()) for q in range(t): n = inputnum() i = 2 a = 0 b = 0 while i*i <= n and (a == 0 or b == 0): if n%i == 0 and a == 0: n //= i a = i i += 1 continue elif n%i == 0 and b == 0: n //= i b = i i += 1 continue i += 1 if (a == 0 or b == 0) or (n == a or n == b): print("NO") else: print("YES") print(a, b, n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t = int(input()) for ii in range(0,t): n = int(input()) a = 0 b = 0 c = 0 if n<24: print("NO") continue ifFind = 0 for i in range(2,int(math.sqrt(n))+1): if ifFind == 1: break if n%i!=0: continue n2 = n // i for j in range(i+1,int(math.sqrt(n2))+1): if n2%j!=0: continue n3 = n2//j if j==n3: break ifFind = 1 a=i b=j c=n3 break if ifFind == 1: print("YES") print(a,b,c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t=int(input()) from math import sqrt primes=[True for i in range(10**5)] for i in range(2,len(primes)): jumper=i ind=2 while i*ind<len(primes): primes[i*ind]=False ind+=1 primes=set([i for i in range(len(primes)) if primes[i]]) def divider(x): if x%2==0: return x//2,2 for i in range(3,int(sqrt(x)+1),2): #print("Inside loop:",i) if x%i==0: return x//i,i return -1,-1 for _ in range(t): n=int(input()) flag=False ans1,ans2,ans3=0,0,0 for i in range(2,int(sqrt(n)+1)): #print(i) reali=n//i if n%i==0 and n//i not in primes: ans2,ans3=divider(n//i) if ans2==-1 and ans3==-1: continue ans1=i if ans1!=ans2 and ans2!=ans3 and ans3!=ans1: flag=True break if flag: print("YES") print(ans1,ans2,ans3) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def R(): return map(int, input().split()) def I(): return int(input()) def S(): return str(input()) def L(): return list(R()) from collections import Counter import math import sys for _ in range(I()): n=I() div=[] n2=n for i in range(2,int(math.sqrt(n))+1): if n%i ==0: div.append(i) n/=i if n>1: div.append(n) if len(div)<3 or n2//(div[0]*div[1])== div[0] or n2//(div[0]*div[1])==div[1]: print('NO') else: print('YES') print(div[0],div[1],n2//(div[0]*div[1]))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for i in range(int(input())): n=int(input()) i=2 arr=[] while n>0 and i<=(int(n**0.5)): if n%i==0: n/=i arr.append(i) i+=1 if len(arr)==2: break if len(arr)==2: if n not in arr: print('YES') print(arr[0],arr[1],int(n)) else: print('NO') else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt as S def div(x): d=[] if x==1: return [1] if x==2: return [1,2] cnt=[1,n] for i in range(2,int(S(x))+1): if x %i==0: cnt.append(i) return cnt def check(arr): if 1 in arr or 0 in arr: return 0 return len(set(arr))==3 import sys input=sys.stdin.readline t=int(input()) ans=[] for i in range(t): n=int(input()) f=0 cnt=div(n) for x in cnt : y=n//x if f: break for z in div(y): if check([x,z,y//z]): ans=[x,z,y//z] f=1 break if f: print('YES') print(*ans) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def main(): t = int(input()) for z in range (t): n = int(input()) arr = [] i=2; while i*i <= n: while n%i==0: arr.append(i) n //= i i += 1 if n>1:arr.append(n) a,b,c = 1,1,1 for x in arr: if a==1: a *= x elif b==1 or a==b: b *= x else: c *= x arr = set([a,b,c]) if a!=1 and b!=1 and c!=1 and len(arr)==3: print("YES") print(a,b,c) else: print("NO") if __name__ == "__main__": main()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math import os def get_array(): return list(map(int, input().split(' '))) def get_divisions(a): i = 2 while i <= math.sqrt(a): if a % i == 0: yield i i += 1 yield -1 if __name__ == '__main__': t = int(input()) for i in range(t): n = int(input()) divs = get_divisions(n) while True: a = next(divs) f = False if a != -1: divs_a = get_divisions(n / a) while True: b = next(divs_a) if b != -1: c = int(n / a / b) if b != a and c != b: print('YES') print(a, ' ', b, ' ', c) f = True break else: f = False break if not f: print('NO') break else: print('NO') break
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
/* If you want to aim high, aim high Don't let that studying and grades consume you Just live life young ****************************** If I'm the sun, you're the moon Because when I go up, you go down ******************************* I'm working for the day I will surpass you **************************************** */ import java.util.*; import java.awt.Point; import java.lang.Math; import java.util.Arrays; import java.util.Arrays; import java.util.Scanner; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.util.Comparator; import java.util.stream.IntStream; public class Main { static int oo = (int)1e9; public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); MuskA solver = new MuskA(); solver.solve(1, in, out); out.close(); } static class MuskA { static int inf = (int) 1e9 + 7; public int curr; public int[] visited; public void solve(int testNumber, Scanner in, PrintWriter out) { int T= in.nextInt(); main: for (int t=0; t<T; t++) { long N = in.nextLong(); for (long a=2; a*a*a<N; a++) { if (N%a == 0) { for (long b=a+1; b*b<N/a; b++) { if (N%(a*b) == 0) { out.println("YES"); out.println(a + " " + b + " " + N/(a*b)); continue main; } } } } out.println("NO"); } } } public int factorial(int n) { int fact = 1; int i = 1; while(i <= n) { fact *= i; i++; } return fact; } public static long gcd(long x,long y) { if(x%y==0) return y; else return gcd(y,x%y); } public static int gcd(int x,int y) { if(x%y==0) return y; else return gcd(y,x%y); } public static int abs(int a,int b) { return (int)Math.abs(a-b); } public static long abs(long a,long b) { return (long)Math.abs(a-b); } public static int max(int a,int b) { if(a>b) return a; else return b; } public static int min(int a,int b) { if(a>b) return b; else return a; } public static long max(long a,long b) { if(a>b) return a; else return b; } public static long min(long a,long b) { if(a>b) return b; else return a; } public static long pow(long n,long p,long m) { long result = 1; if(p==0) return 1; if (p==1) return n; while(p!=0) { if(p%2==1) result *= n; if(result>=m) result%=m; p >>=1; n*=n; if(n>=m) n%=m; } return result; } public static long pow(long n,long p) { long result = 1; if(p==0) return 1; if (p==1) return n; while(p!=0) { if(p%2==1) result *= n; p >>=1; n*=n; } return result; } static long sort(int a[]){ int n=a.length; int b[]=new int[n]; return mergeSort(a,b,0,n-1); } static long mergeSort(int a[],int b[],long left,long right){ long c=0; if(left<right){ long mid=left+(right-left)/2; c= mergeSort(a,b,left,mid); c+=mergeSort(a,b,mid+1,right); c+=merge(a,b,left,mid+1,right); } return c; } static long merge(int a[],int b[],long left,long mid,long right){ long c=0;int i=(int)left;int j=(int)mid; int k=(int)left; while(i<=(int)mid-1&&j<=(int)right){ if(a[i]<=a[j]){ b[k++]=a[i++]; } else{ b[k++]=a[j++];c+=mid-i; } } while (i <= (int)mid - 1) b[k++] = a[i++]; while (j <= (int)right) b[k++] = a[j++]; for (i=(int)left; i <= (int)right; i++) a[i] = b[i]; return c; } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt def solve(R:list): n = int(input()) m = n for i in range(2,int(sqrt(m))): if i >= n : return if n % i == 0: R.append(i) n //= i if len(R) == 2: break if len(R) == 2: if n > R[-1]: R.append(n) t = int(input()) for cnt in range(t): R = [] solve(R) # print("CASE : " + str(cnt+1)) if len(R) == 3: print("YES") print(" ".join(map(str,R))) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; import java.math.*; import java.io.*; public class input2 { public static int factoiral(int a) { if (a == 0) return 1; else return (a * factoiral(a - 1)); } public static void sortbyColumn(int arr[][], int col) { Arrays.sort(arr, new Comparator<int[]>() { @Override public int compare(int[] entry1, int[] entry2) { if (entry1[col] > entry2[col]) return 1; else return -1; } }); } public static void merge(long arr[], long brr[], int l, int m, int r) { // Find sizes of two subarrays to be merged int n1 = m - l + 1; int n2 = r - m; /* Create temp arrays */ long L[] = new long[n1]; long L1[] = new long[n1]; long R[] = new long[n2]; long R1[] = new long[n2]; /* Copy data to temp arrays */ for (int i = 0; i < n1; ++i) { L[i] = arr[l + i]; L1[i] = brr[l + i]; } for (int j = 0; j < n2; ++j) { R[j] = arr[m + 1 + j]; R1[j] = brr[m + 1 + j]; } /* Merge the temp arrays */ // Initial indexes of first and second subarrays int i = 0, j = 0; // Initial index of merged subarry array int k = l; while (i < n1 && j < n2) { if (L[i] <= R[j]) { arr[k] = L[i]; brr[k] = L1[i]; i++; } else { arr[k] = R[j]; brr[k] = R1[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; brr[k] = L1[i]; i++; k++; } /* Copy remaining elements of R[] if any */ while (j < n2) { arr[k] = R[j]; brr[k] = R1[j]; j++; k++; } } public static void sort(long arr[], long brr[], int l, int r) { if (l < r) { // Find the middle point int m = (l + r) / 2; // Sort first and second halves sort(arr, brr, l, m); sort(arr, brr, m + 1, r); // Merge the sorted halves merge(arr, brr, l, m, r); } } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(br.readLine()); for (int j = 0; j < t; j++) { int n = Integer.parseInt(br.readLine()); int g = n; int upn = (int)Math.sqrt(n); int a = 1; for(int i=2;i<=upn;i++){ if(n%i == 0){ a = Math.min(i,n/i); break; } } // System.out.println(a); n = n/a; upn = (int)Math.sqrt(n); int b = 1; for(int i=2;i<=upn;i++){ if(n%i == 0 &&(i!=a)){ b = Math.min(i,n/i); break; } } // System.out.println(b); int x = a*b; int c = g/x; if(a == 1 || b == 1 || c == 1) System.out.println("NO"); else if(a == b || a == c || b == c) System.out.println("NO"); else{ System.out.println("YES"); System.out.println(a + " " + b + " " + c); } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) while t: t-=1 n = int(input()) i = 2 val = [] while(i*i<=n): if n%i==0: n = n//i val.append(i) break i+=1 i = 2 while(i*i<=n): if n%i==0 and i!=val[0]: n = n//i val.append(i) break i+=1 if len(val)<2 or n==1 or val[-1]==n: print('NO') else: print('YES') val.append(n) print(*val)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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.BufferedWriter; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; public class Main { static String s; public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br= new BufferedReader(new InputStreamReader(System.in)); BufferedWriter bw= new BufferedWriter(new OutputStreamWriter(System.out)); String str= br.readLine(); int t = Integer.parseInt(str); for(int h=0; h<t; h++) { int n= Integer.parseInt(br.readLine()); String s="NO"; int nn=0; int i=2; int m0=0; while(i*i<=n) { if(nn==0) { if(n%i==0) { n /= i; m0=i; nn++; } } else if(nn==1) { if(n%i==0 && n/i != i) { s = "YES\n" + m0 + " " + i + " " + n/i; break; } } i++; } System.out.println(s); } } }
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 isPrime(int n) { if (n <= 1) return 0; for (int i = 2; i * i <= n; i++) if (n % i == 0) return 0; return 1; } int main() { int t; cin >> t; while (t--) { int n; cin >> n; if (isPrime(n)) cout << "NO\n"; else { int c = 0; vector<int> a; int prev = 0; for (int i = 2; i * i < n; i++) { if ((a.size() == 2) && (n != prev)) break; if (n % i == 0) { if (prev != i) { a.push_back(i); prev = i; } n = n / i; } } if (a.size() < 2) cout << "NO\n"; else { cout << "YES\n"; cout << a[0] << " " << a[1] << " " << n << "\n"; } } } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.*; import java.util.*; public class CF1294C extends PrintWriter { CF1294C() { super(System.out); } Scanner sc = new Scanner(System.in); public static void main(String[] $) { CF1294C o = new CF1294C(); o.main(); o.flush(); } void main() { int t = sc.nextInt(); while (t-- > 0) { int n = sc.nextInt(); int u = 1, ku = 0, v = 1, kv = 0, w = n; for (int p = 2; p <= w / p; p++) if (w % p == 0) { int k = 0; while (w % p == 0) { k++; w /= p; } if (u == 1) { u = p; ku = k; } else { v = p; kv = k; break; } } if (w != 1) { if (u == 1) { u = w; ku = 1; w = 1; } else if (v == 1) { v = w; kv = 1; w = 1; } } int a = -1, b = -1, c = -1; if (u != 1 && v != 1 && w != 1 || u != 1 && v != 1 && ku + kv >= 4) { a = u; b = v; c = n / a / b; } else if (ku >= 6) { a = u; b = u * u; c = n / a / b; } if (c == -1) println("NO"); else { println("YES"); println(a + " " + b + " " + c); } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def prime_factorize(n): a = [] if n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n and len(a)<2: if n % f == 0: a.append(f) n //= f f += 1 else: f += 1 if n != 1 and n not in a: a.append(n) return a YN=[] N=int(input()) for i in range(N): P=int(input()) p=prime_factorize(P) nums="" num=1 if len(p)>=3: YN.append('YES') for j in range(2,len(p)): num=num*p[j] nums+= str(p[0]) + ' ' + str(p[1]) + ' ' +str(num) YN.append(nums) else: YN.append('NO') for u in YN: print(u)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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 # A function to print all prime factors of # a given number n def primeFactors(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 _ in range(int(input())): n=int(input()) ar=[] l=primeFactors(n,ar) s=[] s=set(s) temp=1 for i in l: temp*=i if temp not in s and len(s)<2: s.add(temp) temp=1 if temp!=1: s.add(temp) if len(s)>2: print("YES") s=list(s) for i in s: print(i,end=" ") else: print("NO",end=" ") print()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
//Product of three numbers import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.io.PrintWriter; import java.util.StringTokenizer; public class ProductOfThreeNumbers { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); while(t-- > 0){ int n = Integer.parseInt(br.readLine()); boolean flag = false; for(int i = 2; i < Math.floor(n/i); ++i){ if(n/i == (double)n/i){ int[] a = factors(n/i, i); if(a.length == 2){ out.println("YES"); out.println(i+" "+a[0]+" "+a[1]); flag = true; break; } } } if(!flag) out.println("NO"); out.flush(); } } static int[] factors(int n, int a){ int end = (int)Math.sqrt(n); for(int i = a+1; i <= end; ++i){ if(n%i == 0 && i != a){ if(i != n/i){ return new int[]{i, n/i}; } } } return new int[]{0}; } }
JAVA