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
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n; cin >> n; for (long long int i = 0; i < n; i++) { long long int a, x; cin >> a; x = a; vector<int> v; for (long long int i = 2; i <= sqrt(a); i++) { if (a % i == 0) { if (a / i == i) v.push_back(i); else { v.push_back(i); v.push_back(a / i); } a = a / i; } } if (v.size() < 2) cout << "NO" << '\n'; else { sort(v.begin(), v.end()); if (x / (v[0] * v[1]) > 1 && x / (v[0] * v[1]) != v[0] && x / (v[0] * v[1]) != v[1]) { cout << "YES" << "\n"; cout << v[0] << ' ' << v[1] << ' ' << x / (v[0] * v[1]) << '\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 break if a==1: print('NO') continue x=n//a for i in range(2,int(((x)**0.5)+1)): if x%i==0 and i!=a: b=i break if b==1: print('NO') continue c=int(n//(a*b)) if c!=1 and c!=a and c!=b: print('YES') print(a,b,c) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
""" This template is made by Satwik_Tiwari. python programmers can use this template :)) . """ #=============================================================================================== #importing some useful libraries. import sys import bisect import heapq from math import * from collections import Counter as counter # Counter(list) return a dict with {key: count} from itertools import combinations as comb # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)] from itertools import permutations as permutate from bisect import bisect_left as bl # from bisect import bisect_right as br from bisect import bisect #=============================================================================================== #some shortcuts mod = pow(10, 9) + 7 def inp(): return sys.stdin.readline().strip() #for fast input def out(var): sys.stdout.write(str(var)) #for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return map(int, inp().split()) def strsep(): return map(str, inp().split()) def graph(vertex): return [[] for i in range(0,vertex+1)] def zerolist(n): return [0]*n def nextline(): out("\n") #as stdout.write always print sring. def testcase(t): for p in range(t): solve() def printlist(a) : for p in range(0,len(a)): out(str(a[p]) + ' ') def lcm(a,b): return (a*b)//gcd(a,b) #=============================================================================================== # code here ;)) def sieve(a): #O(n loglogn) nearly linear #all odd mark 1 for i in range(3,((10**5)+1),2): a[i] = 1 #marking multiples of i form i*i 0. they are nt prime for i in range(3,((10**5)+1),2): for j in range(i*i,((10**5)+1),i): a[j] = 0 a[2] = 1 #special left case return (a) a = [0]*((10**5)+1) a = sieve(a) # print(a[2]) # print(12345**0.5) def solve(): n = int(inp()) i = 3 f = 0 while(i*i < n): if(n%(i) == 0): f = 1 break i +=2 if(n%2 == 0): f = 1 if(f == 0): print('NO') else: i = 2 div = [] cnt = 0 while((i*i) <n): if(n%i==0): div.append(i) n = n//i cnt +=1 if(cnt == 2): break i+=1 if(cnt == 2): if(n>div[1]): print('YES') print(div[0],div[1],n) else: print('NO') else: print('NO') testcase(int(inp()))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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()) abc = set() for i in range(2, int(n**0.5)+1): if n % i == 0: if len(abc) == 0: abc.add(i) n = n//i else: if i != n//i and n//i != 1: abc.add(i) abc.add(n//i) break if len(abc) == 3: print("YES") for num in abc: print(num,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
t = int(input()) for _ in range(t): n= int(input()) import math temp = int(math.sqrt(n)) done = 0 for i in range(2,temp+1): if n%i == 0: a = i for j in range(2,int(math.sqrt(a))+1): if a%j == 0 and a/j != a: x = n//i y = j z = a//j if x!=y and z!=y and z!=x: done = 1 break if done == 1: break if i != n/i : b = n//i for j in range(2,int(math.sqrt(b))+1): if b%j == 0 and b!=b//j: x = i ; y = b//j;z = j if x!=y and z!=y and z!=x: done = 1 break if done == 1: break if done: print("YES") print(x,y,z) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# import libraries for input/ output handling # on generic level import atexit, io, sys # A stream implementation using an in-memory bytes # buffer. It inherits BufferedIOBase. buffer = io.BytesIO() sys.stdout = buffer # print via here @atexit.register def write(): sys.__stdout__.write(buffer.getvalue()) import math # A function to print all prime factors of # a given number n def primeFactors(n): m={} # Print the number of two's that divide n while n % 2 == 0: if 2 not in m: m[2]=1 else: m[2]+=1 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: if i not in m: m[i]=1 else: m[i]+=1 n = n / i # Condition if n is a prime # number greater than 2 if n > 2: m[n]=1 return m for _ in range(input()): n=input() v=primeFactors(n) if len(v)>=3: print"YES" for k,g in v.items(): t=pow(k,g);break for k,g in v.items(): r=pow(k,g); if r!=t: break print t,r,n/(t*r) elif len(v)==2: c=0;d=[];t=0;p,q,r=[],[],[] for k,g in v.items(): d.append(pow(k,g)) t+=g if g>2: p.append(k) if g==2: q.append(k) else: r.append(k) if t<=3: print"NO" else: print"YES"; if len(p): k=p[0] print k,k*k,n/(k*k*k) elif len(q): print q[0],q[1],n/(q[0]*q[1]) else: for k,g in v.items(): if g>5: print"YES";print k,k*k,n/(k*k*k) else: print"NO"
PYTHON
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; long long n, m, ni, mi; long long cn; string s; long long num[100005]; long long ok = false; deque<long long> v; map<string, bool> M; map<string, bool> MC; long long sch(long long a, long long b, long long c, long long i) { string s = to_string(a) + " " + to_string(b) + " " + to_string(c) + " " + to_string(i); if (M[s]) return MC[s]; if (a > 1 && b > 1 && c > 1) { if (a != b && a != c && b != c) { if (a * b * c == cn) { cout << "YES" << endl; cout << a << " " << b << " " << c << endl; return 1; } } } long long na, nb, nc; if (i == v.size()) return 0; na = a * v[i]; nb = b * v[i]; nc = c * v[i]; M[s] = 1; MC[s] = sch(na, b, c, i + 1) || sch(a, nb, c, i + 1) || sch(a, b, nc, i + 1); return MC[s]; } void solve() { cin >> n; cn = n; v.clear(); M.clear(); MC.clear(); for (long long i = 2; i * i < n + 5; i++) { if (n % i == 0) { while (n % i == 0) { v.push_back(i); n /= i; } } } if (n != 1) { v.push_back(n); } if (!sch(1, 1, 1, 0)) { cout << "NO" << endl; } } int32_t main() { cin.tie(0); ios_base::sync_with_stdio(NULL); long long 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
////////////////////---------------------------SHUBHAM CHAUDHARI-------------------------------/////////////////////// import java.util.*; public class Main { public static void main(String[] args) { Scanner in=new Scanner(System.in); int t=in.nextInt(); StringBuilder res=new StringBuilder(); while (t-->0) { int n=in.nextInt(); ArrayList<Integer>primes=primeFactors(n); HashSet<Integer>set=new HashSet<>(); for(int i=0;i<primes.size();i++) { set.add(primes.get(i)); } primes=new ArrayList<>(); for(int i:set) { primes.add(i); } int tmp=n; int size=0; for(int i=0;i<primes.size();i++) { while (tmp%primes.get(i)==0) { tmp/=primes.get(i); size++; } } //System.out.println(primes.size()); if(primes.size()==1) { if(size>=6) { res.append("YES\n"); //System.out.println("ji"); res.append(primes.get(0)+" "+(primes.get(0)*primes.get(0))+" "+(n/(primes.get(0)*primes.get(0)*primes.get(0)))+"\n"); } else res.append("NO\n"); } else if(primes.size()==2) { if(size>3) { res.append("YES\n"); res.append(primes.get(0)+" "+primes.get(1)+" "+(n/(primes.get(0)*primes.get(1)))+"\n"); } else { res.append("NO\n"); } } else { res.append("YES\n"); res.append(primes.get(0)+" "+primes.get(1)+" "+(n/(primes.get(0)*primes.get(1)))+"\n"); } } System.out.println(res); } public static ArrayList<Integer> primeFactors(int n) { ArrayList<Integer>list=new ArrayList<>(); while (n%2==0) { list.add(2); n /= 2; } for (int i = 3; i <= Math.sqrt(n); i+= 2) { while (n%i == 0) { list.add(i); n /= i; } } if (n > 2) list.add(n); return list; } static class Node implements Comparable<Node> { int x; int y; public Node(int x,int y) { this.x=x; this.y=y; } @Override public int compareTo(Node o) { if(x>o.x) { return 1; } if(x==o.x) { if(y>o.y) return 1; else if(y<o.y)return -1; return 0; } return -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
import collections import itertools import sys from collections import defaultdict, Counter from math import sqrt, ceil input = sys.stdin.readline ############ ---- Input Functions ---- ############ def inp(): return (int(input())) def inlt(): return (list(map(int, input().split()))) def insr(): s = input() return (list(s[:len(s) - 1])) def invr(): return (map(int, input().split())) def ds(d, s): for i in range(s, d + 1): if i*i>d: break if d % i == 0: return i def main(): n = inp() for _ in range(n): d = inp() d1 = ds(d, 2) if d1 is not None: d2 = ds(d // d1, d1 + 1) if d2 is not None: d3 = d // d1 // d2 if d3 != 1 and d3 != d1 and d3 != d2: print("YES") print(" ".join([str(v) for v in [d1, d2, d3]])) else: print("NO") else: print("NO") else: print("NO") if __name__ == "__main__": # sys.setrecursionlimit(10 ** 6) # threading.stack_size(10 ** 8) # t = threading.Thread(target=main) # t.start() # t.join() main()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt n = int(input()) for i in range(n): f = int(input()) a = [] for j in range(2, int(sqrt(f))): if f % j == 0: a.append(j) f = f // j if len(a) == 2: break if len(a)==2 and a.count(f)==0: print("YES") print(a[0], a[1], f) 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
'''input 3 1 2 3 4 5 6 ''' import math # Method to print the divisors def printDivisors(n) : list = [] # List to store half of the divisors a = [] x = n for i in range(2, int(math.sqrt(n) + 1)) : if (x % i == 0) : a.append(i) # i -= 1 x/=i if len(a)==2: p = 1 # for i in range(2,len(a)): # p*=a[i] if x==a[0] or x==a[1]: print("NO") return print("YES") print(a[0], end = " ") print(a[1], end = " ") print(int(x)) return print("NO") t = int(input()) # print(t) for i in range(t): a = int(input()) # print((60-m) + (23-h)*60) printDivisors(a)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt, floor t = int(input()) for _ in range(t): n = int(input()) if n < 24: print("NO") else: m = floor(sqrt(n)) + 1 d = 0 divs = [] for i in range(2, m): if n % i == 0: d += 1 divs.append(i) n //= i break if d == 0: print("NO") else: m = floor(sqrt(n)) + 1 for i in range(divs[0]+1, m): if n % i == 0: d += 1 divs.append(i) n //= i break if d == 2: if n in divs: print("NO") else: divs.append(n) ans = map(str, divs) print("YES") print(' '.join(ans)) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in[0]*int(input()): n=int(input());a=['YES'];i=j=2 while j<4and i*i<n: if n%i<1:a+=i,;n//=i;j+=1 i+=1 print(*(a+[n],['NO'])[j<4][:4])
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t = int(input()) for j in range(t): n = int(input()) a = 1 b = 1 c = 1 for i in range(2, int(math.sqrt(n)) + 1): if n % i == 0: a = i break m = n // a for i in range(a + 1, int(math.sqrt(m)) + 1): if m % i == 0: b = i c = m // i break if (a > 1 and b > 1) and c > b: print("YES") print(a, b, c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; double squrt(int64_t num) { double high = num, low = 0, mid; while (high - low > 0.00001) { mid = low + (high - low) / 2; if (mid * mid > num) { high = mid; } else { low = mid; } } return mid; } void solve() { int64_t num; cin >> num; for (int64_t i = 2; i * i < num; i++) { if (num % i != 0) continue; for (int64_t j = i + 1; j * j <= (num / i); j++) { int64_t x; if (num % (i * j) == 0) { int64_t x = num / (i * j); if (x != i && i != j && x != j) { cout << "YES" << "\n"; cout << i << " " << j << " " << x << "\n"; return; } } } } cout << "NO" << "\n"; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; cout.precision(10); cout << fixed; ; int64_t test; cin >> test; while (test--) { solve(); } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int add(int a, int b) { long long x = a + b; if (x >= 1000000007) x -= 1000000007; if (x < 0) x += 1000000007; return x; } long long mul(long long a, long long b) { return (a * b) % 1000000007; } long long pw(long long a, long long b) { long long ans = 1; while (b) { if (b & 1) ans = (ans * a) % 1000000007; a = (a * a) % 1000000007; b >>= 1; } return ans; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); long long rand_seed() { long long a = rng(); return a; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; for (; t; --t) { int n; cin >> n; int aa = 0, bb = 0, cc = 0; for (int i = 2; i * i <= n; ++i) if (n % i == 0) { aa = i; n /= i; break; } for (int i = 2; i * i <= n; ++i) if (n % i == 0 && i != aa) { bb = i; n /= i; break; } cc = n; if (aa && bb && cc && aa != bb && aa != cc && bb != cc) { cout << "YES\n"; cout << aa << " " << bb << " " << cc << '\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; const int MAX_N = -1; const int inf = 2e9 + 19; vector<long long> vec; void primeDiv(long long n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) { while (n % i == 0) vec.push_back(i), n /= i; } } if (n) vec.push_back(n); } int main() { ios::sync_with_stdio(false), cin.tie(0), cout.tie(0); long long Q; cin >> Q; while (Q--) { long long t, a = 1, b = 1, c = 1; cin >> t; vec.clear(); primeDiv(t); if ((int)vec.size() < 3) { cout << "NO" << endl; continue; } a = vec[0]; b = vec[1]; bool flag = false; if (a == b) b *= vec[2], flag = true; for (int i = 2 + flag; i < (int)vec.size(); i++) { c *= vec[i]; } if (a < 2 || b < 2 || c < 2 || a == b || b == c || a == c) cout << "NO" << endl; else cout << "YES" << endl << a << ' ' << b << ' ' << c << endl; } return (0); }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for i in range(t): n = int(input()) dvdrs = [] passs = True if n < 24: print("NO") continue for k in range(2,n): if k*k*k > n: passs = False break if n%k == 0: dvdrs += [k] n = int(n/k) break if passs: for k in range(dvdrs[0]+1, n): if k*k > n: passs = False break if n%k == 0: dvdrs += [k] n = int(n/k) break if passs and n != dvdrs[0] and n != dvdrs[1]: print("YES") print(str(dvdrs[0]) + " " + str(dvdrs[1]) + " " + str(n)) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def div(n): l = [] i = 2 while i <= math.sqrt(n): if (n % i == 0): if (n / i == i): l.append(int(i)) else: l.append(int(i)) l.append(int(n/i)) i = i + 1 l.sort() return l for _ in range(int(input())): n = int(input()) y = n l = div(n) l = l[::-1] #print(l) o = [] if len(l) != 0: y = y//l[-1] x1 = l[-1] o.append(l[-1]) l.pop() else: print("NO") continue if len(l) != 0: f = 1 while(f == 1 and (y % l[-1] != 0)): l.pop() if len(l) == 0: f = 0 if f == 0: print("NO") continue y = y // l[-1] o.append(l[-1]) x2 = l[-1] l.pop() if len(l) == 0: print("NO") continue if (x2 == y) or (x1 == x2) or (x1 == y) or (x1 == 1) or (x2 == 1) or (y == 1): print("NO") continue o.append(y) else: print("NO") continue cnt = 1 for i in o: cnt = cnt*i if cnt == n: print("YES") for i in o: print(i,end = " ") print("") else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; import java.lang.Math; import java.io.* ; public class Account { class Pair { int key ; int val ; Pair(int key ,int val) { this.key = key ; this.val = val ; } int getKey() { return this.key ; } int getVal() { return this.val ; } } public static void main (String[] args) { // Scanner sc= new Scanner(System.in) ; FastReader sc= new FastReader() ; // StringBuilder res= new StringBuilder() ; int t= 1 ; t= sc.nextInt() ; while(t-- > 0) { long n= sc.nextLong() ; int rt= (int) Math.sqrt(n) ; int x= -1 ; boolean flg= false ; int m= rt - ((rt*rt == n) ? 1 : 0) ; for(int i=2 ;i<=m ;i++) { if(x == -1 && n%i == 0) { x= i ; }else if(n%(x*i) == 0) { long num= (n) / (x*i) ; if(num != x && num != i) { flg= true ; System.out.println("YES"); System.out.println(x+" "+i+" "+num); } break ; } }if(flg == false) { System.out.println("NO"); } } } public static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } int [] readintarray(int n) { int res [] = new int [n]; for(int i = 0; i<n; i++)res[i] = nextInt(); return res; } long [] readlongarray(int n) { long res [] = new long [n]; for(int i = 0; i<n; i++)res[i] = nextLong(); return res; } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def primeFactors(n): li =[] while n % 2 == 0: li.append(2) #print (2) n = n//2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: ##print (i) li.append(i) n = n//i if n > 2: li.append(n) #print (n) return li for _ in range(int(input())): n = int(input()) li = primeFactors(n) d = dict() for i in li: if i not in d: d[i] = 1 else: d[i] += 1 #print(d) if(len(d) == 1): x = li[0] if(d[x]>=6): print("YES") print(x,x*x,pow(x,d[x]-3)) else: print("NO") if(len(d)>=3): x = 1 lee = [] for i in d: lee.append((i,d[i])) a = pow(lee[0][0],lee[0][1]) b = pow(lee[1][0],lee[1][1]) c = 1 for i in range(2,len(d)): c = c*pow(lee[i][0],lee[i][1]) print("YES") print(a,b,c) if(len(d) ==2): lee = [] for i in d: lee.append((i,d[i])) if(lee[0][1]>=3): print("YES") x= lee[0][1] print(lee[0][0], pow(lee[0][0], lee[0][1]-1), pow(lee[1][0],lee[1][1])) elif(lee[1][1]>=3): print("YES") x= lee[1][1] print(pow(lee[0][0],lee[0][1]), lee[1][0], pow(lee[1][0], lee[1][1]-1)) elif(lee[0][1] == 2 and lee[1][1]==2): print("YES") print(lee[0][0],lee[0][0]*lee[1][0], lee[1][0]) 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 ll = long long; using lli = long long int; using ld = long double; const int N = 2e5 + 5, inf = 2e9; bool valid(int a, int b, int c) { if (a == b || b == c || a == c) return false; return true; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int x = 0, y = 0; vector<pair<int, int>> v; set<int> st; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { v.push_back({i, n / i}); } } int a = 0, b = 0, c = 0; int found = false; for (auto p : v) { for (int i = 2; i * i <= p.first; i++) { if (p.first % i == 0) { a = i; b = p.first / i; c = p.second; if (valid(a, b, c)) { found = true; break; } } } if (found) break; for (int i = 2; i * i <= p.second; i++) { if (p.second % i == 0) { a = i; b = p.second / i; c = p.first; if (valid(a, b, c)) { found = true; break; } } } if (found) break; } if (found) { cout << "YES" << "\n"; cout << a << " " << b << " " << c << "\n"; } else cout << "NO" << "\n"; } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; public class geek { public static void main(String[] args) { Scanner s = new Scanner(System.in); int t = s.nextInt(); while (t-- > 0) { int n = s.nextInt(); int a = 0; int b = 0; int c = 0; boolean flag = true; boolean flag1 = true; boolean flag2 = true; StringBuffer sb = new StringBuffer(); for (int i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) { a = i; flag = false; break; } } if (flag) { System.out.println("NO"); } else { int k = n / a; for (int i = a + 1; i <= Math.sqrt(k); i++) { if (k % i == 0) { b = i; break; } }if(b<2){ System.out.println("NO"); }else { int p = k / b; if (p != a && p != b && a != b) { System.out.println("YES\n" + "" + a + " " + b + " " + p); } else { System.out.println("NO"); } } } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys from collections import defaultdict as dc import math from bisect import bisect, bisect_left,bisect_right input=sys.stdin.readline for _ in range(int(input())): n=int(input()) i=2 f=0 #p=math.sqrt(n) while(i<=math.sqrt(n)): if n%i==0: f=1 break i+=1 if f==0: #print("c1") print("NO") else: f=0 n=n//i j=2 while(j<=math.sqrt(n)): if j not in [1,i] and n%j==0: f=1 break j+=1 if f==0: #print("c2") print("NO") else: n=n//j if i!=j and n!=i and n!=j: print("YES") print(i,j,n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def prime(n): if n == 1: return [] if n == 2: return [2] i = 2 while i*i <= n: if n%i == 0: return prime(n//i)+[i] i += 1 return [n] for _ in range(int(input())): n = int(input()) a = sorted(prime(n)) if len(set(a)) >= 3: print("YES") prod = 1 for x in a[1:-1]: prod *= x print(a[0], prod, a[-1]) if len(set(a)) == 2: if len(a) >= 4: print("YES") prod = 1 for x in a[1:-1]: prod *= x print(a[0], prod, a[-1]) else: print("NO") if len(set(a)) == 1: if len(a) >= 6: print("YES") print(a[0], a[0]*a[0], a[0]**(len(a)-3)) else: print("NO") if a == []: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def prod(li): p = 1 for i in li: p*=i return p def getAns(n): d = dict() while n % 2 == 0: if 2 in d.keys(): d[2] += 1 else: d[2] = 1 n//=2 for i in range(3, int(math.sqrt(n)) + 3, 2): while n % i == 0: if i in d.keys(): d[i] += 1 else: d[i] = 1 n//=i if n > 2: d[n] = 1 k = list(d.keys()) if len(k) >= 3: a = k[0]**d[k[0]] b = k[1]**d[k[1]] c = prod([(k[i]**d[k[i]]) for i in range(2, len(k))]) elif len(k) == 2: if d[k[0]] >= 3: a = k[0] b = k[0]**(d[k[0]] - 1) c = k[1]**(d[k[1]]) else: if d[k[1]] >= 3: a = k[0]**d[k[0]] b = k[1] c = k[1]**(d[k[1]] - 1) elif d[k[1]] == 2 and d[k[0]] == 2: a = k[0] b = k[1] c = k[0]*k[1] else: return False, -1, -1, -1 else: if d[k[0]] >= 6: a = k[0] b = k[0] * k[0] c = k[0]**(d[k[0]] - 3) else: return False, -1, -1, -1 return True, a, b, c for _ in range(int(input())): n = int(input()) truth,a,b,c = getAns(n) if truth: print("YES") print(*sorted([a,b,c])) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import string import math import collections def LeReseauLMD(n): orin = n a,b,c = 0,0,0 for a in range(2,math.floor(n**0.5)+1): if n%a==0: n //=a for b in range(2,math.floor((n)**0.5)+1): if n%b == 0 and b != a: """for c in range(2,math.floor(n**0.5)+1): if n%c == 0 and c != b and c != a: break""" c = n//b if c == a or c == b: c = 0 break break if a*b*c == orin: return f"{a} {b} {c}" else: return "NO" def main(): q = int(input()) for _ in range(q): n = int(input()) rep = LeReseauLMD(n) if rep != "NO": print("YES") print(rep) 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
#include <bits/stdc++.h> using namespace std; const int max6 = 1e6 + 6; map<int, int> rem; int e[max6], p[max6]; int main() { int tests; scanf("%d", &tests); for (int i = 1; i <= 1000000; ++i) e[i] = i; int sl = 0; for (int i = 2; i <= 1000000; ++i) if (e[i] == i) { p[++sl] = i; for (int j = 1; j * i <= 1000000; ++j) e[i * j] = i; } while (tests--) { int n; scanf("%d", &n); int _n = n; rem.clear(); sl = 0; int j = 1; while (n > 1000000) { int t; while (p[j] <= n / p[j] && n % p[j] != 0) j++; if (p[j] > n / p[j]) t = n; else t = p[j]; while (n % t == 0) { rem[t]++; n = n / t; } } while (n > 1) { int p = e[n]; rem[p]++; n = n / p; } auto v = rem.begin(); int a = (*v).first; rem[a]--; int b = 1; bool ok = false; int c; while (b == 1 || b == a) { if ((*v).second == 0) { v++; if (v == rem.end()) break; } (*v).second--; b = b * (*v).first; } c = _n / (a * b); if (a >= 2 && b >= 2 && c >= 2) if (a != b && b != c && c != a) ok = true; if (ok) { 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())): i = 2 l = [] n = int(input()) size = 0 while(i*i<=n and size < 2): if(n % i == 0): l.append(i) n //= i size += 1 i += 1 if(size == 2 and (l[0]!=n and l[1]!=n)): print('YES') print(l[0],l[1],n) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def read_ints(): return map(int, input().split()) def read_int(): return int(input()) def factors(n): factors_p = dict() twos = 0 while n % 2 == 0: n //= 2 twos += 1 if twos > 0: factors_p[2] = twos d = 3 while d * d <= n: p = 0 while n % d == 0: p += 1 n //= d if p > 0: factors_p[d] = p d += 2 if n > 1: factors_p[n] = 1 return factors_p t = read_int() for _ in range(t): n = read_int() primes = factors(n) p_sum = 0 abc = [] for k, v in primes.items(): p_sum += v if len(primes) < 1: print("No") continue elif len(primes) == 1: if p_sum < 6: print("No") continue else: print("Yes") d = list(primes.keys())[0] abc = [d, d ** 2, n // (d ** 3)] elif len(primes) == 2: psum = 0 for k, v in primes.items(): psum += v if psum < 4: print("No") continue print("Yes") p1, p2 = list(primes.keys())[:2] abc = [p1, p2, n // (p1 * p2)] elif len(primes) >= 3: print("Yes") p1, p2 = list(primes.keys())[:2] abc = [p1, p2, n // (p1 * p2)] print(*abc)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import floor, sqrt, ceil t = int(input()) for _ in range(t): a = -1 b = -1 n = int(input()) i = 2 while i*i < n: if n % i == 0: a = i n //= a break i += 1 i = 2 while i*i < n: if n % i == 0 and i != a: b = i n //= b break i += 1 if a == -1 or b == -1 or n == 1 or n == a or n == b: 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
m=int(input()) for l in range(m): n=int(input()) q,t=int(n**.5)+1,0 for i in range(2,q): if n%i==0: a=n//i w=int(a**.5)+1 for j in range(2,w): if a%j==0: r=a//j if r!=j and j!=i and r!=i: print("YES") print(i,j,r) t=1 break if t: break if not t: 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 m=1000000007 def fact(n): ans=1 for i in range(1,n+1): ans=((ans%m)*(i%m))%m return ans def power_2(n): ans=1 for i in range(n): ans=((ans%m)*(2))%m return ans for z in range(int(input())): n=int(input()) fin=int(math.ceil(n**(1/3))) cnt,i=0,2 # to find the first no in three we check the #value when it is less than cube root of n # becouse left no(2nd and 3rd) must be greater #than first becoz any no.less than first is not #able to divide n while(i<=fin): if(n%i==0): cnt+=1 n=int(n/i) break i+=1 fin=int(math.ceil(n**(1/2))) j=i+1 while(j<=fin): if(n%j==0 and j!=int(n/j) and int(n/j)!=i): cnt+=1 break j+=1 if(cnt==2): print("YES") print(i,j,int(n/j)) 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 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep=" ") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sys.stdin.readline()[:-1] g = II() for j in range(g): n = II() fl = 0 i = 2 used = set() while i*i*i<n: if n % i == 0: used.add(i) n //= i break i += 1 if len(used) == 0: print("NO") continue i += 1 while i * i < n: if n % i == 0: used.add(i) n //= i break i += 1 if len(used) == 1: print("NO") continue if n not in used: used.add(n) print("YES") p2D(used) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys input=sys.stdin.readline t=int(input()) for i in range(t): x=int(input()) ar=[] l=0 a=1 b=1 c=1 ct=0 bl=False for j in range(2,int(x**(0.5))): if(x%j==0 and ct==0): a=j ct+=1 elif(x%j==0 and ct==1): temp=j if(x%(a*temp)==0 and x//(a*temp)!=a and x//(a*temp)!=temp): b=temp c=x//(a*temp) bl=True break if(bl==True): print("YES") print(a,b,c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin, stdout import sys INF=1e9 import bisect def get_int(): return int(stdin.readline().strip()) def get_ints(): return map(int,stdin.readline().strip().split()) def get_array(): return list(map(int,stdin.readline().strip().split())) def get_string(): return stdin.readline().strip() def op(c): return stdout.write(c) #from collections import defaultdict import math for _ in range(int(stdin.readline())): n=get_int() a,b,c=0,0,0 f=0 for i in range(2,int(math.sqrt(n))+1): if n%i==0: a=i n=n//i for j in range(i+1,int(math.sqrt(n))+1): if n%j==0: b=j n=n//j f=1 break if f==1: break if f==1 and n not in [a,b] : print("YES") print(a,b,n) continue print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): num = int(input()) list_of_nums = [1] for i in range(2, int(pow(num, .5)+1)): if num % i == 0: num = num // i list_of_nums.append(i) break # print(list_of_nums) for i in range(2, int(pow(num, .5))+1): if num % i == 0 and i not in list_of_nums: num //= i list_of_nums.append(i) break # print(list_of_nums) if num not in list_of_nums and len(list_of_nums) > 2: print("YES") list_of_nums = [str(x) for x in list_of_nums] print(num, ' '.join(list_of_nums[1:])) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
'use strict' const problem = (n) => { for (let i = 2; i < Math.cbrt(n); i++) { if (n % i === 0) { n /= i; for (let j = i + 1; j < Math.sqrt(n); j++) { if (n % j === 0) return `YES\n${i} ${j} ${n/j}`; } } } return 'NO'; } let t = +readline(); while(t--) print(problem(+readline()));
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 my_def(x): a, b, c = 1, 1, 1 for j in range(2, int(x ** 0.5) + 2): while x % j == 0: if a == 1: a = j elif b == 1 or b == a: b *= j else: return (a, b, x) x //= j return (a, b, x) n = int(input()) for i in range(n): x = int(input()) a, b, c = my_def(x) if a != b and b != c and a != c and a != 1 and b != 1 and c != 1: print("YES") print(a, b, c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt def calcul(x,message): for j in range (2,int(sqrt(x))): if x%j==0: m=x/j s=int(sqrt(m)) if j+1>s: s=int(m/2) for k in range (j+1,s+1): if (m%k==0) and (int(m/k)!=k) and (int(m/k)!=j): message="YES" print(message) print(j,' ',k,' ',int(m/k)) return -1 n = int(input()) l=[] for i in range (0,n): l.append(int(input())) for i in range (0,n): message="NO" if calcul(l[i],message)!=-1: print(message)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt t=int(input()) for w in range(t): n=int(input()) c=0 ans=[] for i in range(2,int(sqrt(n))+1): if n==1 or c==2: break if n%i==0: ans.append(i) n=n//i c+=1 if c<2 or n==ans[1] or n==ans[0]: print("NO") else: print("YES") print(ans[0],ans[1],n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math from collections import Counter,defaultdict I =lambda:int(input()) M =lambda:map(int,input().split()) LI=lambda:list(map(int,input().split())) for _ in range(I()): n=I();i=2;a,b,c=-1,-1,-1 while i*i<=n: while n%i==0: n//=i if a==-1: a=i elif b==-1 or a==b: if b==-1:b=i else:b*=i else: if c==-1:c=i else:c*=i i+=1 if n>1: if c==-1:c=n else:c*=n if min(a,b,c)==-1 or b==c or a==b 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
#include <bits/stdc++.h> int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int flag, a, b, c; flag = 1; if (n % 2 == 0) { a = 2; flag = 0; } else for (a = 3; a * a * a <= n; a += 2) if (n % a == 0) { flag = 0; break; } if (!flag) { int flag2 = 0; n /= a; flag = 1; if (n % 2 == 0) flag2 = 1; for (b = a; b * b <= n;) { if ((n % b == 0) && (a != b)) { flag = 0; break; } b++; } if (!flag) { n /= b; flag = 1; if ((n != a) && (n != b) && (n >= 2)) flag = 0; } } if (flag) printf("NO\n"); else printf("YES\n%d %d %d\n", a, b, n); } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; public class code { static int sqrt(int x) { for(int i=2; true; i++) { if(i*i==x) { return i; } if(i*i>x) { return i-1; } } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); for(int i=0; i<n; i++) { int a= sc.nextInt(); int b= sqrt(a); int c=0; double[] arr= new double[2]; for(double j=2; j<=b; j++) { if((a/j)%1==0) { arr[c]=j; c++; } if(c==2) { double z=((a/arr[0])/arr[1]); if(z%1==0 && z!=arr[1] && z!=arr[0]) { break; } else { c--; } } } if(c==2) { System.out.println("YES"); System.out.println((int)arr[0]+" "+(int)arr[1]+" "+(int)((a/arr[0])/arr[1])); } 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
def find_multipliers(n): if n < 8: return None a = b = c = None for i in range(2, int(n**0.5 + 1)): if n % i == 0: a = i break if a is None: return None n /= a for i in range(2, int(n**0.5 + 1)): if (i != a) and (n % i == 0): b = i break if b is None: return None c = n / b if (c == a) or (c == b): return None return a, b, c t = int(input()) for _ in range(t): n = int(input()) result = find_multipliers(n) if result is None: print("NO") else: print("YES") print(" ".join(map(str, 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
def Sieve(n): ret = [] divlis = [-1] * (n+1) flag = [True] * (n+1) flag[0] = False flag[1] = False ind = 2 while ind <= n: if flag[ind]: ret.append(ind) ind2 = ind ** 2 while ind2 <= n: flag[ind2] = False divlis[ind2] = ind ind2 += ind ind += 1 return ret,divlis t = int(input()) ret,divs = Sieve(10**6) for loop in range(t): n = int(input()) ans = [] now = 1 flag = False for i in ret: while n % i == 0: n //= i now *= i if now > 1 and now not in ans: ans.append(now) now = 1 if len(ans) == 2: if n not in ans and n > 1: ans.append(n) print ("YES") print (" ".join(map(str,ans))) flag = True break else: print ("NO") flag = True break if flag: 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
#include <bits/stdc++.h> using namespace std; int main() { long long int T; cin >> T; while (T--) { long long int n, k = 0, i, j, b, c, flag = 0, p = 0; cin >> n; vector<int> a; for (int i = 1; i <= sqrt(n); i++) { if (n % i == 0) { if (n / i == i) a.push_back(i); else { a.push_back(i); a.push_back(n / i); } } } sort(a.begin(), a.end()); for (i = 0; i < a.size(); i++) { if (a[i] < 2) continue; else { for (j = 0; j < a.size(); j++) { if (a[j] < 2) continue; else { for (k = 0; k < a.size(); k++) { if (a[k] < 2) continue; else if (a[i] * a[j] * a[k] == n && a[i] != a[j] && a[j] != a[k] && a[k] != a[i]) { cout << "YES" << endl; cout << a[i] << " " << a[j] << " " << a[k] << endl; flag = 1; break; } } } if (flag == 1) break; } } if (flag == 1) break; } if (flag == 0) 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 _ in range(int(input())): n=int(input()) l=[] a=2 m=n while a*a<=n: if(n%a==0): l.append(a) n=n//a break a+=1 b=2 while b*b<=n: if(n%b==0): if b not in l: l.append(b) n=n//b break b+=1 if(len(l)==2): c=m//(l[0]*l[1]) if c not in l: print("YES") print(l[0],l[1],c) else: print("NO") else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for i in range(t): N = int(input()) answer = [] F = 0 for i in range(2,int(N**0.5)+1): if N%i == 0: X = i Z = N//i for j in range(2,int(Z**0.5)+1): if Z%j==0: ANS1=Z//j if ANS1!=j and ANS1!=X and j!=X: print("YES") print(ANS1,j,X) F=1 break if F==1: break if F==0: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from bisect import bisect_left as bl from bisect import bisect_right as br import heapq import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline # M = mod = 998244353 def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))) # def inv_mod(n):return pow(n, mod - 2, mod) def li():return [int(i) for i in input().rstrip('\n').split()] def st():return input().rstrip('\n') def val():return int(input().rstrip('\n')) def li2():return [i for i in input().rstrip('\n').split(' ')] def li3():return [int(i) for i in input().rstrip('\n')] def primefactors(n): l = [] while not n%2: l.append(2) n//=2 for i in range(3,int(math.sqrt(n)) + 1,2): while not n%i: l.append(i) n//=i if n>2: l.append(n) return l # # https://www.geeksforgeeks.org/print-all-prime-factors-of-a-given-number/ # def primeFactors(n): # # Print the number of two's that divide n # l = [] # while n % 2 == 0: # l.append(2) # n = n // 2 # # n must be odd at this point # # so a skip of 2 ( i = i + 2) can be used # for i in range(3,int(math.sqrt(n))+1,2): # # while i divides n , print i ad divide n # while n % i== 0: # l.append(i) # n = n // i # # Condition if n is a prime # # number greater than 2 # if n > 2: # l.append(n) # return l for _ in range(val()): l = sorted(primefactors(val())) ans = 'YES' if len(l) < 3: print('NO') continue first = l[0] second = 1 # print(l) for i in range(1,len(l)-1): secondlast = l[i-1] second*=l[i] last = l[i] third = l[-1] if second == third: second//=last third*=last if third == first: second//=secondlast third*=secondlast if second == first or second == third or first == third or 1 in set([first,second,third]): print('NO') continue print('YES') print(first,second,third)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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.Math.max; public class Main { public static void main(String[] args) throws IOException { run(); end(); } static void run() throws IOException { int t = nextInt(); while (t-- > 0) { solve(nextInt()); } } private static void solve(int n) { for (int i = 2; i * i <= n; ++i) { if (n % i == 0) { for (int j = 2; j * j < n / i; ++j) { if ((n / i) % j == 0 && j != i && n / i / j != i) { out.println("YES"); out.println(n / i / j + " " + i + " " + j); return; } } } } out.println("NO"); } static class mem { int x, y; } static class comparator implements Comparator<mem> { public int compare(mem o1, mem o2) { if (o1.x != o2.x) return Integer.compare(o1.x, o2.x); return Integer.compare(o1.y, o2.y); } } static long stepenb(long a, long b) { long h = 1; while (b > 0) { if (b % 2 != 0) { h *= a; b--; } b /= 2; a *= a; } return h; } static long lcm(long a, long b) { return a * b / gcd(a, b); } private static long gcd(long a, long b) { return b == 0 ? a : gcd(b, a % b); } static void end() { out.flush(); out.close(); } static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); static PrintWriter out = new PrintWriter(System.out); static StringTokenizer in = new StringTokenizer(""); public static String nextToken() throws IOException { while (in == null || !in.hasMoreTokens()) { String s = br.readLine(); if (s == null) return null; in = new StringTokenizer(s); } return in.nextToken(); } public static int nextInt() throws IOException { return Integer.parseInt(nextToken()); } public static double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } public static long nextLong() throws IOException { return Long.parseLong(nextToken()); } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def factors(x): l=[] while(x>1): a=0 for i in range(2,int(math.sqrt(x)+1)): if(x%i==0): l.append(i) a=1 break if(a==0): l.append(x) break x=x//l[-1] return l t=int(input()) while(t): n=int(input()) l1 = factors(n) if(len(l1)<3): print("NO") elif(len(l1)==3): if((l1[0]!=l1[-1])and(l1[0]!=l1[1])and(l1[1]!=l1[-1])): print("YES") s="" for i in l1: s+=str(i)+" " print(s) else: print("NO") else: if(l1[0]==l1[1]): l1[1] = l1[1]*l1[2] l1.pop(2) i=3 while(i<len(l1)): l1[2]*=l1[i] l1.pop(i) if((l1[0]!=l1[-1])and(l1[0]!=l1[1])and(l1[1]!=l1[-1])): print("YES") s="" for i in l1: s+=str(i)+" " print(s) else: print("NO") else: i=3 while(i<len(l1)): l1[2]*=l1[i] l1.pop(i) if((l1[0]!=l1[-1])and(l1[0]!=l1[1])and(l1[1]!=l1[-1])): print("YES") s="" for i in l1: s+=str(i)+" " print(s) 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
t = int(input()) while(t): n = int(input()) l = [] i = 2 c = 0 while(c < 2 and i*i < n): if(n % i == 0): l.append(i) n //= i c += 1 i += 1 #print(*l) if(c == 2 and n not in l): print('YES') print(*l, n) else: print("NO") t -= 1
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# -*- coding: utf-8 -*- """ Created on Tue Feb 4 23:28:21 2020 @author: User """ import math n = int(input()) num = [] for i in range(n): num.append(int(input())) for x in num: flag = 0 counter = 0 y = int(math.sqrt(x)) for j in range(2,y+1) : if flag == 1 : break elif x % j == 0 : a = int(j) nu = int(x/j) z=int(math.sqrt(nu)) for k in range(j+1,z+1) : if nu % k == 0 : b = int(k) c = int(nu/k) if b==c or a==c : counter = 0 else : print('YES') print(a,b,c) flag = 1 counter = 1 break if counter == 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
/*package whatever //do not write package name here */ import java.util.*; import java.lang.*; import java.io.*; public class GFG { public static void main (String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) {int n=sc.nextInt();mm(n);} } static int mm (int n){ int nsqr=(int)Math.sqrt(n); for(int j=2;j<=nsqr;j++) { if(n%j==0) {int nbyjsqr=(int)Math.sqrt(n/j); for(int k=j+1;k<=nbyjsqr;k++) { if((n/j)%k==0) {if(j!=k&&k!=(n/(j*k))&&(n/(j*k))!=j) {System.out.println("YES"); System.out.println(j+" "+k+" "+n/(k*j)); return 1; }} } } } System.out.println("NO"); return -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
#-------------Program-------------- #----Kuzlyaev-Nikita-Codeforces---- #-------------Round615------------- #---------------------------------- t=int(input()) for i in range(t): n=int(input()) a=[] for i in range(2,int(n**0.5)+2): if len(a)==2: a.append(n) break if n%i==0: a.append(i) n//=i a=list(set(a)) if len(a)==3 and a.count(1)==0: print('YES') a.sort() 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 sys def minp(): return sys.stdin.readline().strip() def mint(): return int(minp()) def mints(): return map(int, minp().split()) def solve(): n = mint() a = [] nn = n for i in range(2,n+1): if i*i > n: break if n % i == 0: c = 0 while n % i == 0: n //= i if len(a) == 2: break c += 1 a.append((i, c)) if n != 1: a.append((n, 1)) if len(a) == 1: if a[0][1] < 6: print('NO') else: print('YES') print(a[0][0],a[0][0]**2,nn // (a[0][0]**3)) elif len(a) == 2: if a[0][1] > 1 and a[1][1] > 1: print('YES') print(a[0][0],a[1][0],nn // (a[0][0]*a[1][0])) elif a[0][1] > 2: print('YES') print(a[0][0],a[0][0]**2,nn // (a[0][0]**3)) elif a[1][1] > 2: print('YES') print(a[1][0],a[1][0]**2,nn // (a[1][0]**3)) else: print('NO') else: print('YES') print(a[0][0],a[1][0],nn // (a[0][0]*a[1][0])) for i in range(mint()): 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; inline void setPrecision(int n) { cout.precision(n); } long long int INF = 1e10; int MOD = 1e9 + 7; inline bool same2(int x, int y, int z) { return (x == y) || (y == z) || (z == x); } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int tt; cin >> tt; while (tt--) { int n; cin >> n; int first = -1; for (int i = 2; i * i <= n; ++i) { if (n % i == 0) { first = i; break; } } if (first == -1) { cout << "NO\n"; continue; } n /= first; int second = -1; for (int i = first + 1; i * i <= n; ++i) { if (n % i == 0) { second = i; break; } } if (second == -1 || same2(first, second, n / second)) { cout << "NO\n"; continue; } cout << "YES\n"; cout << first << " " << second << " " << n / second << "\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 t=int(input()) for _ in range(t): n=int(input()) raj=set() for i in range(2, math.ceil(math.sqrt(n))): if(n%i==0): raj.add(i) raj.add(n//i) flg=0 for i in raj: a=i dup=n//a andro=set() for j in range(2, math.ceil(math.sqrt(dup))): if(dup%j==0): b=j c=dup//b if(b!=a and b!=c and c>1 and a!=c): ans=[a,b,c] ans=sorted(ans) print("YES") print(*ans) flg=1 break if(flg==1): break if(not flg): print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def div(n, r): sq = math.sqrt(n) d = 1 for x in range(2, int(sq) + 1): if n % x == 0 and x != r: d = x break return d t = int(input()) for i in range(0, t): y = int(input()) a = div(y, 1) if a == 1: print("NO") continue else: z = int(y / a) b = div(z, a) if b == 1 or b == a: print("NO") continue else: c = int(y / (a * b)) if c == 1 or c == a or c == b: print("NO") continue 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 def deliteli_chisla(cur): mas = [] ot = "NO" n = cur for i in range(2, math.ceil(cur ** 0.5)): if n % i == 0: mas.append(i) for i in range(len(mas)): del1 = mas[i] nn = n // del1 s = nn for j in range(i, len(mas)): nn = s if nn % mas[j] == 0: nn = nn // mas[j] del2 = mas[j] if del1 * del2 != n and n % (del1 * del2) == 0: if del1 != del2 and del2 != (n // del1 // del2) and del1 != n // del1 // del2: ot = "YES\n" + str(del1) + " " + str(del2) + " " + str(n // del1 // del2) return ot for t in range(int(input())): n = int(input()) if deliteli_chisla(n) is None: print("NO") else: print(deliteli_chisla(n))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a, b, c, c1 = 0; for (int i = 2; i < sqrt(n) + 1; i++) { if (n % i == 0) { if (c1 == 0) { a = i; c1++; n = n / i; } else if (c1 == 1) { b = i; c = n / i; c1++; break; } } } if (c1 < 2 || b == c || a == c) cout << "NO" << endl; else { cout << "YES" << endl << a << " " << b << " " << c << 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
for _ in range(int(input())): n = int(input()) a = [] i=2 while(len(a)<2 and i*i <n): if n%i ==0: n=n//i a.append(i) i+=1 if len(a)==2 and n not in a:print("YES");print(n,*a) else:print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t=int(input()) for i in range(t): n=int(input()) a=[] for j in range(2,int(n**0.5)+1): if(n%j==0): a.append(j) n=n/j break if(len(a)==1): for k in range(j+1,int(n**0.5)+1): if(n%k==0): a.append(k) n=int(n/k) break if(len(a)==2): if(n!=a[0] and n!=a[1]): print("YES") print(a[0],end=" ") print(a[1],end=" ") print(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
t = int(input()) for i in range(t): n = int(input()) ans=list() for i in range(2,int(n**(2/3))+1): if len(ans) == 2: break if n%i==0: ans.append(i) n//=i if len(ans) == 2 and ans[1] < n: print('YES') print(*ans, n) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math T=int(input()) for i in range((T)): x=input() x=int(x) d=0 a,b,c=-1,-1,-1 p=x for j in range(2,int(math.sqrt(x))+1): if x%j==0: a=j x=x//j break if a!=-1: for j in range(a+1,int(math.sqrt(x))+1): if x%j==0: b=j x=x//j break if p%x==0: c=x if a==-1 or b==-1 or c==-1 or b==c or a==c: 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
t = int(input()) for _ in range(t): n = int(input()) f = 0 for x in range(2, n): if x * x * x >= n: break for y in range(x + 1, n): #print(x, y) if x * y * y >= n: break if n % (x * y) == 0: f = 1 print("YES") print(x, y, n // (x * y)) break if f > 0: 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
#include <bits/stdc++.h> int main() { int t; std::cin >> t; for (; t > 0; t--) { long n; std::cin >> n; int i = 2; std::vector<int> primes; while (i * i <= n) { if (n % i == 0) { while (n % i == 0) { primes.push_back(i); n /= i; } } i++; } if (n != 1) { primes.push_back(n); } if (primes.size() < 3) { std::cout << "NO\n"; continue; } long a = primes[0]; long b = primes[1]; int next_prime = 2; if (a == b) { b *= primes[next_prime++]; } if (primes.size() <= next_prime) { std::cout << "NO\n"; continue; } long c = primes[next_prime++]; while (next_prime < primes.size()) { c *= primes[next_prime++]; } if (c == a or c == b) { std::cout << "NO\n"; } else { std::cout << "YES\n"; std::cout << a << " " << b << " " << c << "\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.util.Arrays; import java.util.Comparator; import java.util.HashSet; import java.util.LinkedList; import java.util.Queue; import java.util.Scanner; import java.util.Set; public class Main { private static long gcd(long a, long b) { return (a == 0 ? b : gcd(b % a, a)); } public static void main(String[] args) { Scanner cin = new Scanner(System.in); int t = cin.nextInt(); while (t-- != 0) { int n = cin.nextInt(); int a = 0,b = 0,c = 0; int flag = 0; for(int i = 2;i * i <= n;i++) { if(n % i == 0) { for(int j = 2;j * j <= n / i;j++) { if((n / i) % j == 0 && ((n / i) / j) >= 2 && (i) != (n / i / j) && i != j && j != (n / i / j)) { a = i; b = j; c = n / i / j; flag = 1; break; } } } if(flag == 1)break; } if(flag == 1)System.out.println("YES" + "\n" + a + " " + b + " " + c); else System.out.println("NO"); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt def check(n): k=0 for i in range(2,int(sqrt(n+1))): if k==2 and n>=i: return a,b,n if k==3: return a,b,c if k<3 and n<i: return 'NO' if n%i==0: k+=1 n //= i if k==1: a=i elif k==2: b=i elif k==3: c=i return 'NO' t = int(input()) for i in range (t): n = int(input()) out = check(n) if type(out)==str: print(out) else: print('YES') for x in list(out): print(x,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
# Python3 implementation of the approach from math import sqrt # Function to find the required triplets def findTriplets(x): # To store the factors fact = []; factors = set(); # Find factors in sqrt(x) time for i in range(2, int(sqrt(x))): if (x % i == 0): fact.append(i); if (x / i != i): fact.append(x // i); factors.add(i); factors.add(x // i); found = False; k = len(fact); for i in range(k): # Choose a factor a = fact[i]; for j in range(k): # Choose another factor b = fact[j]; # These conditions need to be # met for a valid triplet if ((a != b) and (x % (a * b) == 0) and (x / (a * b) != a) and (x / (a * b) != b) and (x / (a * b) != 1)): # Print the valid triplet print("YES") print(a, b, x // (a * b)); found = True; break; # Triplet found if (found): break; # Triplet not found if (not found): print("NO"); # Driver code if __name__ == "__main__": t=int(input()) while(t): t-=1 n=int(input()) findTriplets(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
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Wed Jan 22 08:37:17 2020 @author: huynguyen """ def findTripple(n): res = [] for i in range(2,int(n**.5)+1): if n%i == 0: res.append(i) n//=i if len(res) ==2: break if n!=1: if res: if n not in res: res.append(n) return res t = int(input()) for test in range(t): n = int(input()) res = findTripple(n) if len(res)==3: print("YES") print (" ".join([str(item) for item in res])) 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 q = int(input()) for _ in range(q): n = int(input()) cnt = 0 save = [0] * 6 for i in range(2, int(sqrt(n)) + 2): if n % i == 0: cnt += 1 save[cnt] = i n = int(n/i) if cnt == 2: break if cnt < 2: print("NO") elif n <= save[cnt]: print("NO") else: print("YES") print(save[1], save[2], n, ' ')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t, i; long n, d, arr[2]; cin >> t; while (t--) { cin >> n; i = 0; for (d = 2; d * d < n && i < 2; d++) { if (n % d == 0) { arr[i++] = d; n /= d; } } if (i == 2) cout << "YES\n" << arr[0] << ' ' << arr[1] << ' ' << n << '\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
t=int(input()) for x in range(t): n=int(input()) l=[] i=2 while len(l)<2 and n>i**2: if n%i==0: l.append(i) n=n/i i+=1 if len(l)==2 and n not in l: print('YES') print(*l,int(n)) else:print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys import os import time import collections from collections import Counter, deque import itertools import math import timeit import random ######################### # imgur.com/Pkt7iIf.png # ######################### def sieve(n): if n < 2: return list() prime = [True for _ in range(n + 1)] p = 3 while p * p <= n: if prime[p]: for i in range(p * 2, n + 1, p): prime[i] = False p += 2 r = [2] for p in range(3, n + 1, 2): if prime[p]: r.append(p) return r def divs(n, start=1): divisors = [] for i in range(start, int(math.sqrt(n) + 1)): if n % i == 0: if n / i == i: divisors.append(i) else: divisors.extend([i, n // i]) return divisors def divn(n, primes): divs_number = 1 for i in primes: if n == 1: return divs_number t = 1 while n % i == 0: t += 1 n //= i divs_number *= t def flin(d, x, default=-1): left = right = -1 for i in range(len(d)): if d[i] == x: if left == -1: left = i right = i if left == -1: return (default, default) else: return (left, right) def ceil(n, k): return n // k + (n % k != 0) def ii(): return int(input()) def mi(): return map(int, input().split()) def li(): return list(map(int, input().split())) def lcm(a, b): return abs(a * b) // math.gcd(a, b) def prr(a, sep=' '): print(sep.join(map(str, a))) def dd(): return collections.defaultdict(int) def ddl(): return collections.defaultdict(list) # input = sys.stdin.readline for _ in range(ii()): n = ii() d = divs(n, 2) f = 1 if len(d): x = d[0] for y in divs(n // x, 2): z = n // (x * y) if x != y != z != x and z != 1: print('YES') print(x, y, z) f = 0 break if f: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#!/usr/bin/env python3 import math primes = [2] for n in range(3,math.ceil(math.sqrt(1e9)),2): is_prime = True sqrt_n = math.sqrt(n) for p in primes: if p > sqrt_n: break if n%p == 0: is_prime = False break if is_prime: primes.append(n) t = int(input()) for _ in range(t): n = int(input()) _n = n factors = {} for p in primes: while _n % p == 0: if p not in factors: factors[p] = 0 factors[p] += 1 _n /= p if _n != 1: factors[_n] = 1 f1 = None f2 = None if len(factors) == 1: [f] = list(factors) if factors[f] >= 6: f1 = f f2 = f*f elif len(factors) == 2: [_f1, _f2] = list(factors) if (factors[_f1] + factors[_f2]) >= 4: f1 = _f1 f2 = _f2 elif len(factors) >= 3: [_f1,_f2] = list(factors)[:2] f1 = _f1 f2 = _f2 if f1 != None and f2 != None: print("YES") print(f"{int(f1)} {int(f2)} {int(n/(f1*f2))}") 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
# -*- coding: utf-8 -*- """ Created on Wed Jan 22 19:40:08 2020 @author: DELL """ import math # A function to print all prime factors of # a given number n def primeFactors(n): li=[] # Print the number of two's that divide n while n % 2 == 0: li.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: li.append(i) n = n / i # Condition if n is a prime # number greater than 2 if n > 2: li.append(int(n)) return li t=int(input()) for i in range(t): n=int(input()) p = primeFactors(n) k=set(p) w=list(k) if len(w)==1: if p.count(w[0])>5: print("YES") a=p[0] b=p[1]*p[2] c=1 for i in range(3,len(p)): c=c*p[i] print(str(a)+" "+str(b)+" "+str(c)) else: print("NO") elif len(w)==2: if len(p)<=3: print("NO") else: if len(p)==5: print("YES") a=p[0] b=p[1]*p[2]*p[3] c=p[4] print(str(a)+" "+str(b)+" "+str(c)) else: print("YES") a=p[0] b=p[1]*p[2] c=1 for i in range(3,len(p)): c=c*p[i] print(str(a)+" "+str(b)+" "+str(c)) elif len(w)==0: print("NO") else: if len(p)==3: print("YES") a=p[0] b=p[1] c=p[2] print(str(a)+" "+str(b)+" "+str(c)) else: print("YES") a=p[0] b=p[1]*p[2] c=1 for i in range(3,len(p)): c=c*p[i] print(str(a)+" "+str(b)+" "+str(c))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n=int(input()) t=pow(n,0.5)+3 l=[] co=0 i=2 while i<t: if n%i==0: n=n//i l.append(i) else: i+=1 # print(l) if n!=1: l.append(n) flag="YES" t=len(l) if t>=3: a=l[-1] l.pop(-1) b=l[-1] l.pop(-1) if a==b: b=b*l[-1] l.pop(-1) c=1 for i in l: c=c*i if t>=3: if c>1 and a>1 and b>1 and b!=c and a!=b and a!=c: print("YES") print(a,b,c) else: print("NO") else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; public class Product_of_Three_Numbers { public static void main(String args[]) { Scanner ob=new Scanner(System.in); int t=ob.nextInt(); while(t-->0) { int n=ob.nextInt(); int a=0,b=0; for(int i=2;i*i<n;i++) { if(n%i==0) { n/=i; if(a==0) a=i; else{ b=i; break; } } } if(a!=0 && b!=0 && n>b) { System.out.println("YES"); System.out.println(a+" "+b+" "+n+" ");} else System.out.println("NO"); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for _ in range(t): n = int(input()) li = [] i = 2 while i*i<n: if n%i==0: li.append(i) n/=i if len(li)==2: break i+=1 if len(li)!=2 or n in li: print('NO') else: print("YES") print(li[0],li[1], int(n))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import factorial from collections import Counter from sys import stdin def RL(): return map(int, stdin.readline().rstrip().split() ) def comb(n, m): return factorial(n)/(factorial(m)*factorial(n-m)) if n>=m else 0 def perm(n, m): return factorial(n)//(factorial(n-m)) if n>=m else 0 def mdis(x1, y1, x2, y2): return abs(x1-x2) + abs(y1-y2) mod = 1000000007 from math import gcd # ------------------------------ from math import sqrt N = int(input()) for _ in range(N): n = int(input()) tag = False for i in range(2, int(sqrt(n))+1): if n%i==0: for j in range(2, int(sqrt(n//i))+1): if i!=j and (n//i)%j==0 and n//i//j!=j and n//i//j!=i and n//i//j!=1: print("YES") print(i, j, n//i//j) tag = True if tag: break if tag: break else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# Python program to print prime factors import math # a given number n def prime(n): a= []# Print the number of two's that divide n while n % 2 == 0: a.append(2) n = n / 2 # n must be odd at this point # so a skip of 2 ( i = i + 2) can be used for i in range(3,int(math.sqrt(n))+1,2): # while i divides n , print i ad divide n while n % i== 0: a.append(int(i)) n = n / i # Condition if n is a prime # number greater than 2 if n > 2: a.append(int(n)) return a # Driver Program to test above function t= int(input()) while(t>0): n = int(input()) a = prime(n) l = len(a) if l<3: print('NO') elif l==3 and len(set(a))==3: print('YES') for i in a: print(i,end=' ') print() else: i = 0 k = 1 temp = [] temp.append(a[i]) i+=1 if a[i]!=a[i-1]: temp.append(a[i]) i+=1 else: temp.append(a[i]*a[i+1]) i+=2 for j in range(i,l): k*=a[j] if k!=1 and k not in temp: temp.append(k) s= set(temp) if len(s)==3 and temp[0]*temp[1]*temp[2]==n: print('YES') for i in s: print(i,end=' ') print() else: print('NO') t-=1
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t = int(input()) for _ in range(t): n = int(input()) d = [] while n % 2 == 0: d.append(2) n //= 2 for i in range(3, (int(math.sqrt(n)) + 1), 2): while n % i == 0: d.append(i) n //= i if n > 2: d.append(n) if len(d) < 3: print('NO') elif len(d) == 3 and (d[0] == d[1] or d[1] == d[2]): print('NO') else: # print(d) a = d[0] if d[1] == d[0]: b = d[1] * d[2] c = math.prod(d[3:]) else: b = d[1] c = math.prod(d[2:]) if a == b or a == c or b == 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 as mt n = int(input()) i = 0 while i < n: case = int(input()) n1 = case a, b, c = 1, 1, 1 divisor = [] for p in range(2, mt.ceil(mt.sqrt(case + 1))): if len(divisor) == 2: divisor.append(int(n1 / (divisor[0] * divisor[1]))) break elif case % p == 0: divisor.append(p) case /= p try: a, b, c = tuple(divisor) except ValueError: a, b, c = 1, 1, 1 if a == 1 or b == 1 or c == 1 or a == c or a == b or b == c: ans = False else: ans = True if ans: print("YES") print(a, b, c) else: print("NO") 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
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin >> q; while (q--) { cin >> n; vector<int> res; for (int i = 2; res.size() < 2 && i * i < n; ++i) { if (n % i == 0) { res.push_back(i); n /= i; } } res.push_back(n); if (res.size() != 3) { cout << "NO" << endl; } else { cout << "YES" << endl; cout << res[0] << " " << res[1] << " " << res[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
def IsPrime(n): d = 2 while d * d <= n and n % d != 0: d += 1 return d * d > n t = int(input()) ans = [] for j in range(t): n = int(input()) divs = [] i = 2 while i*i <= n: if n % i == 0: x = n // i u = i + 1 while u*u <= x: if x % u == 0: if x//u == u: break ans.append(['YES', i, u, x//u]) u = x i = n u += 1 i +=1 if len(ans) == j: ans.append(['NO']) for i in range(len(ans)): if len(ans[i]) == 1: print(*ans[i]) else: print(ans[i][0]) print(*ans[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 java.io.*; import java.util.*; import java.lang.Math.*; public class CodeForces615C { public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.valueOf(br.readLine()); for (int i = 0;i<t ;i++ ){ Number n = new Number(Integer.valueOf(br.readLine())); System.out.println(n.tutorialSolution()); } } } class Number{ int input ; public Number(int input){ this.input = input; } public String tutorialSolution(){ int a = findSmallestFactor(2,input); if(a<=0){ return "NO"; } int b = findSmallestFactor(a+1, input/a); if(b<0){ return "NO"; } //System.out.println(a+" "+b+" "+input/(a*b)); StringBuilder sb = new StringBuilder(); if(input/(a*b)==1){ sb.append("NO"); } else{ if(a!=b && b!= input/(a*b) && a!=input/(a*b)){ sb.append("YES\n"); sb.append(a+" "+b+" "+input/(a*b)); }else { sb.append("NO"); } } return sb.toString(); } public int findSmallestFactor(int start, int input){//complexity root(n) same as primes int ret = -1; double a = (double)input; for (int i = start; i<=java.lang.Math.sqrt(a); i++) { //System.out.println(i+" "+ i*i); if(input%i==0){ ret= i; break; } } return ret; } public String findThreeFactors(){ int [] ret = new int[6]; int k = input; boolean noMoreFactors = false; Factors f = null; int i = 0; for ( i = 0;i<ret.length ;i++ ) { f = returnFactors(k); //System.out.println("k " + k + "("+f.a+" "+f.b +")"); ret[i] = f.a; if(f.b<0|| f.b == 1){ i++; noMoreFactors = true; break; } k = f.b; }//what happens when 1 is given String retString = null; Set<Integer> s = new HashSet<Integer>(); if(!noMoreFactors){ s.add(ret[0]); s.add(ret[1]* ret[2]); s.add(ret[3]* ret[4]* ret[5]*f.b); }else{ if(i<3){ retString = "NO"; } if(i==3){ s.add(ret[0]); s.add(ret[1]); s.add(ret[2]); } else if(i==4){ s.add(ret[0]); s.add(ret[1]* ret[2]); s.add(ret[3]); } else if(i==5){ s.add(ret[0]); s.add(ret[1]* ret[2]); s.add(ret[3]* ret[4]); }else if(i==6) { s.add(ret[0]); s.add(ret[1]* ret[2]); s.add(ret[3]* ret[4]* ret[5]); } } if(s.size()==3){ StringBuilder sb = new StringBuilder(); sb.append("YES\n"); Iterator iter = s.iterator(); while (iter.hasNext()) { sb.append(iter.next()); if(iter.hasNext()) { sb.append(" "); } } retString = sb.toString(); } else{ retString = "NO"; } return retString ; } public Factors returnFactors(int i){ if(i==1) return new Factors(-1) ; if(i==3) return new Factors(3) ; if(i==2) return new Factors(2) ; if(i%2==0){ Factors f = new Factors(i/2, 2); return f; } if(i%3 ==0){ Factors f = new Factors(i/3, 3); return f; } int j =5; while(j<= java.lang.Math.sqrt((double)i) ){// ignore ones where j * j = i if(i%j == 0){ Factors f = new Factors(i/j, j); return f; } else if(i%(j+2)==0){ Factors f = new Factors(i/(j+2), j+2); return f; } // System.out.println(j+" "+ (j+2)); j = j+6; } return new Factors(i); } } class Factors{ int a; int b; public Factors(int i,int j){ //make sure a<b and dont add 1 if(i==1){ a = j; b = -1; }else if(j==1){ a = i; b = -1; }else if(i<j){ a = i; b = j; }else{ a = j; b = i; } } public Factors(int i){ a = i; b = -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
import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = Integer.parseInt(sc.next()); for(int i = 0; i < t; i++){ int n = Integer.parseInt(sc.next()); List<Long> list = primeFactorization(n); if(list.size() < 3){ System.out.println("NO"); }else{ long a = list.get(0); long b = list.get(list.size()-1); long c = 1; for(int j = 1; j < list.size()-1; j++){ c *= list.get(j); } if(a == b || b == c || c == a){ if(list.size() < 6){ System.out.println("NO"); }else{ b = list.get(1) * list.get(2); c = 1; for(int j = 3; j < list.size(); j++){ c *= list.get(j); } System.out.println("YES"); System.out.println(a + " " + b + " " + c); } }else{ System.out.println("YES"); System.out.println(a + " " + b + " " + c); } } } } static List<Long> primeFactorization(long n){ List<Long> list = new ArrayList<>(); while(n%2 == 0){ n /= 2; list.add(2L); } double sqrt = Math.sqrt(n); for(long l = 3; l <= sqrt; l += 2){ while(n%l == 0){ n /= l; list.add(l); } } if(n > 1) list.add(n); return list; } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin, 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 <= math.sqrt(n): if n % f1 == 0: ans.append(f1) break f1 += 1 if len(ans) == 0: print("NO") continue m = n//f1 f2 = f1 + 1 while f2 <= math.sqrt(m): if m % f2 == 0: ans.append(f2) break f2 += 1 if len(ans) == 1: print("NO") continue f3 = n//(f1*f2) if f3 not in {f1, f2}: print("YES") print(*[f1, f2, f3]) 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
from math import ceil, sqrt n = int(input()) for i in range(n): num = int(input()) ans = [] for mult in range(2, ceil(sqrt(num))): #print('Try ', mult,' for ', num) if num < mult: break if num % mult == 0: ans.append(mult) num = num / mult if (len(ans) == 2) and (ans[0] != num) and (ans[1] != num) and (num != 1): ans.append(int(num)) break if len(ans) == 3: print('YES') print(' '.join([str(x) for x in ans])) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; import java.lang.*; import java.io.*; public class Codeforces { static FastReader sc=new FastReader(); static PrintWriter out=new PrintWriter(System.out); static long mod=1000000007; public static void main (String[] args) throws java.lang.Exception { // your code goes here // StringBuffer sb=new StringBuffer(); int t=I(); while(t-->0) { int n=I(); int x=checkPrime(n,2); if(x==-1)out.println("NO"); else{ int y=n/x; int p=checkPrime(x,2); if(p==-1){ int q=checkPrime(y,x+1); if(q==-1)out.println("NO"); else{ out.println("YES"); out.println(x+" "+q+" "+(y/q)); } }else{ out.println("YES"); out.println(p+" "+(x/p)+" "+y); } } } // out.print(sb.toString()); out.close(); } public static int checkPrime(int n,int p) { for(int i=p;i*i<=n;i++){ if(n%i==0 && n/i!=i){ return i; } } return -1; } public static void printArray(int a[]) { for(int i=0;i<a.length;i++){ out.print(a[i]+" "); } out.println(); } public static void printArray(ArrayList<Integer> arr) { for(int i=0;i<arr.size();i++){ out.print(arr.get(i)+" "); } out.println(); } public static void DFS(ArrayList<Integer> arr[],int s,boolean visited[]) { visited[s]=true; for(int i:arr[s]){ if(!visited[i]){ DFS(arr,i,visited); } } } public static int BS(long a[],long x,int ii,int jj) { // int n=a.length; int mid=0; int i=ii,j=jj; while(i<=j) { mid=(i+j)/2; if(a[mid]>x) j=mid-1; else if(a[mid]<=x) i=mid+1; } if(a[mid]>x && mid>ii) return mid-1; else return mid; } public static ArrayList<Integer> prime(int n) { ArrayList<Integer> arr=new ArrayList<>(); boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int i = 2; i <= n; i++) { if (prime[i] == true) arr.add(i); } return arr; } public static HashSet<Integer> primeSet(int n) { HashSet<Integer> arr=new HashSet<>(); boolean prime[] = new boolean[n + 1]; for (int i = 0; i <= n; i++) prime[i] = true; for (int p = 2; p * p <= n; p++) { if (prime[p] == true) { for (int i = p * p; i <= n; i += p) prime[i] = false; } } for (int i = 2; i <= n; i++) { if (prime[i] == true) arr.add(i); } return arr; } // Fenwick / BinaryIndexed Tree USE IT - FenwickTree ft1=new FenwickTree(n); public static class FenwickTree { long farr[]; int n; public FenwickTree(int c) { n=c+1; farr=new long[n]; } public void update_range(int l,int r,long p) { update(l,p); update(r+1,(-1)*p); } public void update(int x,long p) { for(;x<n;x+=x&(-x)) { farr[x]+=p; } } public long get(int x) { long ans=0; for(;x>0;x-=x&(-x)) { ans=ans+farr[x]; } return ans; } } //Disjoint Set Union public static class DSU { static int par[],rank[]; public DSU(int c) { par=new int[c+1]; rank=new int[c+1]; for(int i=0;i<=c;i++) { par[i]=i; rank[i]=0; } } public static int find(int a) { if(a==par[a]) return a; return par[a]=find(par[a]); } public static void union(int a,int b) { int a_rep=find(a),b_rep=find(b); if(a_rep==b_rep) return; if(rank[a_rep]<rank[b_rep]) par[a_rep]=b_rep; else if(rank[a_rep]>rank[b_rep]) par[b_rep]=a_rep; else { par[b_rep]=a_rep; rank[a_rep]++; } } } //SEGMENT TREE CODE // public static void segmentUpdate(int si,int ss,int se,int qs,int qe,long x) // { // if(ss>qe || se<qs)return; // if(qs<=ss && qe>=se) // { // seg[si][0]+=1L; // seg[si][1]+=x*x; // seg[si][2]+=2*x; // return; // } // int mid=(ss+se)/2; // segmentUpdate(2*si+1,ss,mid,qs,qe,x); // segmentUpdate(2*si+2,mid+1,se,qs,qe,x); // } // public static long segmentGet(int si,int ss,int se,int x,long f,long s,long t,long a[]) // { // if(ss==se && ss==x) // { // f+=seg[si][0]; // s+=seg[si][1]; // t+=seg[si][2]; // long ans=a[x]+(f*((long)x+1L)*((long)x+1L))+s+(t*((long)x+1L)); // return ans; // } // int mid=(ss+se)/2; // if(x>mid){ // return segmentGet(2*si+2,mid+1,se,x,f+seg[si][0],s+seg[si][1],t+seg[si][2],a); // }else{ // return segmentGet(2*si+1,ss,mid,x,f+seg[si][0],s+seg[si][1],t+seg[si][2],a); // } // } public static class pair { long a; long b; public pair(long val,long index) { a=val; b=index; } } public static class myComp implements Comparator<pair> { //sort in ascending order. public int compare(pair p1,pair p2) { if(p1.a==p2.a) return 0; else if(p1.a<p2.a) return -1; else return 1; } //sort in descending order. // public int compare(pair p1,pair p2) // { // if(p1.a==p2.a) // return 0; // else if(p1.a<p2.a) // return 1; // else // return -1; // } } public static class myComp1 implements Comparator<pair1> { //sort in ascending order. public int compare(pair1 p1,pair1 p2) { if(p1.a==p2.a) return 0; else if(p1.a<p2.a) return -1; else return 1; } //sort in descending order. // public int compare(pair p1,pair p2) // { // if(p1.a==p2.a) // return 0; // else if(p1.a<p2.a) // return 1; // else // return -1; // } } public static class pair1 { long a; long b; public pair1(long val,long index) { a=val; b=index; } } public static ArrayList<pair1> mergeIntervals(ArrayList<pair1> arr) { //****************use this in main function-Collections.sort(arr,new myComp1()); ArrayList<pair1> a1=new ArrayList<>(); if(arr.size()<=1) return arr; a1.add(arr.get(0)); int i=1,j=0; while(i<arr.size()) { if(a1.get(j).b<arr.get(i).a) { a1.add(arr.get(i)); i++; j++; } else if(a1.get(j).b>arr.get(i).a && a1.get(j).b>=arr.get(i).b) { i++; } else if(a1.get(j).b>=arr.get(i).a) { long a=a1.get(j).a; long b=arr.get(i).b; a1.remove(j); a1.add(new pair1(a,b)); i++; } } return a1; } public static boolean palindrome(String s,int n) { for(int i=0;i<=n/2;i++){ if(s.charAt(i)!=s.charAt(n-i-1)){ return false; } } return true; } public static long countDigit(long n) { long sum=0; while(n!=0) { sum++; n=n/10; } return sum; } public static long digitSum(long n) { long sum=0; while(n!=0) { sum=sum+n%10; n=n/10; } return sum; } public static long gcd(long a,long b) { if(b==0) return a; else return gcd(b,a%b); } public static int gcd(int a,int b) { if(b==0) return a; else return gcd(b,a%b); } public static long pwr(long m,long n) { long res=1; m=m%mod; if(m==0) return 0; while(n>0) { if((n&1)!=0) { res=(res*m)%mod; } n=n>>1; m=(m*m)%mod; } return res; } public static void sort(int[] A) { int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i) { int tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } public static void sort(long[] A) { int n = A.length; Random rnd = new Random(); for(int i=0; i<n; ++i) { long tmp = A[i]; int randomPos = i + rnd.nextInt(n-i); A[i] = A[randomPos]; A[randomPos] = tmp; } Arrays.sort(A); } public static int I(){return sc.I();} public static long L(){return sc.L();} public static String S(){return sc.S();} public static double D(){return sc.D();} } class FastReader { BufferedReader br; StringTokenizer st; public FastReader(){ br = new BufferedReader(new InputStreamReader(System.in)); } String next(){ while (st == null || !st.hasMoreElements()){ try { st = new StringTokenizer(br.readLine()); } catch (IOException e){ e.printStackTrace(); } } return st.nextToken(); } int I(){ return Integer.parseInt(next()); } long L(){ return Long.parseLong(next()); } double D(){ return Double.parseDouble(next()); } String S(){ 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
#!/usr/bin/env python # coding: utf-8 # In[7]: import math def divisor(n): for i in range(2,int(math.sqrt(n))+1): if n%i==0: k=n//i for j in range(2,int(math.sqrt(k))+1): if j!=i and k%j==0: t=k//j if t!=i and t!=j: return ["YES",i,j,t] return "NO" t=int(input()) for i in range(t): n=int(input()) if divisor(n)=="NO": print("NO") else: print(divisor(n)[0]) print(*divisor(n)[1:]) # In[ ]:
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.*; import java.util.*; import java.math.*; public class S{ static class Pair implements Comparable<Pair>{ int a; int b; public Pair(int x,int y){a=x;b=y;} public Pair(){} public int compareTo(Pair p1){ if(a == p1.a) return b - p1.b; return a - p1.a; } } static class TrieNode{ TrieNode[]child; int w; boolean term; TrieNode(){ child = new TrieNode[26]; } } public static int gcd(int a,int b) { if(a<b) return gcd(b,a); if(b==0) return a; return gcd(b,a%b); } //static long ans = 0; static long mod =(long)( 1e9 + 7); public static void main(String[] args) throws Exception { new Thread(null, null, "Anshum Gupta", 99999999) { public void run() { try { solve(); } catch(Exception e) { e.printStackTrace(); System.exit(1); } } }.start(); } static void insert(TrieNode head,String str){ int n = str.length(); TrieNode cur = head; for(int i=0;i<n;i++){ int ch = str.charAt(i)-'A'; if(cur.child[ch] == null) cur.child[ch]=new TrieNode(); cur = cur.child[ch]; } cur.term = true; } static boolean isRoot(TrieNode cur){ if(cur==root)return true; return false; } static int f(TrieNode head){ int ans = 0; for(int i=0;i<26;i++){ if(head.child[i]!=null){ ans += f(head.child[i]); } } if(head.term)ans++; if(ans >=2 && !isRoot(head)) ans-=2; return ans; } static boolean done(int[]arr){ for(int i=1;i<arr.length;i++){ if(arr[i-1] > arr[i] ) return false; } return true; } static TrieNode root; public static void solve() throws Exception { // solve the problem here MyScanner s = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out), true); int t = s.nextInt(); int tc = 0; while(tc++<t){ int n = s.nextInt(); int a=0,b=0,c=0; for(int i = 2;i*i <= n;i++){ if(n%i == 0){ a = i; break; } } if(a==0) { out.println("NO"); continue; } for(int i=a+1;i*i<=n;i++){ if(n%(i*a) == 0 ){ b = i; break; } } if(b==0) { out.println("NO"); continue; } c = n/(a*b); if(a == 0 || b==0 || c==0 || a==b || b==c || c==a) out.println("NO"); else { out.println("YES"); out.println(a+" "+b+" "+c); } } out.flush(); } //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } //-------------------------------------------------------- }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int q; cin >> q; for (int i = 0; i < q; ++i) { int n; cin >> n; set<int> used; for (int i = 2; i * i <= n; ++i) { if (n % i == 0 && !used.count(i)) { used.insert(i); n /= i; break; } } for (int i = 2; i * i <= n; ++i) { if (n % i == 0 && !used.count(i)) { used.insert(i); n /= i; break; } } if (int(used.size()) < 2 || used.count(n) || n == 1) { cout << "NO" << endl; } else { cout << "YES" << endl; used.insert(n); for (auto it : used) cout << it << " "; cout << endl; } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def pm(n): arr = [] while(n%2==0): arr.append(2) n//=2 for i in range(3,int(pow(n,0.5))+1,2): while n%i==0: arr.append(i) n//=i if n>2: arr.append(n) return arr tc = int(input()) for ii in range(tc): n = int(input()) arr = pm(n) a = arr[0] b = 1 c = 1 index = 0 for i in range(1,len(arr)): b*=arr[i] if b!=a: index = i break for j in range(index+1,len(arr)): c*=arr[j] if a!=b and b!=c and a!=c and a!=1 and b!=1 and c!=1: print("YES") print(a,b,c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n=int(input()) l=[];i=2 while len(l)<2 and i*i<n: if n%i==0:l.append(i);n//=i; i+=1 if len(l)==2 and n not in l:print("YES");print(*l,n); else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math from functools import reduce t = int(input()) for _ in range(t): n = int(input()) m = n sqrt_n = int(math.sqrt(n)) res = [] for i in range(2, sqrt_n): if n == 1: break while n > 1 and n % i == 0: res.append(i) n //= i if n > 1: res.append(n) if len(res) < 3: print('NO') elif len(res) == 3: if len(set(res)) < 3: print('NO') else: print('YES') print(res[0], res[1], res[2]) elif len(res) == 4: if len(set(res)) == 1: print('NO') else: print('YES') print(res[0], res[1] * res[2], res[3]) elif len(res) == 5: if len(set(res)) == 1: print('NO') else: print('YES') print(res[0], res[1] * res[2] * res[3], res[4]) else: print('YES') print(res[0], res[1] * res[2], reduce(lambda x, y: x * y, res[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
# from sys import stdin, stdout # print = lambda x: stdout.write(x) # input = stdin.readline from math import sqrt #Ref: Geeksforgeeks def primeFactors(n): arr = [] # Print the number of two's that divide n while n % 2 == 0: arr.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(sqrt(n))+1,2): # while i divides n , print i ad divide n while n % i== 0: arr.append(i) n = n // i # Condition if n is a prime # number greater than 2 if n > 2: arr.append(n) return arr def solve(a,n,res): for i in res: b = n//i if a!=b: return a,b return False for t in range(int(input())): n = int(input()) res = primeFactors(n) if len(res) <= 2: print('NO') continue resset = list(set(res)) ans = [] if len(resset) >= 2: ans.append(resset[0]) ans.append(resset[1]) ans.append(n//(ans[-1]*ans[-2])) ans = set(ans) else: ans.append(resset[0]) ans.append(resset[0]**2) ans.append(n//(ans[-1]*ans[-2])) ans = set(ans) ans = list(ans) if len(ans) == 3 and min(ans)>=2: print('YES') for i in ans: print(i, end = ' ') print() else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt def factor(n): s = int(sqrt(n)) rLst = [1, n] for i in xrange(2, s+1): if n%i==0: rLst.append(i) if n//i != i: rLst.append(n//i) rLst = list(set(rLst)) rLst.sort() return rLst from sys import stdin raw_input = lambda: stdin.readline().rstrip() input = lambda: int(raw_input()) I=lambda: map(int, raw_input().split()) t = input() for _ in xrange(t): n = input() facts = factor(n) q1 = facts[1] facts1 = factor(n//q1) q2 = -1 for x in facts1: if x>1 and x != q1: q2 = x break if q2==-1: print 'NO' continue q3 = n//(q1*q2) if q3==1 or q3==q1 or q3==q2: print 'NO' else: print 'YES' print q1, q2, q3 # if len(facts)<7: # print 'NO' # else: # print 'YES' # q1 = facts[1] # q2 = facts[2] # print q1, q2, n//(q1*q2)
PYTHON