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
for i in range(int(input())): n = int(input()) j = 2 a = [] while j*j < n: if n % j == 0: n //= j a.append(j) if len(a) == 2: a.append(n) break j += 1 if len(a) < 3: print('NO') elif a[1] == a[2]: print('NO') else: print('YES') print(a[0],a[1],a[2])
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys import time import math start_time = time.time() input = sys.stdin.readline t = int(input()) for _ in range( t): n = int(input()) sqrtn = math.ceil(n**0.5) a,b,c=1,1,1 mod = 2 while(True): if n == 1 or mod > sqrtn: break if n % mod == 0 : if a == 1 : a*= mod else: b*= mod n//= mod if(a>1 and b > 1 and a!= b): c = n break else: if mod == 2 : mod = 3 else: mod += 2 # print(a,b,c) if(a==1 or b==1 or c==1 or a==b or b==c or a==c): print("NO") else: print("YES") print(a,b,c) # print("--- %s seconds ---" % (time.time() - start_time))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
kl = int(input()) for l in range(kl): pr = 0 n = int(input()) t = int(n ** 0.5) a = [] for i in range(2, t + 1): if n % i == 0: a += [i] n = n // i if len(a) == 2: pr = 1 break if pr and a[1] < n: print('YES') print(a[0], a[1], n) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.ArrayList; import java.util.Scanner; public class Main { public static void main(String[] args){ int t; Scanner sc = new Scanner(System.in); t = sc.nextInt(); for(int i=0;i<t;i++) { int n = sc.nextInt(); ArrayList<Integer> ans = new ArrayList<>(); int count=0; int cuberoot = (int)Math.pow(n, 0.33)+1; int j=2; int temp = n; while(j*j<n) { if(temp%j==0) { temp = temp/j; ans.add(j); count++; if(count==2) break; } j++; } if(count!=2) { System.out.println("NO"); continue; } else { if(temp!=ans.get(1) && temp!=ans.get(0) && temp>2) { System.out.println("YES"); System.out.println(ans.get(0)+" "+ans.get(1)+" "+n/(ans.get(0)*ans.get(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
t = int(input()) for _ in range(t): n = int(input()) on = n a = [] for i in range(2, 1+int(n**0.5)): if not n%i: a.append(i) n//=i if len(a) == 2: break if len(a) < 2 or on//(a[0]*a[1]) == 1 or on//(a[0]*a[1]) in a: print("NO") else: print("YES") a.append(on//(a[0]*a[1])) print(*a)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; inline int mulmd(long long a, long long b) { long long ret = (a * b) % 1000000007; return (int)ret; } inline int power(long long x, long long y, int m) { long long res = 1; x = x % m; while (y > 0) { if (y & 1) { res = mulmd(res, x); } y = y >> 1; x = mulmd(x, x); } return (int)res; } inline int submd(long long a, long long b) { long long ret = (a - b); if (ret < 0) ret += 1000000007; return (int)ret; } inline int addmd(long long a, long long b) { long long ret = (a + b) % 1000000007; return (int)ret; } inline int invPow(long long a) { return power(a, 1000000007 - 2, 1000000007); } inline int divmd(long long a, long long b) { long long ret = mulmd(a, invPow(b)); return (int)ret; } const int N = 1e5 + 5; int arr[N]; void solve() { int n; cin >> n; vector<int> ans; int r = n; for (int i = 2; i <= 100000; i++) { if (n % i == 0) { n /= i; ans.push_back(i); break; } } if (ans.size() < 1) { cout << "NO\n"; return; } for (int i = 2; i <= 100000; i++) { if (n % i == 0 && i != ans[0]) { n /= i; ans.push_back(i); break; } } if (ans.size() < 2) { cout << "NO\n"; return; } int prod = ans[0] * ans[1]; int fin = r / prod; if (fin != ans[0] && fin != ans[1] && fin >= 2) { cout << "YES\n"; cout << ans[0] << " " << ans[1] << " " << fin << "\n"; } else { cout << "NO\n"; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { solve(); } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; public class C { public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); int a = 1, b = 1, c = 1; for (int i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) { a = i; break; } } int x = n / a; for (int i = 2; i <= Math.sqrt(x); i++) { if (x % i == 0 && i != a) { b = i; break; } } c = x / b; if (c != a && c != b && a >= 2 && b >= 2 && c >= 2) { System.out.println("YES"); if (a > b) { int temp = a; a = b; b = temp; } if (b > c) { int temp = b; b = c; c = temp; } System.out.println(a + " " + b + " " + c); } else { System.out.println("NO"); } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n = int(input()) f = 0 i = 2 li = [] while i*i<=n: if n%i == 0: f+=1 li.append(i) n = n//i i+=1 if f == 2: break if f==2 and n!=1 and n not in li: print("YES") print(*li, n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin , stdout from os import path if path.exists("input.txt"): stdin = open("input.txt",'r') for _ in range(int(stdin.readline())): x = int(stdin.readline()) i = 2 q = [] while len(q)< 2 and i*i < x: if x%i == 0 : q.append(i) x //= i i+=1 if len(q) == 2 and x not in q : print("YES") print(*q,x) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def is_prime(n): isPrime=1 for i in range(2,math.floor(math.sqrt(n))+1): if n%i==0: isPrime=1 break if isPrime==1: return False return True for _ in range(int(input())): n=int(input()) isPrime = is_prime(n) if isPrime: print("NO") else: a,b,c = 0,0,0 l=[] k=n for i in range(2,math.floor(math.sqrt(n))+1): if n%i==0: if (n//i==i): l.append(i) else: l.append(i) l.append(n//i) l.append(k) a=min(l) if (a!=0): l=[] n=k//a for i in range(2,math.floor(math.sqrt(n))+1): if n%i==0: if (n//i==i): if i>a: l.append(i) else: if i>a: l.append(i) if n//i>a: l.append(n//i) l.append(k//a) b=min(l) if (b!=0): l=[] n=k//(a*b) for i in range(2,math.floor(math.sqrt(n)+1)): if n%i==0: if (n//i==i): if i>b: l.append(i) else: if i>b: l.append(i) if n//i>b: l.append(n//i) l.append(k//(a*b)) c=max(l) if (len(set([a,b,c]))<3) or a<2 or b<2 or c<2: print("NO") else: print("YES") print(a,b,c)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.ArrayList; import java.util.Scanner; public class ewtry { public static void main(String[] args) { Scanner sc=new Scanner (System.in); int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); ArrayList <Integer> l1=new ArrayList<Integer>(); for(int i=2;i<=Math.sqrt(n);i++) { if(n%i==0) { n=n/i; l1.add(i); if(l1.size()==2&&n>1&&n!=i) { l1.add(n); break; } } } if(l1.size()==3) { System.out.println("YES"); String s=""; for(int i=0;i<3;i++) { s=s+l1.get(i)+" "; } System.out.println(s); } 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 ceil def factorize(n): ans = [] sq = ceil(n ** 0.5) while n > 1 and len(ans) < 2: prime = True for i in range(2, sq + 1): if n % i == 0: if i not in ans: ans.append(i) n //= i prime = False break if prime: if n != 1 and n not in ans: ans.append(n) n = 1 else: break if n != 1 and n not in ans: ans.append(n) return ans #print(factorize(2 * 2 * 2 * 2 * 2 * 69 * 228 * 1337)) t = int(input()) for i in range(t): n = int(input()) #print(factorize(n)) if len(factorize(n)) == 3: print('YES') print(*factorize(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
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, a, b, c, co = 0, te = 0; cin >> n; int x[3]; for (int j = 2; j <= sqrt(n); j++) { if (n % j == 0) { x[co++] = j; n /= j; te++; if (te == 2) break; } } if (te == 2 && n != 1 && n != x[0] && n != x[1]) { cout << "YES" << endl; cout << x[0] << " " << x[1] << " " << n << endl; } else cout << "NO" << endl; } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int t; cin >> t; while (t--) { long long int n, x, i, y; cin >> n; x = n; vector<pair<long long int, int>> v; for (i = 2; i * i <= x; i++) { y = 0; if (x % i == 0) { while (x % i == 0) { x /= i; y++; } v.push_back({i, y}); } } if (x > 1) v.push_back({x, 1}); if (v.size() >= 3) { x = v[0].first; y = v[1].first; cout << "YES\n" << x << " " << y << " " << n / (x * y) << "\n"; } else if (v.size() == 2) { x = v[0].first; y = v[1].first; long long int c0 = v[0].second, c1 = v[1].second; if (c0 >= 3) { cout << "YES\n" << x << " " << x * x << " " << n / (x * x * x) << "\n"; } else if (c1 >= 3) { x = y; cout << "YES\n" << x << " " << x * x << " " << n / (x * x * x) << "\n"; } else if (c0 >= 2 && c1 >= 2) { cout << "YES\n" << x << " " << y << " " << x * y << "\n"; } else cout << "NO\n"; } else if (v.size() == 1) { x = v[0].first; y = v[0].second; if (y >= 6) { cout << "YES\n" << x << " " << x * x << " " << n / (x * x * x) << "\n"; } else cout << "NO\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
import math for _ in range(int(input())): n=int(input()) r=math.ceil(math.sqrt(n))+1 ou=[] for i in range(2,r): if len(ou)==2: break else: if n%i==0: n=n//i ou.append(i) if n>1 and len(ou)==2 and n not in ou: print('YES') print(n,*ou) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys sys.setrecursionlimit(10**9) IA =lambda: map(int,input().split()) ans=[0,0,0,0] def solve(n): num=int(0) i=int(2) tmp=1 m=n while i*i<=m: if n%i==0: n=n//i tmp*=i if tmp not in ans: num+=1 ans[num]=tmp tmp=1 if num>=3: ans[num]*=n return 1 i+=1 if n>1: if tmp*n not in ans: num+=1 ans[num]=n*tmp if num>=3: return 1 else:return -1 T=int(input()) for t in range(0,T): ans=[0,0,0,0] n=int(input()) if solve(n)==1: print("YES") for i in range(1,4): print(ans[i],end=" ") print() else:print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cout.tie(NULL); cout.tie(NULL); ; long long tt; cin >> tt; while (tt--) { long long n; cin >> n; long long a = -1; for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { a = i; n /= a; break; } } if (a != -1) { long long l = 0; for (long long i = 2; i * i <= n; i++) { if (n % i == 0 && i != a && a != n / i && i != n / i) { cout << "YES\n"; cout << a << " " << n / i << " " << i << "\n"; l = 1; break; } } if (l == 0) cout << "NO\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
t = int(input()) for i in range(0,t): n = int(input()) a = 1 j = 2 while((j*j) <= n): if(n % j == 0): a = j break j = j + 1 if(a == 1): print("NO") else: b = 1 n = n / a j = a + 1 while((j*j) <= n): if(n % j == 0): b = j break j = j + 1 n = int(n / b) if(b == 1): print("NO") elif n <= b: print("NO") else: print("YES") print(str(a) + " " + str(b) + " " + str(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 def getFactors(n): factors = [] while n%2==0: factors.append(2) n = n//2 k=3 while k <= math.sqrt(n): if n%k==0: n= n//k factors.append(k) else: k+=2 if n>1: factors.append(n) return factors t = int(input()) numbers = [ int(input()) for _ in range(t) ] for n in numbers: factors = getFactors(n) distinct = set() i=0 num = 1 while i < len(factors): num *= factors[i] if len(distinct)==2: pass elif num not in distinct: distinct.add(num) num=1 else: pass i+=1 if num!=1: distinct.add(num) if len(distinct)==3: print('YES') print(" ".join(map(str,sorted(list(distinct))))) 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()) i = 2 k = 1 x = 1 y = 1 z = 1 flag = 0 while i*i<=n : if n%i==0 : if k==1 : x = i n = n//i k = 0 elif n//i != i and x!=i and x!= n//i: y = i z = n//i break else : flag = 1 break i += 1 if flag == 0 and x>1 and y>1 and z>1: 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
def solve(n): a, b, c = None, None, None for i in range(2, int(n**0.5) + 1): if n%i == 0: a = i n = n/i break else: return None for i in range(a+1, int(n**0.5) + 1): if n%i == 0: b = i c = int(n/i) break else: return None if b != c and a != c: return (a, b, c) else: return None t = int(input()) for _ in range(t): n = int(input()) res = solve(n) if res: print('YES') print (*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 t = int(input()) f = "" for _ in range(t): n = int(input()) m = n r = 0 x = [] for i in range(2, int(sqrt(n))+1): if i>m or r==2: break else: if m%i==0: x.append(i) m = m//i r += 1 if r==2 and (n//(x[0]*x[1])>x[1]): f += "YES\n" f += str(x[0]) + " " +str(x[1]) + " " + str(n//(x[0]*x[1]))+"\n" else: f += "NO\n" print(f)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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 d[1000001] = {0}; int sum[1000001] = {0}; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a = -1, b = -1, c; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0 && a == -1) { a = i; } else if (a != -1 && (n / a) % i == 0) { b = i; break; } } c = n / (a * b); if (c == 1 || b == -1 || c == b || c == a) a = -1; if (a == -1) cout << "NO\n"; else cout << "YES" << "\n" << 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
from functools import reduce import io import os import sys from atexit import register import random import math import itertools ##################################### Flags ##################################### # DEBUG = True DEBUG = False STRESSTEST = False # STRESSTEST = True ##################################### IO ##################################### if not DEBUG: input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline sys.stdout = io.BytesIO() register(lambda: os.write(1, sys.stdout.getvalue())) tokens = [] tokens_next = 0 def nextStr(): global tokens, tokens_next while tokens_next >= len(tokens): tokens = input().split() tokens_next = 0 tokens_next += 1 if type(tokens[tokens_next - 1]) == str: return tokens[tokens_next - 1] return tokens[tokens_next - 1].decode() def nextInt(): return int(nextStr()) def nextIntArr(n): return [nextInt() for i in range(n)] def print(*argv, end='\n'): for arg in argv: sys.stdout.write((str(arg) + ' ').encode()) sys.stdout.write(end.encode()) ##################################### Helper Methods ##################################### def genTestCase(): return random.randint(1, 100) def bruteforce(n): for c in itertools.combinations(range(2, n), 3): if reduce(lambda x, y: x * y, c) == n: return list(c) return None def check(mySoln, bruteforceSoln): if bruteforceSoln is None or mySoln == None: return mySoln == bruteforceSoln n = reduce(lambda x, y: x * y, bruteforceSoln) return mySoln[0] * mySoln[1] * mySoln[2] == n and len(set(mySoln)) == 3 def doStressTest(): while True: curTest = genTestCase() mySoln = solve(curTest) bruteforceSoln = bruteforce(curTest) if not check(mySoln, bruteforceSoln): print('### Found case ###') print(curTest) print(f'{mySoln} should have been: {bruteforceSoln}') return def genPrimes(limit): limit = int(limit) isPrime = [0, 0] + [1] * (limit + 10) for i in range(len(isPrime)): if isPrime[i]: yield i for j in range(i * i, len(isPrime), i): isPrime[j] = 0 primes = [i for i in genPrimes(10**5)] def factorize(n): res = [] ps = iter(primes) while n > 1: p = next(ps, -1) if p == -1: res.append(n) break while n % p == 0: n = n // p res.append(p) return res def solve(n): factors = factorize(n) if len(factors) > 2: p1 = factors[0] p2 = next((i for i in factors if i != p1), -1) if p2 == -1: p2 = factors[1] * factors[2] res = [p1, p2, n // p1 // p2] if reduce(lambda x, y: x * y, res) == n and len( set(res)) == 3 and 1 not in res: return res return None ##################################### Driver ##################################### if __name__ == "__main__": if not DEBUG and STRESSTEST: raise Exception('Wrong flags!') if STRESSTEST: doStressTest() else: ### Read input here t = nextInt() for _ in range(t): n = nextInt() res = solve(n) if res is None: print('NO') else: print('YES') print(' '.join(map(str, res))) sys.stdout.flush()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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.math.*; import java.util.*; // @author : Dinosparton [ SHIVAM BHUVA ] public class test { static class Pair{ int x; int y; Pair(int x,int y){ this.x = x; this.y = y; } } static class Compare { void compare(Pair arr[], int n) { // Comparator to sort the pair according to second element Arrays.sort(arr, new Comparator<Pair>() { @Override public int compare(Pair p1, Pair p2) { return p1.x - p2.x; } }); // for (int i = 0; i < n; i++) { // System.out.print(arr[i].x + " " + arr[i].y + " "); // } // System.out.println(); } } public static void main(String args[]) { Scanner sc = new Scanner(System.in); StringBuffer res = new StringBuffer(); int tc= sc.nextInt(); while(tc-->0) { long n = sc.nextLong(); int a = 0; int b = 0; for(int i = 2;i*i<=n;i++) { if(n%i==0) { a = i; n = n/i; break; } } for(int i=a+1;i*i<=n;i++) { if(n%i==0) { b = i; n = n/i; break; } } if(a!=n && b!=n && n!=1 && a!=0 && b!=1 && b!=0) res.append("YES").append("\n").append(a+" "+b+" "+n).append("\n"); else res.append("NO").append("\n"); } System.out.println(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
# ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------- fast io -------------------- import math import bisect primes=[2] for j in range(3,10**5): indy=min(bisect.bisect_left(primes,math.ceil(math.sqrt(j))),len(primes)-1) broke=False for s in range(indy+1): if j%primes[s]==0: broke=True break if broke==False: primes.append(j) minny=len(primes) testcases=int(input()) for j in range(testcases): #ok we will find its prime divisors n=int(input()) indy=min(bisect.bisect_left(primes,math.ceil(math.sqrt(n))),minny-1) facs=[] for s in range(indy+1): if n%primes[s]==0: facs.append(primes[s]) exi=True if len(facs)>=3: a,b,c=facs[0],facs[1],n//(facs[0]*facs[1]) elif len(facs)==2: a,b,c=facs[0],facs[1],n//(facs[0]*facs[1]) if c==0 or c==1 or c==a or c==b: exi=False elif len(facs)==1: a,b,c=facs[0],facs[0]**2,n//(facs[0]**3) if c==0 or c==1 or c==a or c==b: exi=False elif len(facs)==0: a,b,c=0,0,0 exi=False if a*b*c==n and exi==True: print("YES") print(str(a)+" "+str(b)+" "+str(c)) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys I=sys.stdin.readline ans="" for _ in range(int(I())): n=int(input()) fac=[] for i in range(2,int(n**.5)): if n%i==0: fac.append((i,n//i)) break if len(fac)!=0: x=fac[0][1] for i in range(2,int(x**.5)+1): if x%i==0 and i!=fac[0][0]: if i!=x//i: ans+="YES\n" ans+="{} {} {}\n".format(fac[0][0],i,x//i) break else: ans+="NO\n" else: ans+="NO\n" print(ans)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int main() { ios_base::sync_with_stdio(false), cin.tie(0); ; int t; cin >> t; while (t--) { int n; cin >> n; int curr = n; vector<int> ans; bool ok = true; while (ans.size() < 2 && ok) { int currMax = (int)sqrt(curr) + 1; int i = 2; if (ans.size()) { i = ans[ans.size() - 1] + 1; } while (i < currMax) { if (curr % i == 0) { ans.push_back(i); curr /= i; break; } i++; } if (i >= currMax) { ok = false; } } if (ans.size() == 2 && ans[1] != n / ans[0] / ans[1]) { cout << "YES\n" << ans[0] << " " << ans[1] << " " << n / ans[0] / ans[1] << "\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
for i in range(int(input())): n=int(input());c=0;x=[];y=n for i in range(2,int(n**0.5)+1): if y%i==0: c+=1 y=y//i x.append(i) if c>=2: break print('YES' if c>=2 and y not in x else 'NO') if c>=2 and y not in x: print(*x[:2],y )
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t=input() for p in xrange(t): n=input() if n<20: print "NO" continue i=2 k=n fac=[] d=0 while i*i<=n and d==0: while k%i==0 and k!=0: # print k k=k/i fac.append(i) if len(fac)==3: d=1 break i+=1 # print k if k!=0 and k!=1: fac.append(k) # print fac if len(fac)<3: print 'NO' continue m=1 if fac[0]!=fac[1]: for i in xrange(2, len(fac)): m*=fac[i] if m>1 and m!=fac[1] and m!=fac[0]: print 'YES' print fac[0], fac[1], m else: print "NO" else: for i in xrange(3, len(fac)): m*=fac[i] if fac[1]*fac[2]!=m and m!=fac[0] and m!=1: print 'YES' print fac[0], fac[1]*fac[2], m 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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; public class ProductofThreeNumbers { static boolean[] isPrime; static ArrayList<Integer> primes; static void sieve(int N) { isPrime = new boolean[N + 1]; Arrays.fill(isPrime, true); isPrime[0] = false; isPrime[1] = false; for (int i = 2; i * i <= N; i++) { if (isPrime[i]) { for (int j = i * i; j <= N; j += i) { isPrime[j] = false; } } } for (int i = 2; i < isPrime.length; i++) { if (isPrime[i]) primes.add(i); } } static ArrayList<Integer> primeFactors(int N){ //O(sqrt(N)/log(sqrt(N)) int idx = 0; int p = primes.get(idx++); ArrayList<Integer> factors = new ArrayList<Integer>(); while(p*p <= N) { while(N % p == 0) { factors.add(p); N /= p; } p = primes.get(idx++); } if(N != 1) factors.add(N); return factors; } public static void main(String[] args) throws NumberFormatException, IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out); int t = Integer.parseInt(br.readLine()); isPrime=new boolean[100000]; primes=new ArrayList<Integer>(); sieve(100000); //int counter=; while(t-->0) { int n=Integer.parseInt(br.readLine()); //out.println(n); ArrayList<Integer> a=primeFactors(n); HashSet<Long> h=new HashSet(); //System.out.println(a); if(a.size()>3) {long number=1; h.add(a.get(0)*1l); if(a.get(1)==a.get(0)) { h.add(a.get(1)*a.get(2)*1l); for(int i=3;i<a.size();i++) number*=a.get(i); } else { h.add(a.get(1)*1l); for(int i=2;i<a.size();i++) number*=a.get(i); } h.add(number); if(h.size()==3) { out.println("YES"); for(long l:h) { out.print(l+" "); } out.println(); } else { out.println("NO"); } } else if(a.size()==3) { h.add(a.get(0)*1l);h.add(a.get(1)*1l);h.add(a.get(2)*1l); if(h.size()==3) { out.println("YES"); for(long l:h) { out.print(l+" "); } out.println(); } else { out.println("NO"); } } else { out.println("NO"); } } out.flush(); } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for _ in range(t): used = [] n = int(input()) for i in range(2,round(n/2)): if i*i>=n: break if n%i==0 and (i not in used): used.append(i) n=n/i break for i in range(2,round(n/2)): if i*i>=n: break if n%i==0 and (i not in used): used.append(i) n=n/i break if len(used) < 2 or (n in used) or n==1: print("NO") else: print("YES") used.append(int(n)) for item in used: print(item, 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
#include <bits/stdc++.h> #pragma GCC optimize("O2") using namespace std; const int INF = int(2e9) + 99; void test_case() { long long n; cin >> n; set<long long> st; for (long long i = 2; i * i <= n; i++) { if (n % i == 0 && st.find(i) == st.end()) { st.insert(i); n /= i; break; } } for (long long i = 2; i * i <= n; i++) { if (n % i == 0 && st.find(i) == st.end()) { st.insert(i); n /= i; break; } } if (st.size() < 2 || n == 1 || st.find(n) != st.end()) { cout << "NO\n"; return; } cout << "YES\n"; st.insert(n); for (auto x : st) cout << x << ' '; cout << '\n'; return; } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) test_case(); 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
# maa chudaaye duniya import math def pf(n): cat = [] while n%2 == 0: cat.append(2) n //= 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n%i == 0: cat.append(i) n //= i if n > 2: cat.append(n) return cat for _ in range(int(input())): n = int(input()) factors = pf(n) factors.sort() ss = list(set(factors)) # print(factors) if len(ss) >= 3 and len(factors) >= 3: a = ss[0] b = ss[1] d = a*b c = n // d print('YES') print(a, b, c) elif len(ss) == 1 and len(factors) >= 6: a = ss[0] b = pow(a, 2) c = n // pow(a, 3) print('YES') print(a, b, c) elif len(ss) == 2 and len(factors) >= 4: a = ss[0] b = ss[1] c = n // (a*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
t = int(input()) while t!=0: n = int(input()) p = int(pow(n,.5)) a,b,c = -1,-1,-1 for i in range(2,p+1): if n%i==0: a= i n = n//i break q = int(pow(n,.5)) for i in range(2,q+1): if i!=a and n%i==0 and i!=n//i: b=i c=n//i break if a!=-1 and b!=-1 and c!=-1: print("YES") print(a,b,c) else: print("NO") t-=1
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n=int(input()) s=set() for i in range(2,int(pow(n,0.5))+1): if(n%i==0): s.add(i) s.add(n//i) l1=list(s) n1=len(l1) if(n1<3): print("NO") else: flag=0 for i in range(n1-2): if(flag==1): break for j in range(i+1,n1-1): if(flag==1): break for k in range(j+1,n1): v=l1[i]*l1[j]*l1[k] if(n==v): flag=1 print("YES") print(l1[i],l1[j],l1[k]) break if(flag==0): print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
//package CodeForces.RoadMap.D2_B; import java.util.Arrays; import java.util.Scanner; /** * @author Syed Ali. * @createdAt 16/04/2021, Friday, 01:40 */ public class ProductOfThreeNumsSolution { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t=sc.nextInt(); int a[]=new int[3]; while(t-->0) { Arrays.fill(a,0); int cnt=0; int n=sc.nextInt(); for(int i=2;i<=Math.sqrt(n);i++) { if(n%i==0) { a[cnt++]=i; n/=i; if(cnt==2) {a[cnt]=n;break;} } } if(cnt==2&&a[2]>a[1]) { System.out.println("YES\n"+a[0]+" "+a[1]+" "+a[2]); } else System.out.println("NO"); } sc.close(); } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int t, n; int main() { cin >> t; while (t--) { cin >> n; int a[3] = {}, j = 0; for (int i = 2; i * i < n && j < 2; i++) { if (n % i == 0) a[j++] = i, n /= i; } if (j != 2) cout << "NO\n"; else { cout << "YES\n"; cout << a[0] << " " << a[1] << " " << n << endl; } } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for i in range(t): n = int(input()) a=0 b=0 c=0 s=0 ss=0 nn=int(n**0.5) for i in range(2,nn): if n%i==0: a=i ss=50 break if ss==0: print('NO') continue ss=0 for i in range(a+1,nn): if (n/a)%i==0: b=i ss=50 break if ss==0: print('NO') continue if n/(a*b)>b: print('YES') print(a,b,int(n/(a*b))) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def solveOne(n): ret = [] d = 2 while d * d < n and len(ret) < 3: if n % d == 0: ret.append(d) n //= d dd = 2 while dd * dd < n: if n % dd == 0 and dd not in ret and n // dd not in ret: ret.extend((dd, n // dd)) break dd += 1 d += 1 return 'YES\n%s' % ' '.join(map(str, ret)) if len(ret) == 3 else 'NO' for _ in range(int(input())): print(solveOne(int(input())))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin, stdout from collections import defaultdict import math rl = lambda: stdin.readline() rll = lambda: stdin.readline().split() def main(): cases = rll() for line in stdin: n = int(line) ans = [] f1 = 2 while f1**2 <= n: if n % f1 == 0: ans.append(f1) break f1 += 1 if len(ans) == 0: stdout.write("NO\n") continue m = n//f1 f2 = f1 + 1 while f2**2 <= m: if m % f2 == 0: ans.append(f2) break f2 += 1 if len(ans) == 1: stdout.write("NO\n") continue f3 = n//(f1*f2) if f3 not in {f1, f2}: stdout.write("YES\n") stdout.write(" ".join((str(x) for x in [f1, f2, f3]))) stdout.write("\n") else: stdout.write("NO\n") stdout.close() if __name__ == "__main__": main()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for _ in range(t): n = int(input()) a, b, c = 0, 0, 0 i = 1 while i < n and i < 10 ** 4: i += 1 if n % i == 0: n = n // i if a == 0: a = i elif b == 0: b = i c = n break if c > 2 and b != c and c != a: 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; long long gcd(long long a, long long b); long long nCr(long long n, long long r); long long pow(long long b, long long n); void read(long long a[], long long n); void solve() { long long n; cin >> n; vector<long long> v; for (long long i = 2; i * i <= n; i++) { if (n % i == 0) { v.push_back(i); n /= i; if (v.size() == 2) { v.push_back(n); break; } } } if (v.size() != 3) { cout << "NO" << endl; return; } if (v[0] != v[1] && v[0] != v[1] && v[1] != v[2]) { cout << "YES" << endl; cout << v[0] << " " << v[1] << " " << v[2] << endl; } else { cout << "NO" << endl; } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t--) { solve(); } } long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); } long long nCr(long long n, long long r) { if (r > n) return 0; if (r * 2 > n) r = n - r; if (r == 0) return 1; long long ans = n; for (long long i = 2; i <= r; i++) { ans *= (n - i + 1); ans /= i; } return ans; } long long pow(long long b, long long n) { long long p = b, ans = 1; while (n) { if (n & 1) { ans *= p; } p *= p; n = n >> 1; } return ans; } void read(long long a[], long long n) { for (long long i = 0; i < n; i++) { cin >> a[i]; } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.*; import java.util.*; //import javafx.util.*; import java.math.*; //import java.lang.*; public class Main { //static int n; // static ArrayList<Integer> adj[]; // static boolean vis[]; // static long ans[]; static int arr[]; static long mod=1000000007; static final long oo=(long)1e18; // static int n; public static void main(String[] args) throws IOException { // Scanner sc=new Scanner(System.in); PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))); br = new BufferedReader(new InputStreamReader(System.in)); int test=nextInt(); // int test=1; outer: while(test--!=0){ long n=nextLong(); long ans[]=new long[3]; // int j=0; for(long i=2;i<=Math.sqrt(n);i++){ if(n%i==0){ long b=n/i; // if(isPrime(b)) // pw.println("NO"); // else{ for(long j=i+1;j<=Math.sqrt(b);j++){ if(b%j==0&&j!=b/j){ pw.println("YES"); pw.println(i+" "+j+" "+b/j); continue outer; } } pw.println("NO"); continue outer; //} } } pw.println("NO"); // pw.println(ans[0]+" "+ans[1]+" "+ans[2]); // if(j==3){ // pw.println("YES"); // } // else{ // } } pw.close(); } static long ncr(long n,long r){ if(r==0) return 1; long val=ncr(n-1,r-1); val=(n*val)%mod; val=(val*modInverse(r,mod))%mod; return val; } static int find(ArrayList<Integer> a,int i){ if(a.size()==0||i<0)return 0; ArrayList<Integer> l=new ArrayList<Integer>(); ArrayList<Integer> r=new ArrayList<Integer>(); for(int v:a){ if((v&(1<<i))!=0)l.add(v); else r.add(v); } if(l.size()==0)return find(r,i-1); if(r.size()==0)return find(l,i-1); return Math.min(find(l,i-1),find(r,i-1))+(1<<i); } public static BufferedReader br; public static StringTokenizer st; public static String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { throw new RuntimeException(e); } } return st.nextToken(); } public static Integer nextInt() { return Integer.parseInt(next()); } public static Long nextLong() { return Long.parseLong(next()); } public static Double nextDouble() { return Double.parseDouble(next()); } // static class Pair{ // int x;int y; // Pair(int x,int y,int z){ // this.x=x; // this.y=y; // // this.z=z; // // this.z=z; // // this.i=i; // } // } // static class sorting implements Comparator<Pair>{ // public int compare(Pair a,Pair b){ // //return (a.y)-(b.y); // if(a.y==b.y){ // return -1*(a.z-b.z); // } // return (a.y-b.y); // } // } public static int[] na(int n)throws IOException{ int[] a = new int[n]; for(int i = 0;i < n;i++)a[i] = nextInt(); return a; } static class query implements Comparable<query>{ int l,r,idx,block; static int len; query(int l,int r,int i){ this.l=l; this.r=r; this.idx=i; this.block=l/len; } public int compareTo(query a){ return block==a.block?r-a.r:block-a.block; } } static class Pair implements Comparable<Pair>{ int x;int y; Pair(int x,int y){ this.x=x; this.y=y; //this.z=z; } public int compareTo(Pair p){ return (x-p.x); //return (x-a.x)>0?1:-1; } } // static class sorting implements Comparator<Pair>{ // public int compare(Pair a1,Pair a2){ // if(o1.a==o2.a) // return (o1.b>o2.b)?1:-1; // else if(o1.a>o2.a) // return 1; // else // return -1; // } // } static boolean isPrime(int n) { if (n <= 1) return false; if (n <= 3) return true; if (n % 2 == 0 || n % 3 == 0) return false; for (int i = 5; i * i <= n; i = i + 6) if (n % i == 0 || n % (i + 2) == 0) return false; return true; } static long gcd(long a, long b) { if (b == 0) return a; return gcd(b, a % b); } // To compute x^y under modulo m static long power(long x, long y, long m){ if (y == 0) return 1; long p = power(x, y / 2, m) % m; p = (p * p) % m; if (y % 2 == 0) return p; else return (x * p) % m; } static long fast_pow(long base,long n,long M){ if(n==0) return 1; if(n==1) return base; long halfn=fast_pow(base,n/2,M); if(n%2==0) return ( halfn * halfn ) % M; else return ( ( ( halfn * halfn ) % M ) * base ) % M; } static long modInverse(long n,long M){ return fast_pow(n,M-2,M); } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# cook your dish here import math t=int(input()) for _ in range(t): count=0 a=[] n=int(input()) for i in range(2,int(math.sqrt(n))): if (n%i==0 and count<2): n=int(n/i) a.append(i) count+=1 if n not in a and n!=1: a.append(n) count+=1 if count == 3: print('YES') for i in a: 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
def prime_decomposition(n): i = 2 table = [] while i * i <= n: while n % i == 0: n /= i table.append(i) i += 1 if n > 1: table.append(n) return table t = int(input()) for _ in range(t): n = int(input()) ansl = [] pl = prime_decomposition(n) k = 1 for p in pl: k *= p if k not in ansl and len(ansl) < 2: ansl.append(int(k)) k = 1 else: if k in ansl or k == 1: print("NO") continue ansl.append(int(k)) if len(ansl) < 3: print("NO") else: print("YES") print(str(ansl[0])+ " " + str(ansl[1]) + " " + str(ansl[2]))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t=int(input()) for i in range(t): n=int(input()) s=set() for j in range(2,int(math.sqrt(n))+1): if n%j==0 and not list(s).count(j): s.add(j) n/=j break for k in range(2,int(math.sqrt(n))+1): if n%k==0 and not list(s).count(k): s.add(k) n/=k break if len(s)<2 or list(s).count(n) or n==1: print("NO") else: print("YES") s.add(int(n)) print(*list(s),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
for i in range(0,int(input())): n=int(input()) f1=0 f2=0 root=int(n**0.5) for i in range(2,root+1): if n%i==0: k=i f1=1 break if f1==1: n=int(n/k) root=int(n**0.5) k1=k for i in range(2,root+1): if n%i==0 and i*i!=n and i!=k1: k=i f2=1 break if f2==1: print("YES") print(k1,k,int(n/k)) 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
def smallestDivisor(start,n): # if divisible by 2 if (n % 2 == 0 and start == 2): return 2; # iterate from 3 to sqrt(n) i = start; while(i * i <= n): if (n % i == 0): return i; i += 1; return n; t = int(input()) for i in range(t): n = int(input()) a = smallestDivisor(2, n) b = smallestDivisor(a+1, n/a) c = 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
import math def factors(n): l = [] for i in range(2, int(math.sqrt(n))+1): if n%i == 0: l.append(i) l.append(n//i) return l for _ in range(int(input())): n = int(input()) l = factors(n) nn = len(l) flag = 0 for i in range(nn): for j in range(nn): for k in range(nn): if l[i] * l[j] * l[k] == n: if not (i == j or j == k or k == i): print("YES") print(l[i], l[j], l[k]) flag = 1 break if flag == 1: break if flag == 1: break if flag == 0: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys import math t = int(sys.stdin.readline()) for _ in range(t): n = int(sys.stdin.readline()) a = None for i in range(2, int(math.sqrt(n))): if n % i == 0: a = i break if a == None: print("NO") continue b = None for j in range(2, int(math.sqrt(n))): if (n//i) % j == 0 and j != a: b = j break if b == None: print("NO") continue if n // (a*b) != a and n // (a*b) != b and n // (a*b) != 1: c = n // (a*b) else: print("NO") continue print("YES") print(a, b, c)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def printDivisors(n) : i = 1 l=[] while i <= math.sqrt(n): if (n % i == 0) : if (n / i == i) : l.append(i) else : l.append(i) l.append(n//i) i = i + 1 return l t=int(input()) for _ in range(t): n=int(input()) a=printDivisors(n) a.sort() #print(a) z=-1 d={} d[a[0]]=1 l=[] c=0 for i in range(1,len(a)): for j in range(i+1,len(a)): if n%(a[i]*a[j])==0: if (n//(a[i]*a[j])) in d and (a[i]>=2 and a[j]>=2 and (n//(a[i]*a[j]))>=2): print("YES") z=0 l.append(a[i]) l.append(a[j]) l.append((n//(a[i]*a[j]))) l.sort() print(*l) if z==0: c=1 break if c==1: break d[a[i]]=1 if z==-1: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys queries = int(sys.stdin.readline()) def numberToFactors(number,fromTop=False): factor1 = number factor2 = 2 if fromTop: while factor2<=factor1**0.5: factor2+=1 while factor2>2: if factor1%factor2==0: if factor1//factor2!=factor2: return [factor1//factor2,factor2] factor2-=1 else: factor2 = 2 while factor2<=factor1**0.5: if factor1%factor2==0: if factor1//factor2!=factor2: return [factor1//factor2,factor2] factor2+=1 return [factor1] for query in range(queries): number = int(sys.stdin.readline()) factors = numberToFactors(number) if len(factors)==2: factorsLeft = numberToFactors(factors[0],True) factorsRight = numberToFactors(factors[1],True) next = True if len(factorsLeft)==2: if factorsLeft[0]!=factors[1] and factorsLeft[1]!=factors[1]: del factors[0] factors = factorsLeft+factors next = False if len(factorsRight)==2 and next: if factorsRight[0]!=factors[0] and factorsRight[1]!=factors[0]: del factors[1] factors = factors+factorsRight if len(factors) == 3: print('YES') print(" ".join(map(str,factors))) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) while t > 0: res = [] n = int(input()) root = int(n**.5) while root > 1: if n % root == 0: rem = n/root rem_root = int(rem**.5) if rem == rem_root**2: root -= 1 continue else: while rem_root > 1: if rem % rem_root == 0: if rem_root == root or (rem/rem_root) == root: rem_root -= 1 continue else: res = [root, int(rem_root), int(rem/rem_root)] print(f'YES\n{root} {int(rem_root)} {int(rem/rem_root)}') break rem_root -= 1 if len(res) == 3: break root -= 1 t -= 1 if len(res) != 3: 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; vector<pair<long long, long long>> arr; vector<pair<long long, long long>> arr2; vector<long long> dels; signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); long long q; cin >> q; while (q--) { long long n; cin >> n; long long v = -1; for (long long i = 2; i * i < n; i++) { if (n % i == 0) { for (long long j = 2; j * j <= i; j++) { if (i % j == 0 && i / j != 1 && i / j != n / i && n / i != j && j != i / j) { cout << "YES\n" << i / j << ' ' << n / i << ' ' << j << endl; goto r; } } for (long long j = 2; j * j <= n / i; j++) { if ((n / i) % j == 0 && (n / i) / j != 1 && (n / i) / j != i && i != j && j != (n / i) / j) { cout << "YES\n" << (n / i) / j << ' ' << i << ' ' << j << endl; goto r; } } } } cout << "NO\n"; r:; } 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())): num=int(input()) c=2 p=[] while len(p)<2 and c*c<=num: if num%c == 0: num=num//c p.append(c) c+=1 if len(p)==2 and num not in p: print("YES") print(*p,num) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.awt.Desktop; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.URI; import java.net.URISyntaxException; import java.sql.Array; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.PriorityQueue; import java.util.Queue; import java.util.Scanner; import java.util.Set; import java.util.Stack; import java.util.StringTokenizer; import java.util.TreeSet; import java.util.Vector; public class codechef3 { static class comp implements Comparator<Integer> { @Override public int compare(Integer o1, Integer o2) { if(Math.abs(o1)>Math.abs(o2)) return -1; else return 1; } } //======================================================= //sorting Pair static class comp1 implements Comparator<Pair<Integer,Integer>> { @Override public int compare(Pair<Integer, Integer> o1, Pair<Integer, Integer> o2) { if(o1.k>o2.k) return 1; else return -1; } } //======================================================= //Creating Pair class //---------------------------------------------------------------------- static class Pair<Integer,Intetger> { int k=0; int v=0; public Pair(int a,int b) { k=a; v=b; } } //-------------------------------------------------------------------------- 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; } } //gcd of two number public static int gcd(int a, int b) { if (b == 0) return a; return gcd(b, a % b); } //-------------------------------------------------------------------------------------------- //lcm of two number static int x; public static int lcm(int a, int b) { return (a / gcd(a, b)) * b; } //------------------------------------------------------------------------------------------- public static void main(String[] args) { FastReader s=new FastReader(); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); int x=1; int y=1; for(int i=2;i*i<=n;i++) { if(n%i==0) { x=i; break; } } for(int i=3;i*i<=n;i++) { if(n%(x*i)==0&&x!=i&&x!=1) {y=i; break;} } int flag=0; //System.out.println(x+" "+y); if(n/(x*y)!=x&&n/(x*y)!=y&&x!=1&&y!=1) { System.out.println("YES"); System.out.println(x+" "+y+" "+n/(x*y)); }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 primfacs(n): i = 2 primfac = [] while i * i <= n: while n % i == 0: primfac.append(i) n = n / i i = i + 1 if n > 1: primfac.append(n) return primfac def mul(arr): p = 1 if not len(arr): return 0 for i in arr: p = p * i return p t = int(input()) for _ in range(t): n = int(input()) dels = primfacs(n) result = [dels[0]] tmp = [] for i in range(1, len(dels)): tmp.append(dels[i]) p = mul(tmp) if not p or p in result: continue else: if len(result) < 2: result.append(p) tmp = [] else: continue p = mul(tmp) if not p or p in result: print("NO") else: result.append(p) print("YES") print(' '.join(str(int(i)) for i in result))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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 t = int(input()) for _ in range(t): n = int(input()) divisors = Counter() for p in range(2, int(math.sqrt(n))+1): while n % p == 0: divisors[p] += 1 n //= p if n > 1: divisors[n] += 1 ans = [1, 1, 1, 1] i = 1 for k, v in divisors.items(): for j in range(v): ans[i] *= k if all(ans[i] != ans[j] for j in range(i)) and i < 3: i += 1 if len(set(ans)) == 4: print('YES') print(*ans[1:]) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; public class pre372 { static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } public static void main(String args[]) { FastReader obj = new FastReader(); int tc = obj.nextInt(); while(tc--!=0) { int n = obj.nextInt(); boolean flag = true; ArrayList<Integer> arr = new ArrayList<>(); for(int i=2;i<=Math.sqrt(n);i++) { if(n%i==0 && !arr.contains(i)) { n /=i; arr.add(i); break; } } for(int i=2;i<=Math.sqrt(n);i++) { if(n%i==0 && !arr.contains(i)) { n /=i; arr.add(i); break; } } if(arr.size()<2 || arr.contains(n))System.out.println("NO"); else { System.out.println("YES"); for(int i=0;i<2;i++) System.out.print(arr.get(i)+" "); System.out.print(n); System.out.println(); } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def ld(a, last): found = False for div in range(last,int(math.sqrt(a))+1): if a % div == 0: found = True return div if not found: return False def do(int): x = ld(int,2) if x: y = ld(int//x, x+1) if y: z = int//(x*y) if x != y and x != z and y != z: print("Yes") print(x,y,z) else: print("No") else: print("No") else: print("No") t = int(input()) a = [] for inp in range(0,t): inp = int(input()) a.append(inp) for element in a: do(element)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for _ in range (int(input())): n = int(input()) l = [] i = 2 while i < math.sqrt(n) and len(l) < 2: if (n % i == 0): l.append(i) n = n // i i = i + 1 if len(l) == 2 and n > l[1]: print("YES") print(*l, n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin, stdout fin = lambda: stdin.readline() fout = lambda *args: stdout.write(' '.join(str(i) for i in args) + '\n') def f(n, s=2): a, b = -1, -1 for i in range(s, 22361): if n % i == 0: if a == -1: a = i n //= i elif i < n // i: return a, i, n // i return -1 for _ in range(int(fin())): n = int(fin()) a = f(n) if a == -1: fout('NO') else: fout('YES') fout(a[0], a[1], a[2])
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n = int(input()) fac = [] rem = 1 if n % 2 == 0: n /= 2 fac.append(2) tot = 1 tot *= 2 added = 2 x = 1 while n > 1 and n % 2 == 0: x *= 2 n /= 2 tot *= 2 if fac[-1] < x: fac.append(x) # app = True added *= x x = 1 if len(fac) >= 3: rem *= n n = 1 break rem *= tot / added i = 3 while n > 1: if n % i == 0: n /= i fac.append(i) tot = 1 tot *= i added = i x = 1 while n > 1 and n % i == 0: x *= i n /= i tot *= i if fac[-1] < x: fac.append(x) # app = True added *= x x = 1 if len(fac) >= 3: break rem *= tot / added if len(fac) >= 3: rem *= n n = 1 break if i * i >= n: if n > 1 and n not in fac: fac.append(n) else: rem *= n n = 1 break i += 2 # print(fac, rem) if len(fac) >= 3: a = fac[0] b = fac[1] c = fac[2] for x in fac[3:]: c *= x c *= rem print("YES") print(int(a), int(b), int(c)) elif len(fac) >= 2 and rem > 1 and rem not in fac: # print() a = fac[0] b = fac[1] c = rem print("YES") print(int(a), int(b), int(c)) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t=int(input()) for q in range(t): n=int(input()) lists=[] i=2 while len(lists)<2 and i*i<n: if n%i==0: lists.append(i) n//=i i+=1 if len(lists)==2 and n not in lists: print('YES') print(*lists,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
#include <bits/stdc++.h> using namespace std; template <typename T> std::ostream &operator<<(std::ostream &out, vector<T> &v) { for (typename vector<T>::size_type i = 0; i < v.size(); ++i) out << v[i] << " "; out << "\n"; return out; } template <typename T> std::ostream &operator<<(std::ostream &out, vector<pair<T, T> > &v) { for (size_t i = 0; i < v.size(); ++i) out << "(" << v[i].first << ", " << v[i].second << ") "; out << "\n"; return out; } template <typename T> std::ostream &operator<<(std::ostream &out, vector<vector<T> > &v) { for (size_t i = 0; i < v.size(); ++i) { for (size_t j = 0; j < v[i].size(); ++j) { out << v[i][j] << " "; } out << "\n"; } return out; } int main() { std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; int a = 1; for (int i = 2; i * i <= n; ++i) { if (n % i == 0) { a = i; break; } } if (a == 1) { cout << "NO\n"; continue; } int b = 1; for (int i = a + 1; i * i <= n / a; ++i) { if ((n / a) % i == 0) { b = i; break; } } if (b == 1) { cout << "NO\n"; continue; } int c = n / (a * b); if (c && c != 1 && c != a && c != b) { 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
t = int(input()) for _ in range(t): n = int(input()) arr = [1] * 3 i = 0 p = 2 while n > 1: if n % p != 0: p += 1 if p >= int(n**0.5) + 1: break continue arr[i] *= p n //= p if i > 0 and arr[1] == arr[0]: continue i += 1 if i == 2: break if i < 2 or n == 1 or n == arr[0] or n == arr[1]: print('NO') else: print('YES') print(f'{arr[0]} {arr[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,sys from collections import Counter, defaultdict, deque from sys import stdin, stdout input = stdin.readline lili=lambda:list(map(int,sys.stdin.readlines())) li = lambda:list(map(int,input().split())) #for deque append(),pop(),appendleft(),popleft(),count() I=lambda:int(input()) S=lambda:input().strip() mod = 1000000007 # A Better (than Naive) Solution to find all divisiors import math # method to print the divisors def printDivisors(n) : a=[] i = 1 while i <= math.sqrt(n): if (n % i == 0) : # If divisors are equal, print only one if (n / i == i) : a.append(i) else : # Otherwise print both a.append(i) a.append(n//i) i = i + 1 return (a) for i in range(I()): n=I() a=printDivisors(n) d=Counter(a) for i in a: f=0 if(i==1 or i==n): continue p=n//i #print(p) j=1 while(j<=math.sqrt(p)): if(p%j==0 and j!=1 and j in d and (p//j) in d and j!=i and i!=(p//j) and j!=(p//j) and j!=p): print("YES") print(i,j,p//j) f=1 break j+=1 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 functools import reduce def factors(n): l = [] for i in range(2,int(n**0.5)+1): if n%i==0: l.append(i) l.append(n//i) return l for _ in range(int(input())): n = int(input()) l = factors(n) flag = False flag1 = False flag2 = False for i in range(len(l)): a = l[i] b = n//a if a!=b: flag = True break if flag: # print(a,b,'****') p = factors(b) l1 = p for i in range(len(l1)): c = l1[i] d = b//c if c!=d and d!=a and c!=a: flag1 = True # print(a,c,d,'%%%%%%%%%%%5') break if flag1: print('YES') print(a,c,d) else: p = factors(a) # p.remove(1) # s.remove(a) l1 = list(p) for i in range(len(l1)): c = l1[i] d = a // c if d!=c and b!=d and c!=b: flag2 = True break if flag2: print('YES') print(c,d,b) else: print('NO') else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.*; public class PrimeFactorization { private static List<Integer> primes = new ArrayList(); // Prepoulates the primes array with all prime numbers uptil N. private static void prepopulatePrimes(int N) { BitSet isPrime = new BitSet(); isPrime.set( 0, false); isPrime.set( 1, false ); isPrime.set( 2, N, true ); for (int i=2; i*i<N; i++ ) { if (isPrime.get( i )) { for( int j=i*i; j<N; j+=i ) { isPrime.clear( j ); } } } for (int i=0; i<N; i++) { if (isPrime.get(i)) { // System.out.println(i); primes.add(i); } } // System.out.println(count); } // Uses the prepopulated primes array to factorize N. public static List<Long> primeFactors(long N) { List<Long> factors = new ArrayList<>(); if (N==0) { factors.add(0L); return factors; } if (N==1) { factors.add(1L); return factors; } for (long prime : primes) { while( N%prime == 0 ) { factors.add(prime); N = N/prime; } } if (N!=1) { factors.add(N); } for (long x : factors) { // System.out.print(x + " "); } // System.out.println(); return factors; } public static void main( String[] args ) throws Exception { int MAX = 100000 + 1; prepopulatePrimes(MAX); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int T = Integer.parseInt(br.readLine()); for (int t=0; t<T; t++) { long X = Long.parseLong(br.readLine()); List<Long> factors = primeFactors(X); if (factors.size() <= 2) { System.out.println("NO"); } else { long a = factors.get(0); long b_part = 1; int index = 1; boolean fail = false; while ((b_part == 1) || (b_part == a)) { if (index >= factors.size()) { fail = true; break; } b_part = b_part * factors.get(index); index++; } long c_part = 1; while (true) { if (index >= factors.size()) { break; } c_part = c_part * factors.get(index); index++; } if (fail || (c_part == a) || (c_part == b_part) || (c_part == 1)) { System.out.println("NO"); } else { System.out.println("YES"); System.out.println(a + " " + b_part + " " + c_part); } } } } }
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; using ll = long long int; void solve() { int n; cin >> n; if (n < 24) { cout << "NO\n"; return; } set<int> div; for (int i = 2; i * i <= n; ++i) { if (n % i == 0 and !div.count(i)) { div.insert(i); n /= i; break; } } for (int i = 2; i * i <= n; ++i) { if (n % i == 0 and !div.count(i)) { div.insert(i); n /= i; break; } } if (int(div.size()) < 2 || div.count(n)) { cout << "NO" << endl; } else { cout << "YES" << endl; div.insert(n); for (auto it : div) cout << it << " "; cout << endl; } } int main() { ios_base::sync_with_stdio(false); int t; cin >> t; while (t--) { solve(); } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long mod = 1e9 + 7; const long long N = 2e5; signed main() { ios_base::sync_with_stdio(false); cin.tie(0); long long t; cin >> t; ; while (t--) { long long n; cin >> n; ; long long cpy = n; map<long long, long long> mp; long long sqr = sqrt(n + 1); for (long long i = (2); i <= (sqr); i++) { while (n % i == 0) { n /= i; mp[i]++; } } if (n > 1) mp[n]++; if (mp.size() >= 3) { cout << "YES\n"; long long x = (*mp.begin()).first, y = (*(++mp.begin())).first; cout << x << " " << y << " " << cpy / (x * y) << '\n'; } else if (mp.size() == 1) { long long x = (*mp.begin()).first, y = (*mp.begin()).second; if (y < 6) cout << "NO\n"; else { cout << "YES\n"; cout << x << " " << x * x << " " << cpy / (x * x * x) << '\n'; } } else { long long x = (*mp.begin()).first, y = (*(++mp.begin())).first, z = cpy / (x * y); if (z == x || z == y || z == 1) cout << "NO\n"; else { cout << "YES\n"; cout << x << " " << y << " " << z << '\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
t = int(input()) def prime_decomposition(n): table = [] for i in range(2, int(n ** 0.5) + 1): while n % i == 0: table += [i] n //= i if n == 1: break if n != 1: table += [n] return table for i in range(t): n = int(input()) s = prime_decomposition(n) s.sort() flg = 0 if len(s) < 3: print ("NO") continue #print (s) #if len(set(s)) == 3: # print ("YES") # print (" ".join(map(str,list(s)))) # continue for j in range(1,len(s)): for k in range(j+1,len(s)): z = s[0] x = 1 y = 1 for a in s[j:k]: x *= a for b in s[k:]: y *= b if x != y and y != z and x != z: print ("YES") print (z,x,y) flg = 1 break if flg == 1: break if flg == 0: print ("NO") #print (s)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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()) factors = [] for factor in range (2, int(math.sqrt(n))): if n <= factor: break if n % factor == 0: if n // factor <= factor: break factors.append(factor) n = n // factor if len(factors) == 2: break if len(factors) == 2: factors.append(n) print('YES') print(' '.join(map(str, factors))) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t=int(input()) while(t): l=set() tr=0 n=int(input()) ce=n if n>=12: i=2 while(n>0 and tr<3 ): if tr<2 and i*i>ce: break if tr==2: l.add(int(n)) tr=tr+1 break elif n%i==0: l.add(i) tr=tr+1 n=n/i elif tr==2: l.add(int(n)) tr=tr+1 break i=i+1 if tr==3 and len(l)==3: print("YES") l=list(l) l.sort() for i in range (3): print(l[i],end=" ") print() else: print("NO") t=t-1
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Scanner; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; Scanner in = new Scanner(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskC solver = new TaskC(); solver.solve(1, in, out); out.close(); } static class TaskC { public void solve(int testNumber, Scanner in, PrintWriter out) { int q = in.nextInt(); while (q > 0) { int n = in.nextInt(); int a = -1; int b = -1; int c = -1; boolean flag = false; for (int i = 2; i <= Math.sqrt(n); i++) { int temp = n; if (temp % i == 0) { a = i; temp /= i; boolean f = false; for (int j = i + 1; j <= Math.sqrt(temp); j++) { if (temp % j == 0 && temp / j != j) { b = j; c = (n / b) / a; flag = true; f = true; break; } } if (f) break; } } if (flag) { out.println("YES"); out.println(a + " " + b + " " + c); } else { out.println("NO"); } q--; } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n=int(input()) l=[] i=2 while i**2<=n and len(l)<2: if n%i==0: l.append(i) n//=i i+=1 if len(l)<2 or n==1 or l.count(n): print("NO") else: print("YES") l.append(n) print(*l)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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 s(a,b): i = b+1 c = int(a**0.5) while 1: if a%i==0: return i else: if i<c: i+=1 else: return 1 for _ in range(int(input())): n = int(input()) a = s(n,1) #print(a) if a==1 or a==n: print('NO') else: a1 = n//a a2 = s(a1,a) if a2==1 or a2==a1: print('NO') else: a3 = a1//a2 b = sorted([a,a2,a3]) if len(set(b))==3: print('YES') print(b[0],b[1],b[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
// package Div3_615; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.HashMap; public class ProblemC { public static void main(String[] args)throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int test=Integer.parseInt(br.readLine()); int seive[]=new int[100001]; ArrayList<Integer> primes=new ArrayList<>(); for(int i=2;i<=100000;i++){ if(seive[i]==0){ primes.add(i); for(int j=2*i;j<=100000;j+=i){ seive[j]=1; } } } StringBuilder print=new StringBuilder(); // System.out.println(primes.size()); while(test--!=0){ int n=Integer.parseInt(br.readLine()); HashMap<Integer,Integer> power=new HashMap<>(); int temp=n; for(int i=0;i<primes.size();i++){ int prime=primes.get(i); int count=0; while(temp%prime==0){ count++; temp/=prime; } if(count!=0){ power.put(prime,count); } if(temp==1){ break; } } if(temp!=1){ power.put(temp,1); } // System.out.println(power.toString()); if(power.size()==1){ for(int k:power.keySet()){ if(power.get(k)<6){ print.append("NO\n"); } else{ print.append("YES\n"); int a=(int)Math.pow(k,1); int b=(int)Math.pow(k,2); int c=(int)Math.pow(k,power.get(k)-3); print.append(a+" "+b+" "+c+"\n"); } } } else if(power.size()==2){ int pow1=0,pow2=0; int prime1=0,prime2=0; for(int k:power.keySet()){ if(pow1==0){ pow1=power.get(k); prime1=k; continue; } else{ pow2=power.get(k); prime2=k; } } if(pow1>=3||pow2>=3){ print.append("YES\n"); if(pow1>=3){ int a=(int)Math.pow(prime1,1); int b=(int)Math.pow(prime1,pow1-1); int c=(int)Math.pow(prime2,pow2); print.append(a+" "+b+" "+c+"\n"); } else{ int a=(int)Math.pow(prime2,1); int b=(int)Math.pow(prime2,pow2-1); int c=(int)Math.pow(prime1,pow1); print.append(a+" "+b+" "+c+"\n"); } } else if(pow1==2&&pow2==2){ print.append("YES\n"); int a=(int)Math.pow(prime1,1); int b=(int)Math.pow(prime2,1); int c=a*b; print.append(a+" "+b+" "+c+"\n"); } else{ print.append("NO\n"); } } else{ int a=0,b=0,c=1; for(int k:power.keySet()){ if(a==0){ a=(int)Math.pow(k,power.get(k)); continue; } if(b==0){ b=(int)Math.pow(k,power.get(k)); continue; } int t=(int)Math.pow(k,power.get(k)); c*=t; } print.append("YES\n"); print.append(a+" "+b+" "+c+"\n"); } } System.out.println(print.toString()); } }
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 SieveOfEratosthenes(n): data=[] prime = [True for i in range(n + 1)] p = 2 while (p * p <= n): if (prime[p] == True): for i in range(p * 2, n + 1, p): prime[i] = False p += 1 prime[0]= False prime[1]= False for p in range(n + 1): if prime[p]: data.append(p) return data # print(len(SieveOfEratosthenes(10**6))) if __name__=="__main__": l = SieveOfEratosthenes(10**6) for t in range(int(input())): data=[] n = int(input()) d=n for i in l : if i*i>n: break if n%i==0: while n%i==0: data.append(i) n = n/i if n>1: data.append(n) a,b,c=data[0],0,0 if len(data)<=2: print("NO") else: b = data[1] if a==data[1]: b = data[1]*data[2] c = d//(a*b) if c==1 or c==b or c==a: 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
/* package whatever; // don't place package name! */ import java.util.*; import java.lang.*; import java.io.*; /* Name of the class has to be "Main" only if the class is public. */ public class Ideone { public static void main (String[] args) { // your code goes here Scanner s=new Scanner(System.in); int t=s.nextInt(); while(t-->0) { int n=s.nextInt(); int jo=0; for(int i=2;i<=Math.sqrt(n);i++) { if(n%i==0) { int r=n/i; for(int j=2;j<=Math.sqrt(r);j++) { if(r%j==0&&j!=i&&r/j!=i&&j!=r/j) { System.out.println("YES"); System.out.println(i+" "+j+" "+r/j); jo=1; break; } } if(jo==1) break; } } if(jo==0) System.out.println("NO"); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in) ; PrintWriter out = new PrintWriter(System.out) ; int t = sc.nextInt() ; while(t-->0) { int [] factors = new int [32] ; int id = 0 ; int n = sc.nextInt() ; for(int i = 2 ; 1l * i * i <= n ; i++) while(n % i == 0) { n /= i ; factors[id++] = i ; } if(n > 1) factors[id++] = n; id = 0 ; int a = factors[id++] ; int b = factors[id++] ; if(a == b) b *= factors[id++] ; int c = factors[id++] ; if(c == 0 || b == 0 || a == 0) out.println("NO"); else { while(id < 32 && factors[id] != 0) c *= factors[id++]; if(a != b && a != c && b != c) out.printf("YES \n%d %d %d\n" , a , b , c); else out.println("NO"); } } out.flush(); out.close(); } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from collections import Counter def primes(n): primfac = [] d = 2 while d*d <= n: while (n % d) == 0: primfac.append(d) n //= d d += 1 if n > 1: primfac.append(n) return primfac for _ in range(int(input())): n = int(input()) a = primes(n) if(len(a) < 3): print("NO") else: c = Counter(a) y = list(c.keys()) if(len(c) >= 3): print("YES") x = 1 for i in a[2:]: x *= i print(y[0], y[1], n//(y[0]*y[1])) else: # print(c, list(c.keys())[0]) if(len(c) == 1): if(c[y[0]] > 5): print("YES") print(a[0], a[0]*a[1], n//(a[0]*a[0]*a[0])) else: print("NO") else: if(c[y[0]] + c[y[1]] >= 4): print("YES") print(y[0], y[1], n//(y[0]* y[1])) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys input = sys.stdin.readline from collections import * def factorize(n): fct = [] for i in range(2, int(n**0.5)+1): c = 0 while n%i==0: n //= i c += 1 if c>0: fct.append((i, c)) if n>1: fct.append((n, 1)) return fct t = int(input()) for _ in range(t): n = int(input()) factors = factorize(n) if len(factors)==1: p, c = factors[0] if c>=6: print('YES') print(p, p**2, p**(c-3)) else: print('NO') elif len(factors)==2: p1, c1 = factors[0] p2, c2 = factors[1] if c1+c2>=4: print('YES') print(p1, p2, n//p1//p2) else: print('NO') else: p1, _ = factors[0] p2, _ = factors[1] print('YES') print(p1, p2, n//p1//p2)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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 # method to print the divisors def printDivisors(n) : # Note that this loop runs till square root i = 2 l=[] while i <= math.sqrt(n): if (n % i == 0) : # If divisors are equal, print only one if (n / i == i) : l.append(i) else : # Otherwise print both l.append(i) l.append(n//i) i = i + 1 return l def find3(A, arr_size, s): A.sort() p=0 for i in range(0, arr_size-2): l = i + 1 r = arr_size-1 while (l < r): if( A[i] * A[l] * A[r] == s): print("YES") print(A[i],A[l],A[r]) p=1 break elif (A[i] * A[l] * A[r] < s): l += 1 else: r -= 1 if p==1: break if p==0: print("NO") t=int(input()) while t: t-=1 n=int(input()) l=printDivisors(n) find3(l,len(l),n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for tc in range(int(input())): n=int(input()) a=[] for i in range(2,int(n**0.5)+1): if n%i==0: a.append(i) if n//i!=i: a.append(n//i) a.sort() if len(a)<3: print("NO") else: flag=0 for i in range(len(a)): for j in range(i+1,len(a)): k=n//(a[i]*a[j]) if k in a and k!=a[i] and k!=a[j]: print("YES") print(k,a[i],a[j]) flag=1 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
def solution(): temp = [True]*31623 for i in range(2, 31623): if temp[i]: for j in range(i+i, 31623, i): temp[j] = False er = [i for i, v in enumerate(temp) if v][2:] for _ in range(int(input())): n = int(input()) ans = set() er_iter = er.__iter__() current = er_iter.__next__() l = 1 while current < n: if n%current == 0: if current in ans: if l == 1: l = current else: ans.add(current*l) l = 1 else: ans.add(current) n //= current if len(ans) == 2 and n not in ans: break else: try: current = er_iter.__next__() except StopIteration: break if l: n *= l if len(ans) == 2 and n not in ans: print("YES") ans.add(n) print(*ans) else: print("NO") solution()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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 import math t=int(stdin.readline().rstrip()) while t>0: n=int(stdin.readline().rstrip()) p=int(math.floor(math.sqrt(n))) l=[] a,b=-1,-1 for i in range(2,p+1): if n%i==0: a=i n//=a break for i in range(2,p+1): if n%i==0 and i!=a: b=i n//=b break f=0 if n==1 or n==a or n==b: f=1 if a==-1 or b==-1: f=1 if f==0: print("YES") print(str(a)+" "+str(b)+" "+str(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
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); srand(time(NULL)); ; int q; cin >> q; while (q--) { long long n; cin >> n; vector<long long> ans; for (long long i = 2; i <= sqrt(n); i++) { if (n % i == 0) { ans.push_back(i); n = n / i; } if (n == 1) break; if (ans.size() == 2) break; } if (ans.size() < 2 || n == ans[0] || n == 1 || n == ans[1]) cout << "NO" << endl; else { cout << "YES" << endl << ans[0] << " " << ans[1] << " " << n << endl; } } }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# -*- coding: utf-8 -*- """ Created on Sun Feb 2 11:27:04 2020 @author: pc """ ''' times = int(input()) for _ in range(times): testified_number = int(input()) able = 0 for factor in range(2,testified_number): if testified_number % factor == 0: testified_number_new = testified_number // factor for factor_new in range(factor + 1,testified_number_new): if testified_number_new % factor_new == 0 and testified_number_new // factor_new > factor_new: able = 1 b = factor_new c = testified_number_new // factor_new break if able == 1: a = factor break if able: print("YES") print(a,b,c) else: print('NO') ''' ''' times = int(input()) testified_numbers = [0] * times for i in range(times): testified_numbers[i] = int(input()) M = max(testified_numbers) judge = [False] * 2 + [True] * (M-1) for i in range(M+1): if judge[i]: for j in range(2*i,M+1,i): judge[j]=False for i in range(times): able = 0 number = testified_numbers[i] factors = {} if not judge[number]: for factor in range(2,int(M**(1/3))+1): if judge[factor] and number % factor == 0: while number % factor == 0: number = number // factor if factor in factors: factors[factor] += 1 else: factors[factor] = 1 if len(factors) == 3: able = 1 a = list(factors.keys())[0] b = list(factors.keys())[1] c = testified_numbers[i] // (a*b) break elif len(factors) == 2 and list(factors.values()) != [1,1] and list(factors.values()) != [1,2] and list(factors.values()) != [2,1]: able = 1 a = list(factors.keys())[0] b = list(factors.keys())[1] c = testified_numbers[i] // (a*b) break elif len(factors) == 1 and list(factors.values())[0] >= 6: able = 1 a = list(factors.keys())[0] b = list(factors.keys())[0]**2 c = testified_numbers[i] // (a*b) break if able: print("YES") print(a,b,c) else: print('NO') ''' for _ in range(int(input())): n = int(input()) a = [] for i in range(2, int(n**0.5)+1): if n % i == 0: a.append(i) n = n//i if len(a) == 2: break if len(a) == 2 and n > a[1]: print('YES') print(a[0],a[1],n) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from bisect import * from collections import * from itertools import * import functools import sys import math from decimal import * from copy import * from heapq import * from fractions import * getcontext().prec = 30 MAX = sys.maxsize MAXN = 10**5+10 MOD = 10**9+7 spf = [i for i in range(MAXN)] spf[0]=spf[1] = -1 def sieve(): for i in range(2,MAXN,2): spf[i] = 2 for i in range(3,int(MAXN**0.5)+1): if spf[i]==i: for j in range(i*i,MAXN,i): if spf[j]==j: spf[j]=i def fib(n,m): if n == 0: return [0, 1] else: a, b = fib(n // 2) c = ((a%m) * ((b%m) * 2 - (a%m)))%m d = ((a%m) * (a%m))%m + ((b)%m * (b)%m)%m if n % 2 == 0: return [c, d] else: return [d, c + d] def charIN(x= ' '): return(sys.stdin.readline().strip().split(x)) def arrIN(x = ' '): return list(map(int,sys.stdin.readline().strip().split(x))) def ncr(n,r): num=den=1 for i in range(r): num = (num*(n-i))%MOD den = (den*(i+1))%MOD return (num*(pow(den,MOD-2,MOD)))%MOD def flush(): return sys.stdout.flush() '''*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*''' for _ in range(int(input())): n = int(input()) ans = set() i = 2 while i*i<=n: if len(ans)==2 and n not in ans: ans.add(n) break if n%i==0: if i not in ans: ans.add(i) n//=i i = 2 else: i+=1 else: i+=1 if len(ans)==3: print('YES') print(*list(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
# cook your dish here from sys import stdin, stdout import math from itertools import permutations, combinations from collections import defaultdict from bisect import bisect_left from bisect import bisect_right def L(): return list(map(int, stdin.readline().split())) def In(): return map(int, stdin.readline().split()) def I(): return int(stdin.readline()) P = 1000000007 def main(): for t in range(I()): n = I() lis = [] for i in range(2, int(math.sqrt(n))): if n%i == 0: lis.append(i) n //= i if len(lis) == 2: lis.append(n) break lis = list(set(lis)) lis.sort() if len(lis) == 3: print('YES') print(*lis) 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
# Author : raj1307 - Raj Singh # Date : 13.02.2020 from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().strip().split(" ")) def msi(): return map(str,input().strip().split(" ")) def li(): return list(mi()) def dmain(): sys.setrecursionlimit(100000000) threading.stack_size(40960000) thread = threading.Thread(target=main) thread.start() from collections import deque, Counter, OrderedDict,defaultdict #from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace from math import ceil,floor,log,sqrt,factorial,pi #from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right #from decimal import *,threading #from itertools import permutations #Copy 2D list m = [x[:] for x in mark] .. Avoid Using Deepcopy abc='abcdefghijklmnopqrstuvwxyz' abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} mod=1000000007 #mod=998244353 inf = float("inf") vow=['a','e','i','o','u'] dx,dy=[-1,1,0,0],[0,0,1,-1] def getKey(item): return item[0] def sort2(l):return sorted(l, key=getKey) def d2(n,m,num):return [[num for x in range(m)] for y in range(n)] def isPowerOfTwo (x): return (x and (not(x & (x - 1))) ) def decimalToBinary(n): return bin(n).replace("0b","") def ntl(n):return [int(i) for i in str(n)] def powerMod(x,y,p): res = 1 x %= p while y > 0: if y&1: res = (res*x)%p y = y>>1 x = (x*x)%p return res def gcd(x, y): while y: x, y = y, x % y return x def isPrime(n) : # Check Prime Number or not if (n <= 1) : return False if (n <= 3) : return True if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True def read(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') def main(): for _ in range(ii()): n=ii() f=0 for i in range(2,int(sqrt(n))+1): if n%i==0: x=n//i for j in range(2,int(sqrt(x))+1): if x%j==0 and j!=i: if x//j>=2 and x//j!=j and x//j!=i: print('YES') print(i,j,x//j) f=1 break if f==1: break if f==0: print('NO') # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": #read() main() #dmain() # Comment Read()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible 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()) #if n < 24: # print('NO') a = 0 b = 0 c = 0 sqrt = int(n ** 0.5) for i in range(2, sqrt + 1): if n % i == 0: a = i n /= a break if a: for i in range(a +1, int(n ** 0.5) + 1): if n % i == 0: b = i c = int(n // i) break if a and b and c: if a != b != 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 math def pd(n,not_include) : li = [] for i in range(2, int(math.sqrt(n) + 1)) : if (n % i == 0) : if (n / i == i) : if n!=not_include: lis=[] lis.append(i) lis.append(i) #li.append(lis) else : lis=[] if i!=not_include and n//i!=not_include: lis.append(i) lis.append(n//i) li.append(lis) return li t=(int)(input()) for wirfb in range(t): n=(int)(input()) li=pd(n,1) f=0 if len(li)>=1: for x in li: lis=pd(x[1],x[0]) if len(lis)>=1: f=1 break; else: f=0 else: f=0 if f==0: print("NO") else: print("YES") print(x[0],lis[0][0],lis[0][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
""" // Author : snape_here - Susanta Mukherjee """ from __future__ import division, print_function import os,sys from io import BytesIO, IOBase if sys.version_info[0] < 3: from __builtin__ import xrange as range from future_builtins import ascii, filter, hex, map, oct, zip def ii(): return int(input()) def si(): return input() def mi(): return map(int,input().split()) def li(): return list(mi()) def gcd(x, y): while y: x, y = y, x % y return x def read(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt', 'w') import math # method to print the divisors def printDivisors(n) : l=[] # Note that this loop runs till square root i = 1 while i <= math.sqrt(n): if (n % i == 0) : # If divisors are equal, print only one if (n / i == i) : l.append(i) else : # Otherwise print both l.append(i) l.append(n//i) i = i + 1 return l #This code is contributed by Nikita Tiwari. def main(): for _ in range(ii()): n=ii() b=e=f=0 a=printDivisors(n) f=0 for i in range(1,len(a)): for j in range(i+1,len(a)): x,y=a[i],a[j] z=n/(x*y) if math.ceil(z)==math.floor(z) and z!=1 and z!=x and z!=y: f=1 print("YES") print(x,y,int(z)) break if f: break if f==0: print("NO") # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b"\n") + (not b) ptr = self.buffer.tell() self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode("ascii")) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") def print(*args, **kwargs): """Prints the values to a stream, or to sys.stdout by default.""" sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop("end", "\n")) if kwargs.pop("flush", False): file.flush() if sys.version_info[0] < 3: sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout) else: sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout) input = lambda: sys.stdin.readline().rstrip("\r\n") # endregion if __name__ == "__main__": #read() main() #Comment read()
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 Fenjie(n): k = {} if (n == 1): return {} a = 2 while (n >= 2): b = n%a if (a*a > n): if (n in k): k[n] += 1 else: k[n] = 1 break if (b == 0): if (a in k): k[a] += 1 else: k[a] = 1 n = n//a else: a += 1 return k n = int(input()) for _ in range(n): m = int(input()) k = Fenjie(m) s = 0 le = len(k) l = [i for i in k] if (le >= 3): print("YES") flag = 0 print(l[0], l[1], m//l[0]//l[1]) elif (le==2): if (k[l[0]]+k[l[1]] >= 4): print("YES") print(l[0], l[1], m//l[0]//l[1]) else: print("NO") else: if (k[l[0]] >= 6): print("YES") print(l[0], l[0]*l[0], m//l[0]//l[0]//l[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
def fact(n): i=2 for i in range(2,int(n**0.5)+1): if n%i==0 and i not in l: return i return 0 for _ in range(int(input())): l=[] n=int(input()) a=fact(n) l.append(a) if a!=0: b=fact(n/a) else: print("NO") continue if b!=0: z=(n//(a*b)) else: print("NO") continue if z!=a and z!=b and z!=1: print("YES") print(a,b,z) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n=int(input()) flag=0 for i in range(2,1001): if(n%i==0): a=i n//=i flag=1 break #print(n) if(flag==0): print("NO") else: i=a+1 flag1=0 while(i*i<=n): if(n%i==0): if(i!=n//i): print("YES") print(a,i,n//i) flag1=1 break i+=1 if(flag1==0): print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t = int(input()) while t > 0: n = int(input()) fact = [] for i in range(2, int(math.sqrt(n))+1): if i*int(n/i) == n: if i != int(n/i): fact.append(i) fact.append(int(n/i)) else: fact.append(i) fact.sort() flag = 0 for i in range(len(fact)-1): for j in range(i+1, len(fact)): if fact[i]*fact[j] < n and (n % (fact[i]*fact[j]) == 0): num = int(n/(fact[i]*fact[j])) if num != fact[i] and num != fact[j]: flag = 1 break if flag == 1: break if flag == 0: print('NO') else: print('YES') print(fact[i], fact[j], num) t -= 1
PYTHON3