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
1271_B. Blocks
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 β‹… n. If it is impossible to find such a sequence of operations, you need to report it. Input The first line contains one integer n (2 ≀ n ≀ 200) β€” the number of blocks. The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black. Output If it is impossible to make all the blocks having the same color, print -1. Otherwise, print an integer k (0 ≀ k ≀ 3 β‹… n) β€” the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≀ p_j ≀ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation. If there are multiple answers, print any of them. Examples Input 8 BWWWWWWB Output 3 6 2 4 Input 4 BWBB Output -1 Input 5 WWWWW Output 0 Input 3 BWB Output 2 2 1 Note In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black. It is impossible to make all colors equal in the second example. All blocks are already white in the third example. In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
2
8
n=int(input()) s=list(input()) c=s.copy() k=[] for i in range(n-1): if s[i]=='W': pass else: s[i]='W' if s[i+1]=='W': s[i+1]='B' else: s[i+1]='W' k.append(i+1) if s==['W']*n: print(len(k)) print(*k) else: s=c.copy() k=[] for i in range(n-1): if s[i]=='B': pass else: s[i]='B' if s[i+1]=='W': s[i+1]='B' else: s[i+1]='W' k.append(i+1) if s==['B']*n: print(len(k)) print(*k) else: print(-1)
PYTHON3
1271_B. Blocks
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 β‹… n. If it is impossible to find such a sequence of operations, you need to report it. Input The first line contains one integer n (2 ≀ n ≀ 200) β€” the number of blocks. The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black. Output If it is impossible to make all the blocks having the same color, print -1. Otherwise, print an integer k (0 ≀ k ≀ 3 β‹… n) β€” the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≀ p_j ≀ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation. If there are multiple answers, print any of them. Examples Input 8 BWWWWWWB Output 3 6 2 4 Input 4 BWBB Output -1 Input 5 WWWWW Output 0 Input 3 BWB Output 2 2 1 Note In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black. It is impossible to make all colors equal in the second example. All blocks are already white in the third example. In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
2
8
def sol(): n = int(input()) s = list(input()) b = s.count('B') w = s.count('W') if w % 2 == 1 and b % 2 == 1: print(-1) return ans = [] s = list(s) if w % 2 == 1: odd = 'W' even = 'B' else: odd = 'B' even = 'W' for i in range(n-1): if s[i] != odd: ans.append(i + 1) s[i] = odd s[i+1] = even if s[i+1] == odd else odd print(len(ans)) print(*ans) sol()
PYTHON3
1271_B. Blocks
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 β‹… n. If it is impossible to find such a sequence of operations, you need to report it. Input The first line contains one integer n (2 ≀ n ≀ 200) β€” the number of blocks. The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black. Output If it is impossible to make all the blocks having the same color, print -1. Otherwise, print an integer k (0 ≀ k ≀ 3 β‹… n) β€” the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≀ p_j ≀ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation. If there are multiple answers, print any of them. Examples Input 8 BWWWWWWB Output 3 6 2 4 Input 4 BWBB Output -1 Input 5 WWWWW Output 0 Input 3 BWB Output 2 2 1 Note In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black. It is impossible to make all colors equal in the second example. All blocks are already white in the third example. In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
2
8
import java.io.BufferedReader; import java.io.Console; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import java.util.StringTokenizer; public class Main { public static int check(StringBuffer sf) { int B = 0, W = 0; for (int i = 0; i < sf.length(); i++) if (sf.charAt(i) == 'B') B++; else W++; if (B == 0 || W == 0) return 1; return 0; } public static void main(String[] args) throws IOException { FastReader fs=new FastReader(); int l = fs.nextInt(); String s = fs.next(); char []ch=s.toCharArray(); StringBuffer sf=new StringBuffer(s); int B = 0, W = 0; for (int i = 0; i < l; i++) { if (sf.charAt(i) == 'B') B++; else W++; } if (W == 0 || B == 0) System.out.println(0); else if (B % 2 != 0 && W % 2 != 0) System.out.println(-1); else { int cnt1 = 0; List<Integer> list1 = new ArrayList<>(); for (int i = 0; i < l; i++) { if (sf.charAt(i) == 'W' && i != l - 1) { sf.setCharAt(i, 'B'); if (sf.charAt(i+1) == 'B') sf.setCharAt(i+1,'W'); else sf.setCharAt(i+1, 'B'); cnt1++; list1.add(i + 1); } } if(check(sf)==0){ for(int i=0;i<l-1;i+=2){ cnt1++; list1.add(i+1); } } System.out.println(cnt1); for (int i = 0; i < cnt1; i++) { if (i != 0) System.out.print(" "); System.out.print(list1.get(i)); } } } public static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }
JAVA
1271_B. Blocks
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 β‹… n. If it is impossible to find such a sequence of operations, you need to report it. Input The first line contains one integer n (2 ≀ n ≀ 200) β€” the number of blocks. The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black. Output If it is impossible to make all the blocks having the same color, print -1. Otherwise, print an integer k (0 ≀ k ≀ 3 β‹… n) β€” the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≀ p_j ≀ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation. If there are multiple answers, print any of them. Examples Input 8 BWWWWWWB Output 3 6 2 4 Input 4 BWBB Output -1 Input 5 WWWWW Output 0 Input 3 BWB Output 2 2 1 Note In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black. It is impossible to make all colors equal in the second example. All blocks are already white in the third example. In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
2
8
n=int(input()) s=list(input()) ans=[] if s[0]=="W": ans.append(0) s[0]="B" if s[1]=="W": s[1]="B" else: s[1]="W" for i in range(1,n-1): if s[i]=="W": s[i]="B" if s[i+1]=="W": s[i+1]="B" else: s[i+1]="W" ans.append(i) if s!=["B" for i in range(n)] and n%2==0: print(-1) exit() if s!=["B" for i in range(n)]: for i in range(n-1): if i%2==0: ans.append(i) print(len(ans)) print(" ".join(map(str,[i+1 for i in ans])))
PYTHON3
1271_B. Blocks
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 β‹… n. If it is impossible to find such a sequence of operations, you need to report it. Input The first line contains one integer n (2 ≀ n ≀ 200) β€” the number of blocks. The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black. Output If it is impossible to make all the blocks having the same color, print -1. Otherwise, print an integer k (0 ≀ k ≀ 3 β‹… n) β€” the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≀ p_j ≀ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation. If there are multiple answers, print any of them. Examples Input 8 BWWWWWWB Output 3 6 2 4 Input 4 BWBB Output -1 Input 5 WWWWW Output 0 Input 3 BWB Output 2 2 1 Note In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black. It is impossible to make all colors equal in the second example. All blocks are already white in the third example. In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
2
8
def solve(): n = int(input()) s = input() ans = 0 res = [] w = 0 b = 0 for i in range(n): if s[i]=="W": w+=1 if s[i]=="B": b+=1 delta = -1 if w==0 or b==0: print(0) return if w%2==1: if b%2==1: print(-1) return else: delta = "B" else: delta = "W" s = list(s) for i in range(n): if s[i]==delta: s[i]=0 else: s[i]=1 for i in range(n-1): if s[i]==0: if s[i+1]==1: s[i+1]=0 else: s[i+1]=1 ans+=1 res.append(i+1) print(ans) for i in range(len(res)): print(res[i]," ") solve()
PYTHON3
1271_B. Blocks
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 β‹… n. If it is impossible to find such a sequence of operations, you need to report it. Input The first line contains one integer n (2 ≀ n ≀ 200) β€” the number of blocks. The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black. Output If it is impossible to make all the blocks having the same color, print -1. Otherwise, print an integer k (0 ≀ k ≀ 3 β‹… n) β€” the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≀ p_j ≀ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation. If there are multiple answers, print any of them. Examples Input 8 BWWWWWWB Output 3 6 2 4 Input 4 BWBB Output -1 Input 5 WWWWW Output 0 Input 3 BWB Output 2 2 1 Note In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black. It is impossible to make all colors equal in the second example. All blocks are already white in the third example. In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
2
8
n=int(input()) s=input() l=[i for i in s] s=list(l) numofb=0 numofw=0 for i in s: if(i=='B'): numofb+=1 else: numofw+=1 c=0 if(numofb%2==0): c='W' elif(numofw%2==0): c='B' if(c==0): print(-1) else: numofs=0 l=[] for i in range(n-1): if(s[i]!=c): if(s[i]=='W'): s[i]='B' else: s[i]='W' if(s[i+1]=='B'): s[i+1]='W' else: s[i+1]='B' l.append(i) numofs+=1 print(numofs) for i in l: print(i+1,end=" ") print()
PYTHON3
1271_B. Blocks
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 β‹… n. If it is impossible to find such a sequence of operations, you need to report it. Input The first line contains one integer n (2 ≀ n ≀ 200) β€” the number of blocks. The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black. Output If it is impossible to make all the blocks having the same color, print -1. Otherwise, print an integer k (0 ≀ k ≀ 3 β‹… n) β€” the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≀ p_j ≀ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation. If there are multiple answers, print any of them. Examples Input 8 BWWWWWWB Output 3 6 2 4 Input 4 BWBB Output -1 Input 5 WWWWW Output 0 Input 3 BWB Output 2 2 1 Note In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black. It is impossible to make all colors equal in the second example. All blocks are already white in the third example. In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
2
8
def change(a): if a == 'W': return 'B' else: return 'W' n = int(input()) ss = input() s = [] s[:0] = ss ops = [] good = "w" if s.count("B") == 0 or s.count("W") == 0: print(0) # print("uff") exit() elif s.count("B") % 2 == 0: good = "W" elif s.count("W") % 2 == 0: good = "B" else: print(-1) exit() for i in range(n-1): if s[i] != good: s[i] = change(s[i]) s[i+1] = change(s[i+1]) ops.append(i+1) print(len(ops)) for o in ops: print(o, end=" ") print("")
PYTHON3
1271_B. Blocks
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 β‹… n. If it is impossible to find such a sequence of operations, you need to report it. Input The first line contains one integer n (2 ≀ n ≀ 200) β€” the number of blocks. The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black. Output If it is impossible to make all the blocks having the same color, print -1. Otherwise, print an integer k (0 ≀ k ≀ 3 β‹… n) β€” the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≀ p_j ≀ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation. If there are multiple answers, print any of them. Examples Input 8 BWWWWWWB Output 3 6 2 4 Input 4 BWBB Output -1 Input 5 WWWWW Output 0 Input 3 BWB Output 2 2 1 Note In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black. It is impossible to make all colors equal in the second example. All blocks are already white in the third example. In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
2
8
#include <bits/stdc++.h> using namespace std; template <class C> void min_self(C &a, C b) { a = min(a, b); } template <class C> void max_self(C &a, C b) { a = max(a, b); } long long mod(long long n, long long m = 1000000007) { n %= m, n += m, n %= m; return n; } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); struct custom_hash { static uint64_t splitmix64(uint64_t x) { x += 0x9e3779b97f4a7c15; x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } }; unordered_map<long long, int, custom_hash> safe_map; const int MAXN = 1e5 + 5; const int LOGN = 21; const long long INF = 1e14; int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; string s; cin >> n >> s; vector<int> ans; for (int i = 0; i < n; i++) { if (s[i] != 'W' && i + 1 < n) { ans.push_back(i); s[i] = 'W' + 'B' - s[i]; s[i + 1] = 'W' + 'B' - s[i + 1]; } } int imp = 0; for (int i = 0; i < n; i++) { if (s[i] != 'W') { imp = 1; break; } } if (imp) { for (int i = 0; i < n; i++) { if (s[i] != 'B' && i + 1 < n) { ans.push_back(i); s[i] = 'B' + 'W' - s[i]; s[i + 1] = 'B' + 'W' - s[i + 1]; } } int no = 0; for (int i = 0; i < n; i++) { if (s[i] != 'B') { no = 1; break; } } if (no) { cout << -1, cout << "\n"; } else { cout << ans.size(), cout << "\n"; for (auto x : ans) cout << x + 1 << " "; } } else { cout << ans.size(), cout << "\n"; for (auto x : ans) cout << x + 1 << " "; } cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n"; return 0; }
CPP
1271_B. Blocks
There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white block becomes black, and vice versa). You want to find a sequence of operations, such that they make all the blocks having the same color. You don't have to minimize the number of operations, but it should not exceed 3 β‹… n. If it is impossible to find such a sequence of operations, you need to report it. Input The first line contains one integer n (2 ≀ n ≀ 200) β€” the number of blocks. The second line contains one string s consisting of n characters, each character is either "W" or "B". If the i-th character is "W", then the i-th block is white. If the i-th character is "B", then the i-th block is black. Output If it is impossible to make all the blocks having the same color, print -1. Otherwise, print an integer k (0 ≀ k ≀ 3 β‹… n) β€” the number of operations. Then print k integers p_1, p_2, ..., p_k (1 ≀ p_j ≀ n - 1), where p_j is the position of the left block in the pair of blocks that should be affected by the j-th operation. If there are multiple answers, print any of them. Examples Input 8 BWWWWWWB Output 3 6 2 4 Input 4 BWBB Output -1 Input 5 WWWWW Output 0 Input 3 BWB Output 2 2 1 Note In the first example, it is possible to make all blocks black in 3 operations. Start with changing blocks 6 and 7, so the sequence is "BWWWWBBB". Then change blocks 2 and 3, so the sequence is "BBBWWBB". And finally, change blocks 4 and 5, so all blocks are black. It is impossible to make all colors equal in the second example. All blocks are already white in the third example. In the fourth example it is possible to make all blocks white in two operations: first operation is to change blocks 2 and 3 (so the sequence is "BBW"), and then change blocks 1 and 2 (so all blocks are white).
2
8
#include <bits/stdc++.h> using namespace std; vector<int> v; bool conv(string s, char w) { v.clear(); for (int i = 0; i < s.size(); i++) { if (s[i] == w) continue; else if (i != s.size() - 1) { v.push_back(i + 1); if (s[i + 1] == 'W') s[i + 1] = 'B'; else s[i + 1] = 'W'; } if (i == s.size() - 1) return 0; } return 1; } int main() { int n; cin >> n; string s; cin >> s; string tmp = "WB"; for (int i = 0; i < 2; i++) if (conv(s, tmp[i])) { cout << v.size() << endl; for (int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << endl; return 0; } cout << -1 << endl; return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.*; import java.util.*; import java.math.*; public class Main{ public static void main(String[] args) throws Exception { IO io = new IO(); PrintWriter out = new PrintWriter(System.out); Solver sr = new Solver(); sr.solve(io,out); out.flush(); out.close(); } static class Solver { class Pair { int x, y; public Pair(int a, int b) { x=a; y=b; } } void solve(IO io, PrintWriter out) { int i, j; int t = io.nextInt(); while(t-->0) { int n = io.nextInt(); boolean flag=false; int a=0, b=0, c=0; for(i=2 ; i*i<=n ; i++) { if(n%i==0 && n/i!=i) { int m = n/i; for(j=i+1 ; j*j<=m ; j++) { if(m%j==0 && m/j!=j) { a=i; b=j; c=m/j; flag=true; break; } } } if(flag) break; } if(!flag) out.println("NO"); else out.println("YES\n"+a+" "+b+" "+c); } } } //Special thanks to Petr (on codeforces) who inspired me to implement IO class! static class IO { BufferedReader reader; StringTokenizer tokenizer; public IO() { reader = new BufferedReader(new InputStreamReader(System.in)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public String nextLine() { String s=""; try { s=reader.readLine(); } catch (IOException e) { throw new RuntimeException(e); } return s; } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n=int(input()) i=1 c=2 l=[] y=n while(i<=2): if n%c==0: n=n//c i=i+1 l.append(c) if c>=y**0.5: break c=c+1 if l==[] or len(l)==1: print("NO") elif y%(l[0]*l[1])==0: x=y//(l[0]*l[1]) if x not in l and x!=1: print("YES") l.append(x) for i in range(len(l)): if i==len(l)-1: print(l[i]) else: print(l[i],end=" ") else: print("NO") else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
T = int(input().strip()) import math for t in range(T): N = int(input().strip()) status = True for a in range(2, int(math.sqrt(N)+1)): if N%a==0: b=N//a for x in range(2, int(math.sqrt(b)+1)): if x!=a and b%x==0 and a!=b//x and x!=b//x: print('YES') print(a, x, b//x) status=False break if status==False: break if status==True: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> int main(void) { long long t; scanf("%lld", &t); long long num, sub_num, i, j; while (t--) { int cnt = 1; scanf("%lld", &num); for (i = 2; (i * i) <= num; ++i) { if (!cnt) { break; } if (!(num % i)) { sub_num = (num / i); for (j = (i + 1); (j * j) < sub_num; ++j) { if (!(sub_num % j)) { printf("YES\n%lld %lld %lld\n", i, j, (sub_num / j)); --cnt; break; } } } } if (cnt) { printf("NO\n"); } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def factors(n): s=[] i=2 while(i*i<=n): if(n%i==0): s.append(i) n=n//i if(len(s)==2): if(n not in s): s.append(n) break i=i+1 if(len(s)<3): print("NO") else: print("YES") print(*s) for _ in range(int(input())): n=int(input()) l1=factors(n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input().strip()) import math def primeFactors(n): ans = [] # Print the number of two's that divide n while n % 2 == 0: ans.append(2) n = n // 2 # n must be odd at this point # so a skip of 2 ( i = i + 2) can be used result = int(math.sqrt(n)) for i in range(3,result+1,2): # while i divides n , print i ad divide n while n % i== 0: ans.append(i) n = n // i # Condition if n is a prime # number greater than 2 if n > 2: ans.append(n) return ans for _ in range(t): n = int(input().strip()) ans = primeFactors(n) ts = set(ans) if len(ts) == 3 and len(ts) == len(ans): a = ans[0] b = ans[1] c = 1 for i in range(2,len(ans)): c *= ans[i] print('YES') print(a,b,c) elif (len(ts) >= 2 and len(ans) >= 4): a = ts.pop() b = ts.pop() c = 1 for i in range(len(ans)): if ans[i] == a: ans[i] = 1 break for i in range(len(ans)): if ans[i] == b: ans[i] = 1 break for i in range(len(ans)): c *= ans[i] print('YES') print(a,b,c) elif (len(ts) >= 1 and len(ans) >= 6): a = ans[0] b = ans[1] * ans[2] c = 1 for i in range(3,len(ans)): c *= ans[i] print('YES') print(a,b,c) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n = int(input()) if n < 24: print("NO") continue j = -1 a, b = 0, 0 for i in range(2, int(n**(1 / 3)) + 1): if n % i == 0: a = i n //= i j = i + 1 break if j == -1: print("NO") continue o = -1 for i in range(j, int(n**(1 / 2)) + 1): if n % i == 0: b = i n //= i o = 1 break if o == -1 or n <= b: print("NO") continue print("YES") print(a, b, n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math from collections import defaultdict def primeFactors(n): d=defaultdict(int) while n % 2 == 0: d[2]+=1 n = n // 2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: d[i]+=1 n = n / i if n > 2: d[n]+=1 return d t=int(input()) for i in range(t): n=int(input()) d= primeFactors(n) # print(d) if len( d.keys() )>=3: print("YES") s=[] ww=1 for j in list(d.keys())[:2]: s.append( int(j) ) ww*=j**(d[j]-1) for j in list(d.keys())[2:]: ww*= int(j**d[j]) s.append(ww) print(*s) elif len(list(d.keys()))==1: w,w1 = int(list(d.keys())[0]), int(d[list(d.keys())[0]]) if w1>=6: print("YES") ans = "{} {} {}".format(w,w**2,w**(w1-3)) print(ans) else: print("NO") elif len(list(d.keys()))==2: keys= list(map(int,list(d.keys()))) value = list(map(int,list(d.values()))) if sum(value)>=4: print("YES") ans = "{} {} {}".format( keys[0], keys[1], keys[0]**(value[0]-1) * keys[1]**(value[1]-1) ) print(ans) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
# from debug import debug import sys t_ = int(input()) while t_: t_-=1 n = int(input()) if n<24: print("NO") else: i = 2 a = b = c = 0 while i*i<n: if n%i == 0: a = i n = n//i break i+=1 if a == 0: print("NO") else: i = 3 while i*i<n: if n%i == 0 and i != a: b = i c = n//i break i+=1 if b<2 or c<2 or b == c: print("NO") else: print("YES") print(a,b,c)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int tst; long long n, a, b, c; vector<long long> v; bool flag; cin >> tst; while (tst--) { flag = false; cin >> n; for (int i = 2; i <= sqrt(n); i++) { if (n % i == 0) { v.push_back(i); n /= i; } if (v.size() == 2) { v.push_back(n); if (v[0] != v[1] && v[1] != v[2]) flag = true; break; } } if (flag) { cout << "YES" << endl; sort(v.begin(), v.end()); cout << v[0] << " " << v[1] << " " << v[2] << endl; } else cout << "NO" << endl; v.clear(); } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n; cin >> n; long long temp = n; vector<long long> v; for (long long i = 2; i <= sqrt(n); i++) { while (n % i == 0) { v.push_back(i); n /= i; } } if (n != 1) { v.push_back(n); } if (v.size() < 3) { cout << "No" << endl; continue; } long long fi = v[0]; long long se = v[1]; if (se == fi) { se = se * v[2]; } long long th = temp / (fi * se); if (th != fi && th != se && th != 1) { cout << "Yes" << endl; cout << fi << " " << se << " " << th << 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
from collections import Counter from collections import defaultdict import math import random import heapq as hq from math import sqrt import sys from functools import reduce def input(): return sys.stdin.readline().strip() def iinput(): return int(input()) def tinput(): return input().split() def rinput(): return map(int, tinput()) def rlinput(): return list(rinput()) mod = int(1e9)+7 def solve(adj, colors, n): pass def root(parent, a): while parent[a] != a: parent[a] = parent[parent[a]] a = parent[a] return a def union(parent, size, a, b): roota, rootb = root(parent, a), root(parent, b) if roota == rootb: return parent[rootb] = roota size[roota] += size[rootb] size[rootb] = 0 def factors(n): return set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))) if __name__ == "__main__": for i in range(iinput()): n=iinput() temp1=factors(n) temp=list(factors(n)) temp.sort() l=len(temp) flag=True for i in range(1,l-1): for j in range(i+1,l-1): if n%(temp[i]*temp[j])==0: s=n/(temp[i]*temp[j]) if s!=temp[i] and s!=temp[j] and s!=1 and s!=n and s in temp1: print('YES') print(temp[i],temp[j],int(s)) flag=False break if not flag:break if 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
from math import ceil def find(n,p,ans): for i in range(2,ceil(n**(1/p))+1,1): if n%i==0: if p==3: ans+=find(n//i,2,[i]) if len(set(ans))==3: return ans ans=[] elif p==2 and n//i>1: new=ans+[(n//i),i] if len(set(new))==3: return new return ans for i in range(int(input())): n=int(input()) k=find(n,3,[]) if len(k)==3: print("YES") print(*k,sep=" ") else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for _ in range(int(input())): n=int(input()) g=0 for i in range(2,math.floor(math.sqrt(n))+1): if n%i==0: if n//i!=i: p=n//i for j in range(2,math.floor(math.sqrt(i))+1): if i%j==0: if i//j!=j and j!=p and p!=i//j: g=1 l=[n//i,j,i//j] break for j in range(2,math.floor(math.sqrt(p))+1): if p%j==0: if p//j!=j and i!=j and i!=p//j: g=1 l=[j,p//j,i] break if g==0: print("NO") else: print("YES") 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
#include <bits/stdc++.h> using namespace std; bool isPrime(int x) { for (long long int i = 2; i * i <= x; i++) { if (x % i == 0) return false; } return true; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int aux; cin >> aux; while (aux--) { int n; cin >> n; int num = n; vector<int> fat; for (int d : {2, 3, 5}) { while (n % d == 0) { fat.push_back(d); n /= d; } } int incremento[] = {4, 2, 4, 2, 4, 6, 2, 6}; int aux = 0; for (int i = 7; i * i <= n; i += incremento[(aux++) % 8]) { while (n % i == 0) { fat.push_back(i); n /= i; } } if (n > 1) fat.push_back(n); if (fat.size() < 3) { cout << "NO\n"; continue; } int p = fat[0]; int s = fat[1]; if (s == p) { s *= fat[2]; } int t = num / (p * s); if (p != s and p != t and s != t and s >= 2 and p >= 2 and t >= 2) { cout << "YES\n"; cout << p << ' ' << s << ' ' << t << '\n'; continue; } cout << "NO\n"; } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; struct di { int div1, div2; }; struct divv { int divv1, divv2, divv3; }; di a = {0, 0}; divv b = {0, 0, 0}; int n, t; di f(int nr) { for (int d = 2; d * d <= nr; d++) if (nr % d == 0) { di x = {d, nr / d}; return x; } return a; } divv esteprod(int nr) { for (int d = 2; d * d <= nr; d++) { if (nr % d == 0) { di x = f(d); if (x.div1 != 0 and x.div1 != x.div2 and x.div1 != nr / d and x.div2 != nr / d) { divv z = {x.div1, x.div2, nr / d}; return z; } x = f(nr / d); if (x.div1 != 0 and x.div1 != x.div2 and x.div1 != d and x.div2 != d) { divv z = {x.div1, x.div2, d}; return z; } } } return b; } int main() { cin >> t; for (int tt = 1; tt <= t; tt++) { cin >> n; divv z = esteprod(n); if (z.divv1 != 0) { cout << "YES" << endl; cout << z.divv1 << ' ' << z.divv2 << ' ' << z.divv3 << endl; } else cout << "NO" << endl; } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
N = int(input()) for _ in range(N): x = int(input()) d = 2 ans = [] for steps in range(2): if d > x: break while d * d <= x: if x % d == 0: ans.append(d) x //= d d += 1 break d += 1 if len(ans) == 2 and x >= d: print('YES') print(*(ans + [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
### C. Product of Three Numbers for _ in range(int(input())): n=int(input()) c=[] i=2 while len(c)<2 and i**2<n: if n%i==0: c.append(i) n=n//i i+=1 if len(c)==2 and n not in c: print('YES') print(*c,n) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t=int(input()) for i in range(t): n=int(input()) f=0 l=[] l1=[] for j in range(2,int(math.sqrt(n))+1): if n%j==0: l.append(j) l.append(n//j) l1=list(set(l)) l1.sort() if len(l1)==0: print("NO") else: a=l1[0] n=n//a for j in range(len(l1)): if n%l1[j]==0 and l1[j]!=a: b=l1[j] n=n//b f=1 break if f==0: print("NO") else: if n in l1 and n!=a and n!=b: print("YES") print(a,b,n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def solve(n,i): a=-1 b=-1 while (i*i<=n): if (n%i)==0: a=i b=n//i if a==b: a=-1 b=-1 break i+=1 return a,b for t in range(int(input())): n =int(input()) a,b = solve(n,2) if a==-1: print("NO") else: b,c = solve(b,a+1) if b==-1: print("NO") else: print("YES") print(a,b,c)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
##################################### import atexit, io, sys, collections, math, heapq, fractions buffer = io.BytesIO() sys.stdout = buffer @atexit.register def write(): sys.__stdout__.write(buffer.getvalue()) #################################### def f(n): u = 2 on = n r = [] limit = int(on **0.5) while(u <= limit): if n % u == 0: c = 0 while(n % u == 0): n /= u c+=1 r.append((u,c)) u+= 1 if n > 1: r.append((n,1)) r.sort(key = lambda x:-x[1]) if len(r) >= 3: print 'YES' print ' '.join(map(str,[r[0][0], r[1][0], on / (r[0][0] * r[1][0])])) return if len(r) == 2: if r[0][1] >= 3: e = r[0][0] print 'YES' print ' '.join(map(str,[e, e ** 2, on / (e ** 3)])) return if r[1][1] >= 3: e = r[1][0] print 'YES' print ' '.join(map(str,[e, e ** 2, on / (e ** 3)])) return a = r[0][0] b = r[1][0] if on / (a*b) not in [a,b,1]: print 'YES' print ' '.join(map(str,[a, b, on / (a * b)])) return print 'NO' return if len(r) == 1: if r[0][1] >= 6: e = r[0][0] print 'YES' print ' '.join(map(str,[e, e** 2, on / (e ** 3)])) return print 'NO' return for i in range(int(raw_input())): n = int(raw_input()) f(n)
PYTHON
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> const long long int mod = 1e9 + 7; using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); ; long long int t = 0; cin >> t; while (t--) { long long int n = 0; cin >> n; if (n < 24) { cout << "NO\n"; continue; } else { vector<long long int> f; for (long long int i = 2; i * i <= n; ++i) { if (n % i == 0) { f.push_back(i); n /= i; } } f.push_back(n); sort(f.begin(), f.end()); if (f.size() > 3) { for (long long int i = 3; i < f.size(); ++i) { f[2] *= f[i]; } } if (f.size() < 3) cout << "NO\n"; else if (f[0] != f[1] && f[0] != f[2] && f[1] != f[2]) { cout << "YES\n"; cout << f[0] << " " << f[1] << " " << f[2] << "\n"; } else cout << "NO\n"; } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin t = int(stdin.readline()) for _ in xrange(t): n = int(stdin.readline()) a = [] i = 2 while True: if i * i > n: break if n%i==0: a.append(i) n/=i i+=1 break i+=1 while True: if i*i > n: break if n%i==0: a.append(i) a.append(n/i) break i+=1 a = list(set(a)) if len(a)==3: print "YES" print a[0],a[1],a[2] 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
for _ in range(int(input())): n = int(input()) i = 2 while i * i <= n: if n % i == 0: k = n // i j = i + 1 fl = 0 while j * j <= k: if k % j == 0 and j != k // j: print("YES") print(i, j, k // j) fl = 1 break j += 1 if fl: break i += 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
""" author : dokueki """ import math def divisor(x): i = 1 div = [] while i <= math.sqrt(x): if x%i == 0: if x//i == i: div.append(i) else: div.extend([i,x//i]) i += 1 div.remove(max(div)) div.remove(min(div)) return div for _ in range(int(input())): n = int(input()) div1 = divisor(n) if len(div1) == 0: a = False else: a = min(div1) if a: div2 = sorted(divisor(n // a)) if len(div2) == 0: b = False else: for i in div2: if i > a: b = i break else: b = False #print(div2) if a and b: c = n//(a*b) if c > a and c > b : pass else: c = False else: c = False #print((a,b,c)) if a and b and c: print("YES") print(a,b,c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys #sys.stdin = open("division.in","r") #sys.stdout = open("division.out","w") t = int(input()) for i in range(t): n = int(input()) i = 2 flag = 0 while(i ** 2 <= n): if n % i == 0: a = i j = 2 while(j ** 2 <= (n // a)): if (n // a) % j == 0: b = (n // a) // j c = (n // a) // b if a != b and a != c and b != c: flag = 1 break j += 1 i += 1 if flag: print("YES") print(a,b,c) break if not flag: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') import math,datetime,functools from collections import deque,defaultdict,OrderedDict import collections def primeFactors(n): pf=[] # Print the number of two's that divide n while n % 2 == 0: pf.append(2) n = n / 2 # n must be odd at this point # so a skip of 2 ( i = i + 2) can be used for i in range(3,int(math.sqrt(n))+1,2): # while i divides n , print i ad divide n while n % i== 0: pf.append(int(i)) n = n /i # Condition if n is a prime # number greater than 2 if n > 2: pf.append(int(n)) return pf def main(): starttime=datetime.datetime.now() if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") #Solving Area Starts--> for _ in range(ri()): n=ri() a=primeFactors(n) amult=1 alen=len(a) for i in range(1,alen-1): amult=amult*a[i] # print(a) t=0 if alen<3: ws("NO") else: z=len((set(a))) if z>=3: ws("YES") ans=[a[0],a[-1],amult] t=1 if z==2: if alen>=4: ws("YES") ans=[a[0],a[-1],amult] t=1 if t==0: ws("NO") if z==1: if alen>=6: ws("YES") ans=[a[0],a[0]*2,n//(a[0]**3)] t=1 if t==0: ws("NO") if t==1: wia(ans) #<--Solving Area Ends endtime=datetime.datetime.now() time=(endtime-starttime).total_seconds()*1000 if(os.path.exists('input.txt')): print("Time:",time,"ms") class FastReader(io.IOBase): newlines = 0 def __init__(self, fd, chunk_size=1024 * 8): self._fd = fd self._chunk_size = chunk_size self.buffer = io.BytesIO() def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size)) 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, size=-1): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size)) 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() class FastWriter(io.IOBase): def __init__(self, fd): self._fd = fd self.buffer = io.BytesIO() self.write = self.buffer.write def flush(self): os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class FastStdin(io.IOBase): def __init__(self, fd=0): self.buffer = FastReader(fd) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") class FastStdout(io.IOBase): def __init__(self, fd=1): self.buffer = FastWriter(fd) self.write = lambda s: self.buffer.write(s.encode("ascii")) self.flush = self.buffer.flush if __name__ == '__main__': sys.stdin = FastStdin() sys.stdout = FastStdout() main()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for _ in range(int(input())): n = int(input()) a = b = c = -1; ok = 0; for j in range(2, int(math.sqrt(n))+1): if n % j == 0: if a == -1: a = j; n /= a elif b == -1: b = j; n /= b; if (n >= 2 and n != a and n != b): c = n; ok = 1; else: break if ok: print("YES") print(a, 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
for i in range(int(input())): k=set() a=int(input()) for i in range(2,10000): if len(k)<2: if a%i==0: a=a//i k.add(i) elif len(k)==2 and a>2: k.add(a) if len(k)==3: print('YES') for i in sorted(k): print(i,end=' ') print() else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.ArrayList; import java.util.Scanner; public class ProductofThreeNumbers { public static ArrayList<Integer> factors; public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); while (t-- > 0) { int n = in.nextInt(); getFactors(n); //brute force boolean found = false; for (int i=0;i<factors.size()-2;i++) { for (int j=i+1;j<factors.size()-1;j++) { for (int k=j+1;k<factors.size();k++) { int mul = (factors.get(i) * factors.get(j) * factors.get(k)); if (mul == n) { //print the numbers System.out.println("YES"); System.out.println(factors.get(i) + " " + factors.get(j) + " " + factors.get(k)); found = true; i = factors.size(); j = factors.size(); k = factors.size(); break; }else if (mul > n) { //no need to continue break; } } } } if (!found) { System.out.println("NO"); } } in.close(); } public static void getFactors(int n) { factors = new ArrayList<>(); for (int i = 2; i <= Math.sqrt(n); i++) { if (n % i == 0) factors.add(i); } int size = factors.size() - 2; if (factors.size() == 0) { return; } if (factors.get(size + 1) * factors.get(size + 1) != n) { factors.add(n / factors.get(size + 1)); } for (int i=size;i>=0;i--) { factors.add(n / factors.get(i)); } } public static void printFactors() { for (int i=0;i<factors.size();i++) { System.out.print(factors.get(i) + " "); } 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
def primefactor(n): l = [] while n%2==0: l.append(2) n = n//2 for i in range(3,int(n**0.5)+1,2): if n % i == 0: l.append(i) n//=i if n>2: l.append(n) return l for _ in range(int(input())): n = primefactor(int(input())) l = [] if len(n)==3: if len(set(n))==3: print("YES") print(*n) else: print("NO") elif len(n)>3: if n[0]==n[1]: l.append(n[0]) l.append(n[1]*n[2]) c=1 for i in range(3,len(n)): c *= n[i] l.append(c) if len(set(l))!=3: print("NO") else: print("YES") print(*l) else: l.append(n[0]) l.append(n[1]) c=1 for i in range(2,len(n)): c *= n[i] l.append(c) if len(set(l))!=3: print("NO") else: print("YES") print(*l) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int a[]=new int [(int)5e4+10]; ArrayList<Integer> al=new ArrayList<Integer>(); Arrays.fill(a,1); for(int i=2;i<a.length;i++) { if(a[i]==1) { for(int j=2*i;j<a.length;j+=i) a[j]=0; al.add(i); } } int t=sc.nextInt(); while(t-->0) { int n=sc.nextInt(); int g=0,ans=0; for(int i=0;al.get(i)<=Math.sqrt(n);i++) { if(n%al.get(i)==0) {ans=al.get(i);n/=ans;break;} } if(ans==0) {System.out.println("NO");continue;} for(int i=2;i<=Math.sqrt(n);i++) { if(i==ans) continue; if(n%i==0&&n/i!=i&&n/i!=ans) { System.out.println("YES\n"+ans+" "+i+" "+(n/i)); g=1; break; } } if(g==0) 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
import math t=int(input()) for _ in range(t): n=int(input()) n_root=int(math.sqrt(n)) ans=[] count=0 for i in range(2,n_root+1): if n%i==0: ans.append(i) count+=1 n//=i if count==2 and n>ans[-1]: count+=1 ans.append(n) break if count==3: print("YES") print(*ans) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math for _ in range(int(input())): n=(int(input())) f=0 s=0 k=0 if(n<24): f=1 else: for i in range(2,int(math.sqrt(n))+1): if(n%i==0): f=0 k=i break if(k==int(math.sqrt(n))): f=1 #print(f) if(n>=24 and f==0): f=1 for i in range(2,int(math.sqrt(n))+1): if(n%i==0): x=n//i a=i #print(x,i) for j in range(2,int(math.sqrt(x))+1): b=j c=x//j if(x%j==0): if(a!=b and b!=c and c!=a): f=0 #print(a,b,c) break if(f==0): break #print(f) if(f==0): 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 java.io.PrintWriter; import java.util.*; public class TP { public static PrintWriter out = new PrintWriter(System.out); public static Scanner in = new Scanner(System.in); public static void main(String[] args) { long s = System.currentTimeMillis(); int t = 1; t = ni(); while (t-- > 0) solve(); out.flush(); tr(System.currentTimeMillis() - s + "ms"); } private static void solve() { int n = ni(); Set<Integer> set = new HashSet<>(); int i = 0; int N = n; for (int d = 2; d * d <= n; d++) { if (n % d == 0) { set.add(d); n /= d; if (set.size() >= 2) break; } } set.add(n); if (set.size() == 3) { System.out.println("yes"); set.forEach((I) -> System.out.print(I + " ")); System.out.println(); } else System.out.println("no"); } static boolean isPrime(int n) { for (int i = 2; i * i <= n; i++) if (n % i == 0) return false; return true; } static boolean sorted(int[] a) { for (int i = 0; i < a.length - 1; i++) { if (a[i] > a[i + 1]) return false; } return true; } public static int gcd(int a, int b) { while (b != 0) { a %= b; int t = a; a = b; b = t; } return a; } private static int ni() { return in.nextInt(); } private static int[] na(int n) { int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = ni(); return a; } private static long[] nal(int n) { long[] a = new long[n]; for (int i = 0; i < n; i++) a[i] = nl(); return a; } private static long nl() { return in.nextLong(); } private float nf() { return in.nextFloat(); } private static double nd() { return in.nextDouble(); } public static int[] facs(int n, int[] primes) { int[] ret = new int[9]; int rp = 0; for (int p : primes) { if (p * p > n) break; int i; i = 0; while (n % p == 0) { n /= p; i++; } if (i > 0) ret[rp++] = p; } if (n != 1) ret[rp++] = n; return Arrays.copyOf(ret, rp); } public static int[] sieveEratosthenes(int n) { if (n <= 32) { int[] primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; for (int i = 0; i < primes.length; i++) { if (n < primes[i]) { return Arrays.copyOf(primes, i); } } return primes; } int u = n + 32; double lu = Math.log(u); int[] ret = new int[(int) (u / lu + u / lu / lu * 1.5)]; ret[0] = 2; int pos = 1; int[] isnp = new int[(n + 1) / 32 / 2 + 1]; int sup = (n + 1) / 32 / 2 + 1; int[] tprimes = {3, 5, 7, 11, 13, 17, 19, 23, 29, 31}; for (int tp : tprimes) { ret[pos++] = tp; int[] ptn = new int[tp]; for (int i = (tp - 3) / 2; i < tp << 5; i += tp) ptn[i >> 5] |= 1 << (i & 31); for (int j = 0; j < sup; j += tp) { for (int i = 0; i < tp && i + j < sup; i++) { isnp[j + i] |= ptn[i]; } } } // 3,5,7 // 2x+3=n int[] magic = { 0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, 31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 }; int h = n / 2; for (int i = 0; i < sup; i++) { for (int j = ~isnp[i]; j != 0; j &= j - 1) { int pp = i << 5 | magic[(j & -j) * 0x076be629 >>> 27]; int p = 2 * pp + 3; if (p > n) break; ret[pos++] = p; if ((long) p * p > n) continue; for (int q = (p * p - 3) / 2; q <= h; q += p) isnp[q >> 5] |= 1 << q; } } return Arrays.copyOf(ret, pos); } private static boolean oj = System.getProperty("ONLINE_JUDGE") != null; private static void tr(Object... o) { if (!oj) System.out.println(Arrays.deepToString(o)); } }
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 pro(j): for a in range(2,int(j**(1/3))+1): if j%a==0: for b in range(a+1,int(j**(1/2))): if (j//a)%b==0 and (j//a)//b!=a and ((j//a)//b)!=int((j//a)**(1/2)): print("YES") print(a,b,(j//a)//b) return print("NO") return t=int(input()) l=[] for i in range(t): n=int(input()) l.append(n) for j in l: pro(j)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; public class ProductOfThreeNumbers{ public static void main(String args[]){ Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++){ long n=sc.nextLong(); long arr[]=new long[3]; int c=0; for(int j=2;j<=Math.sqrt(n);j++){ if(n%j==0){ arr[c++]=j;n/=j; } if(c==2){arr[c++]=n;break;} } if(c==3&&arr[0]!=arr[2]&&arr[1]!=arr[2])System.out.println("Yes\n"+arr[0]+" "+arr[1]+" "+arr[2]); else System.out.println("NO"); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def main(): n = int(input()) a = 2 while a * a * a < n: if n % a == 0: b = a + 1 while b * b < n // a: if (n // a) % b == 0: c = n // a // b if a != c and b != c: print("YES") print(a, b, n // a // b) return 0 b += 1 a += 1 print("NO") p = int(input()) for i in range(p): main()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def factor(n): ans=[] d=2 while d*d<=n: if n%d==0: ans.append(d) n=n//d else: d+=1 if n>1: ans.append(n) return ans t=int(input()) for i in range(t): n=int(input()) ans=factor(n) if len(ans)<3: print("NO") else: a=ans[0] b=1 c=1 for i in range(1,len(ans)): if b<=a: b*=ans[i] else: c*=ans[i] if c==1 or c==a or c==b: print('NO') else: print("YES") print(a,b,c)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n = int(input()) c = 0 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
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> v; for (int i = 2; i <= sqrt(n); i++) { while (n % i == 0) { v.push_back(i); n /= i; } } if (n > 1) v.push_back(n); set<int> s; int cur = 1; for (auto it : v) { cur = cur * it; if (s.size() <= 1 && s.find(cur) == s.end()) { s.insert(cur); cur = 1; } } if (cur == 1 || s.find(cur) != s.end()) { cout << "NO\n"; } else { s.insert(cur); cout << "YES\n"; for (auto it : s) cout << it << " "; cout << "\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 def de(m): ret = [] n = m for i in range(2,int(math.sqrt(n))+1): while n%i == 0: ret.append(i) n/= i if n!= 1: ret.append(n) return ret def solve(n): lst = de(n) args = list(set(lst)) if len(args) >= 3: print "YES" print args[0],args[1],n/args[0]/args[1] elif len(args) == 2: if len(lst)<=3: print "NO" else: print "YES" print args[0],args[1],n/args[0]/args[1] elif len(args) == 1: if len(lst) >= 6: print "YES" print args[0],args[0]*args[0],n/args[0]/args[0]/args[0] else: print 'NO' t = input() for _ in range(t): solve(input())
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
n=int(input()) for i in range(n): num=int(input()) list1=[] j=2 while(j*j<num and len(list1)<2): if(num%j==0): num=num//j list1.append(j) j+=1 if(len(list1)==2 and num not in list1): print("YES") for k in list1: print(k,end=" ") print(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
''' Hey stalker :) ''' INF = 10**10 def main(): #print = out.append ''' Cook your dish here! ''' n = get_int() factors = prime_factors(n) keys = list(factors.keys()) if len(factors)>=2: a, b = keys[:2] c = n // (a * b) if c==a or c==b or c<2: print("NO") return else: if factors[keys[0]]>5: a = keys[0] b = keys[0]**2 else: print("NO") return c = n // (a * b) print("YES") print(a,b,c) def prime_factors(n): # n**0.5 complex factors = dict() for i in range(2, math.ceil(math.sqrt(n)) + 1): while n % i == 0: if i in factors: factors[i] += 1 else: factors[i] = 1 n = n // i if n > 2: factors[n] = 1 return (factors) ''' Pythonista fLite 1.1 ''' import sys from collections import defaultdict, Counter from bisect import bisect_left, bisect_right #from functools import reduce import math input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__ out = [] get_int = lambda: int(input()) get_list = lambda: list(map(int, input().split())) #main() [main() for _ in range(int(input()))] print(*out, sep='\n')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; void fastIo() { ios_base::sync_with_stdio(false); cin.tie(NULL); } const long long N = 100000; bitset<N + 5> p; vector<long long> primes; void spf() { primes.push_back(2); for (int i = 4; i <= N; i += 2) p[i] = 1; for (long long i = 3; i <= N; i += 2) { if (p[i] == 0) { primes.push_back(i); for (long long j = i * i; j <= N; j += i) p[j] = 1; } } } vector<long long> factorise(long long n) { vector<long long> ans; for (long long i = 0; primes[i] * primes[i] <= n; i++) { if (n % primes[i] == 0) { while (n % primes[i] == 0) { ans.push_back(primes[i]); n /= primes[i]; } } } if (n != 1) ans.push_back(n); return ans; } void solve() { long long n; cin >> n; vector<long long> ans = factorise(n); if (ans.size() < 3) { cout << "NO\n"; return; } long long a = ans[0], b = ans[1], c = 1, s = 1; if (a == b && ans.size() >= 4) b *= ans[2], s = 2; else if (a == b) { cout << "NO\n"; return; } for (int i = s + 1; i < ans.size(); i++) c *= ans[i]; if (c == 1 || c == a || c == b) { cout << "NO\n"; return; } cout << "YES\n" << a << " " << b << " " << c << endl; } int main() { spf(); fastIo(); 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
''' 5 64 32 97 2 12345 ''' def mi(): return map(int, input().split()) for _ in range(int(input())): n = int(input()) i = 2 found=0 while i*i<=n: if (n % i == 0): n1 = n//i j=2 comp=0 while j*j<=n1: if n1%j==0: comp=1 if i==n1//j or i==j or (n1//j==j) or n//j==1 or j==1: j+=1 continue else: if found or n1//j==1 or j==1: break found = 1 print('YES') print(i,n1//j,j) j+=1 i+=1 if not found: print ('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for _ in range(int(input())): n=int(input()) ans=[] for i in range(2,n): if i*i>=n: break if n%i==0: ans.append(i) n//=i if len(ans)==2: ans.append(n) break if len(ans)==3: print('YES') print(*ans) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.PrintWriter; import java.util.Scanner; public class ProductOfThreeNumbers { public static Scanner sc = new Scanner(System.in); public static PrintWriter out = new PrintWriter(System.out, true); public static int n; public static void Input() { n = sc.nextInt(); } public static int smallestDivisor(int x, int min) { int ans=0; for (int i=min; i*i<=x; i++) { if (x % i == 0) { ans=i; break; } } return ans; } public static void Solve() { int a=smallestDivisor(n, 2); if (a>=n || a==0) {System.out.println("NO"); return;} int b=0; int min=2; while (true) { b=smallestDivisor(n/a, min); if (b>=n/a || b==0) {System.out.println("NO"); return;} if (b>0 && b!=a) {break;} min=b+1; } int c = n/a/b; if (c==a || c==b) {System.out.println("NO"); return;} System.out.println("YES"); System.out.println(a + " " + b + " " + c); } public static void main(String[] args) { int t = sc.nextInt(); while (t-- > 0) {Input(); Solve();} } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin def Prime(d, n): if n%d == 0: return d while d * d <= n: if n % d == 0: return d d= d + 1 return 0 for _ in range(int(stdin.readline())): n = int(stdin.readline()) if n < 24 : print("NO") continue ans = [] count = 0 cond = True d = 2 while(count<2): m = Prime(d, n) if m == 0: cond = False break else: ans.append(m) count += 1 n = n//m d = m+1 if cond == True: if n in ans: print("NO") else: ans.append(n) print("YES") print(*ans) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys 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 #print(fac) if len(fac)!=0: x=fac[0][1] flag=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) flag=0 break if flag: 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; int main() { int t; cin >> t; for (int g = 0; g < t; ++g) { int n; cin >> n; vector<int> v; for (int i = 2; i <= int(sqrt(n)); ++i) { if (n % i == 0) { v.push_back(i); v.push_back(n / i); } } bool T = false; for (int i = 0; i < v.size(); ++i) { for (int j = i + 1; j < v.size(); ++j) { for (int k = j + 1; k < v.size(); ++k) { if (v[i] * v[j] * v[k] == n) { cout << "YES" << '\n' << v[i] << ' ' << v[j] << ' ' << v[k] << '\n'; T = true; break; } } if (T) break; } if (T) break; } if (!T) 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
/* javac c.java && java c */ import java.io.*; import java.util.*; public class c { public static void main(String[] args) { new c(); } FS in = new FS(); PrintWriter out = new PrintWriter(System.out); int t; int n; c() { t = in.nextInt(); while (t-- > 0) { n = in.nextInt(); int[] ans = new int[3]; int lp = 2; boolean found = false; for (; lp * lp <= n; lp++) { if (n %lp == 0) { found = true; n /= lp; ans[0] = lp; break; } } if (!found) { out.println("NO"); } else { int nlp = ans[0] + 1; found = false; for (; nlp * nlp <= n; nlp++) if (n %nlp == 0) { found = true; n /= nlp; ans[1] = nlp; break; } if (!found) out.println("NO"); else { if (n < 2 || n == nlp) out.println("NO"); else { out.println("YES"); out.println(ans[0] + " " + ans[1] + " " + n); } } } } out.close(); } int abs(int x) { if (x < 0) return -x; return x; } long abs(long x) { if (x < 0) return -x; return x; } int min(int a, int b) { if (a < b) return a; return b; } int max(int a, int b) { if (a > b) return a; return b; } long min(long a, long b) { if (a < b) return a; return b; } long max(long a, long b) { if (a > b) return a; return b; } int gcd(int a, int b) { while (b > 0) { a = b^(a^(b = a)); b %= a; } return a; } long gcd(long a, long b) { while (b > 0) { a = b^(a^(b = a)); b %= a; } return a; } long lcm(int a, int b) { return (((long) a) * b) / gcd(a, b); } long lcm(long a, long b) { return (a * b) / gcd(a, b); } void sort(int[] arr) { int sz = arr.length, j; Random r = new Random(); for (int i = 0; i < sz; i++) { j = r.nextInt(i + 1); arr[i] = arr[j]^(arr[i]^(arr[j] = arr[i])); } Arrays.sort(arr); } class FS { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String next() { while (!st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) {} } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def isPrime(n): if n == 2 or n == 3: return True if n % 2 == 0 or n < 2: return False for i in range(3, int(n ** 0.5) + 1, 2): if n % i == 0: return False return True t = int(input()) for _ in range(t): f = 0 n = int(input()) if isPrime(n): print("NO") continue for i in range(2, int(n ** 0.5) + 1): if n % i == 0: if not isPrime(n // i): m = n // i for j in range(2, int(m ** 0.5) + 1): if m % j == 0 and i != j != (m // j) != i: print("YES") print(i, j, m // j) f = 1 break if f: break if not f: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t=int(input()) for q in range(t): n=int(input()) c=[] i=2 while len(c)<2 and i*i<n: if n%i==0: c.append(i) n=n/i i=i+1 if len(c)==2 and n not in c: print("YES") print(*c,int(n)) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; long long ans[3]; int main() { int t; cin >> t; long long n; for (int o = 0; o < t; o++) { cin >> n; vector<long long> z; long long r = sqrt(n) + 1; for (long long i = 2; i <= r; i++) { { while (n % i == 0) { n /= i; z.push_back(i); } } } if (n != 1) { z.push_back(n); } long long prev = 1; set<long long> anses; for (auto x : z) { prev *= x; if (anses.size() >= 3) { ans[2] *= x; continue; } if (anses.find(prev) == anses.end()) { anses.insert(prev); ans[anses.size() - 1] = prev; prev = 1; } } if (anses.size() >= 3) { cout << "YES" << endl; cout << ans[0] << " " << ans[1] << " " << ans[2] << endl; } else { cout << "NO" << endl; } z.clear(); } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math t = int(input()) for i in range(t): n = int(input()) q = int( math.sqrt(n)) l = set() for j in range(2, q + 1): if n % j == 0: l.add(j) if len(l) < 2: print('NO') else: l = sorted(list(l)) res = False for k in range(len(l) - 1): for p in range(k + 1, len(l)): a = l[k] b = l[p] c = (n // a )// b if a * b * c == n and b != c and a != c: res = True print("YES") print(str(a) + ' ' + str(b) + ' ' + str(c)) break if res: break if not res: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from collections import defaultdict for _ in range(int(input())): n = int(input()) dr = n i = 2 primes = defaultdict(int) while i * i <= n: while dr % i == 0: primes[i] += 1 dr //= i i += 1 if dr != 1: primes[dr] += 1 if len(primes) >= 3: print("YES") i = 0 for par in primes: print(par, end=" ") n //= par i += 1 if i == 2: break print(n) elif len(primes) == 2: primes = [(k, v) for k, v in primes.items()] if primes[0][1] == 1: if primes[1][1] <= 2: print("NO") continue else: print("YES") print(primes[0][0], primes[1][0], n // (primes[0][0] * primes[1][0])) elif primes[1][1] == 1: if primes[0][1] <= 2: print("NO") continue else: print("YES") print(primes[0][0], primes[1][0], n // (primes[0][0] * primes[1][0])) else: print("YES") print(primes[0][0], primes[1][0], n // (primes[0][0] * primes[1][0])) else: primes = [(k, v) for k, v in primes.items()] primes = primes[0] if primes[1] >= 6: print("YES") print(primes[0], primes[0] ** 2, n // (primes[0] ** 3)) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math def primes(n): while n % 2 == 0: prime.append(2) n = n / 2 for i in range(3, int(math.sqrt(n)) + 1, 2): while n % i == 0: prime.append(i) n = n / i if n > 2: prime.append(int(n)) t=int(input()) for _ in range(t): n=int(input()) prime=[] primes(n) p={} for i in prime: if i in p.keys(): p[i]+=1 else: p[i]=1 g=list(p.keys()) if len(g)==1: if p[g[0]]>=6: print("YES") p1=p[g[0]]-2 print(g[0],g[0]**2,g[0]**(p[g[0]]-3)) else: print("NO") continue if len(g)==2: if p[g[0]]+p[g[1]]>3: print("YES") n1 = g[0] n2 = g[1] p1 = p[g[0]] p2 = p[g[1]] print(n1, n2, (pow(n1, p1 - 1) * pow(n2, p2 - 1))) else: print("NO") else: print("YES") ans=pow(g[0],p[g[0]]-1)*pow(g[1],p[g[1]]-1) for i in range(2,len(g)): ans*=pow(g[i],p[g[i]]) print(g[0],g[1],ans)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.*; public class CodeForces1294C{ public static void main(String[] args) { Scanner input = new Scanner(System.in); int t = input.nextInt(); for(int j = 0;j<t;j++){ int n = input.nextInt(); ArrayList<Integer> arr = new ArrayList<>(); int m = n; for(int i = 2;i<=Math.sqrt(m);i++){ if(n%i == 0){ if(arr.size() == 2){ break; } arr.add(i); n/= i; } } if(arr.size() < 2 || arr.contains(n)){ System.out.println("NO"); } else{ System.out.println("YES"); System.out.println(arr.get(0) + " " + arr.get(1) + " " + n); } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import floor, sqrt, ceil def findPrimeFac(num): ans = [] lim = ceil(sqrt(num)) while num % 2 == 0: ans.append(2) num //= 2 for p in range(3, lim, 2): while num % p == 0: ans.append(p) num //= p if num != 1: ans.append(num) return ans t = int(input()) for _ in range(t): n = int(input()) primeFacs = findPrimeFac(n) #print(primeFacs) freq = {} for p in primeFacs: if p not in freq: freq[p] = 0 freq[p] += 1 numDist = 0 ans = [] l = list(freq.keys()) if len(l) >= 2: a = l[0] b = l[1] c = n // (a * b) if c != a and c != b and c != 1: print("YES") assert n == a*b*c print(a, b, c) else: print("NO") elif len(l) == 0 or freq[l[0]] < 6: print("NO") else: print("YES") p = l[0] print(p, p*p, n//(p ** 3))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt def szuk_podz(liczba, a = 1): for x in range(2, int(sqrt(liczba)) + 1): if liczba % x == 0 and x != a: return x return -1 for _ in range(int(input())): n = int(input()) a, b, c = szuk_podz(n), 0, 0 x = n // a if a == -1: print("NO") continue b = szuk_podz(x, a) c = x // b if c == a or c == b: print("NO") continue if c > 0 and b > 0: 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()) for kek in range(t): n = int(input()) i = 2 s = list() while i < n ** (1 / 2) + 1: if n % i == 0: s.append(i) n //= i else: i += 1 if n != 1: s.append(n) a = list() a.append(s[0]) x = 1 for i in range(1, len(s)): x *= s[i] if x not in a: a.append(x) x = 1 else: continue a[-1] *= x if len(a) >= 3: x = 1 for i in range(2, len(a)): x *= a[i] print('YES') print(a[0], a[1], 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
t = int(input()) for _ in range(t): out = [] n = int(input()) d = 2 while d * d <= n: if n % d == 0: out.append(d) n //= d if len(out) == 2: break d += 1 if len(out) == 2 and n > out[1]: print("YES") print(out[0], out[1], n) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t=int(input()) for xyz in range(t): n=int(input()) a=[] fa=1 p=n i=2 while(i*i<=p): if p%i==0 and i not in a: a.append(i) p=p/i break i=i+1 while(i*i<=p): if p%i==0 and i not in a: a.append(i) p=p/i break i=i+1 l=len(a) if l==0: print('NO') if l==1: f=a[0] s=a[0]*a[0] t=n//(f*s) if f*s*t==n and f!=s and s!=t and t!=f and t>1: print('YES') print(f,s,t) else: print('NO') if l==2: f=min(a) c=a.copy() for i in c: if i==f: c.remove(i) s=min(c) t=n//(f*s) if f*s*t==n and f!=s and s!=t and t!=f and t>1: print('YES') print(f,s,t) else: print('NO') if l>=3: f=min(a) c=a.copy() for i in c: if i==f: c.remove(i) s=min(c) t=n//(f*s) print('YES') print(f,s,t)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import os,sys,math,random def dep(a): a0 = a res = [] for b in range(2, int(a**(1/3))+1): if a % b == 0: res.append(b) break if len(res) == 0: return "NO" a /= res[0] for b in range(2, int(a**(1/2))+1): if a % b == 0 and b != res[0]: res.append(b) break if len(res) == 1: return "NO" c = int(a0 / res[0] / res[1]) if c == 1 or c == res[0] or c == res[1]: return "NO" res.append(c) return "YES\n" + " ".join(map(str, res)) T = int(input()) for _ in range(T): a = int(input()) print(dep(a))
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from collections import defaultdict import math def prime(n): ans=[] al=defaultdict(int) while(n%2==0): al[2]=al[2]+1 ans.append(2) n=n//2 for i in range(3,int(math.sqrt(n))+1,2): while(n%i==0): al[i]+=1 ans.append(i) n=n//i if(n>2): al[n]=1 ans.append(n) ans=list(set(ans)) return ans,al; t=int(input()) for i in range(t): n=int(input()) ans,al=prime(n) if(len(ans)>=3): print('YES') a=ans[0]**al[ans[0]] b=ans[1]**al[ans[1]] c=n//(a*b) print(a,b,c) elif(len(ans)==2): if(al[ans[0]]+al[ans[1]]>=4): a=ans[0] b=ans[1] c=n//(a*b) print('YES') print(a,b,c) else: print('NO') else: if(al[ans[0]]>5): print('YES') a=ans[0]*ans[0] b=ans[0] c=n//(a*b) 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
# Enter your code here. Read input from STDIN. Print output to STDOUT# =============================================================================================== # importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io import BytesIO, IOBase from itertools import * import bisect from heapq import * from math import ceil, floor from copy import * from collections import deque, defaultdict from collections import Counter as counter # Counter(list) return a dict with {key: count} from itertools import combinations # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)] from itertools import permutations as permutate from bisect import bisect_left as bl from operator import * # If the element is already present in the list, # the left most position where element has to be inserted is returned. from bisect import bisect_right as br from bisect import bisect # If the element is already present in the list, # the right most position where element has to be inserted is returned # ============================================================================================== # fast I/O region BUFSIZE = 8192 from sys import stderr 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) # inp = lambda: sys.stdin.readline().rstrip("\r\n") # =============================================================================================== ### START ITERATE RECURSION ### from types import GeneratorType def iterative(f, stack=[]): def wrapped_func(*args, **kwargs): if stack: return f(*args, **kwargs) to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) continue stack.pop() if not stack: break to = stack[-1].send(to) return to return wrapped_func #### END ITERATE RECURSION #### ########################### # Sorted list class SortedList: def __init__(self, iterable=[], _load=200): """Initialize sorted list instance.""" values = sorted(iterable) self._len = _len = len(values) self._load = _load self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)] self._list_lens = [len(_list) for _list in _lists] self._mins = [_list[0] for _list in _lists] self._fen_tree = [] self._rebuild = True def _fen_build(self): """Build a fenwick tree instance.""" self._fen_tree[:] = self._list_lens _fen_tree = self._fen_tree for i in range(len(_fen_tree)): if i | i + 1 < len(_fen_tree): _fen_tree[i | i + 1] += _fen_tree[i] self._rebuild = False def _fen_update(self, index, value): """Update `fen_tree[index] += value`.""" if not self._rebuild: _fen_tree = self._fen_tree while index < len(_fen_tree): _fen_tree[index] += value index |= index + 1 def _fen_query(self, end): """Return `sum(_fen_tree[:end])`.""" if self._rebuild: self._fen_build() _fen_tree = self._fen_tree x = 0 while end: x += _fen_tree[end - 1] end &= end - 1 return x def _fen_findkth(self, k): """Return a pair of (the largest `idx` such that `sum(_fen_tree[:idx]) <= k`, `k - sum(_fen_tree[:idx])`).""" _list_lens = self._list_lens if k < _list_lens[0]: return 0, k if k >= self._len - _list_lens[-1]: return len(_list_lens) - 1, k + _list_lens[-1] - self._len if self._rebuild: self._fen_build() _fen_tree = self._fen_tree idx = -1 for d in reversed(range(len(_fen_tree).bit_length())): right_idx = idx + (1 << d) if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]: idx = right_idx k -= _fen_tree[idx] return idx + 1, k def _delete(self, pos, idx): """Delete value at the given `(pos, idx)`.""" _lists = self._lists _mins = self._mins _list_lens = self._list_lens self._len -= 1 self._fen_update(pos, -1) del _lists[pos][idx] _list_lens[pos] -= 1 if _list_lens[pos]: _mins[pos] = _lists[pos][0] else: del _lists[pos] del _list_lens[pos] del _mins[pos] self._rebuild = True def _loc_left(self, value): """Return an index pair that corresponds to the first position of `value` in the sorted list.""" if not self._len: return 0, 0 _lists = self._lists _mins = self._mins lo, pos = -1, len(_lists) - 1 while lo + 1 < pos: mi = (lo + pos) >> 1 if value <= _mins[mi]: pos = mi else: lo = mi if pos and value <= _lists[pos - 1][-1]: pos -= 1 _list = _lists[pos] lo, idx = -1, len(_list) while lo + 1 < idx: mi = (lo + idx) >> 1 if value <= _list[mi]: idx = mi else: lo = mi return pos, idx def _loc_right(self, value): """Return an index pair that corresponds to the last position of `value` in the sorted list.""" if not self._len: return 0, 0 _lists = self._lists _mins = self._mins pos, hi = 0, len(_lists) while pos + 1 < hi: mi = (pos + hi) >> 1 if value < _mins[mi]: hi = mi else: pos = mi _list = _lists[pos] lo, idx = -1, len(_list) while lo + 1 < idx: mi = (lo + idx) >> 1 if value < _list[mi]: idx = mi else: lo = mi return pos, idx def add(self, value): """Add `value` to sorted list.""" _load = self._load _lists = self._lists _mins = self._mins _list_lens = self._list_lens self._len += 1 if _lists: pos, idx = self._loc_right(value) self._fen_update(pos, 1) _list = _lists[pos] _list.insert(idx, value) _list_lens[pos] += 1 _mins[pos] = _list[0] if _load + _load < len(_list): _lists.insert(pos + 1, _list[_load:]) _list_lens.insert(pos + 1, len(_list) - _load) _mins.insert(pos + 1, _list[_load]) _list_lens[pos] = _load del _list[_load:] self._rebuild = True else: _lists.append([value]) _mins.append(value) _list_lens.append(1) self._rebuild = True def discard(self, value): """Remove `value` from sorted list if it is a member.""" _lists = self._lists if _lists: pos, idx = self._loc_right(value) if idx and _lists[pos][idx - 1] == value: self._delete(pos, idx - 1) def remove(self, value): """Remove `value` from sorted list; `value` must be a member.""" _len = self._len self.discard(value) if _len == self._len: raise ValueError('{0!r} not in list'.format(value)) def pop(self, index=-1): """Remove and return value at `index` in sorted list.""" pos, idx = self._fen_findkth(self._len + index if index < 0 else index) value = self._lists[pos][idx] self._delete(pos, idx) return value def bisect_left(self, value): """Return the first index to insert `value` in the sorted list.""" pos, idx = self._loc_left(value) return self._fen_query(pos) + idx def bisect_right(self, value): """Return the last index to insert `value` in the sorted list.""" pos, idx = self._loc_right(value) return self._fen_query(pos) + idx def count(self, value): """Return number of occurrences of `value` in the sorted list.""" return self.bisect_right(value) - self.bisect_left(value) def __len__(self): """Return the size of the sorted list.""" return self._len def __getitem__(self, index): """Lookup value at `index` in sorted list.""" pos, idx = self._fen_findkth(self._len + index if index < 0 else index) return self._lists[pos][idx] def __delitem__(self, index): """Remove value at `index` from sorted list.""" pos, idx = self._fen_findkth(self._len + index if index < 0 else index) self._delete(pos, idx) def __contains__(self, value): """Return true if `value` is an element of the sorted list.""" _lists = self._lists if _lists: pos, idx = self._loc_left(value) return idx < len(_lists[pos]) and _lists[pos][idx] == value return False def __iter__(self): """Return an iterator over the sorted list.""" return (value for _list in self._lists for value in _list) def __reversed__(self): """Return a reverse iterator over the sorted list.""" return (value for _list in reversed(self._lists) for value in reversed(_list)) def __repr__(self): """Return string representation of sorted list.""" return 'SortedList({0})'.format(list(self)) # =============================================================================================== # some shortcuts mod = 1000000007 def testcase(t): for p in range(t): solve() def pow(x, y, p): res = 1 # Initialize result x = x % p # Update x if it is more , than or equal to p if (x == 0): return 0 while (y > 0): if ((y & 1) == 1): # If y is odd, multiply, x with result res = (res * x) % p y = y >> 1 # y = y/2 x = (x * x) % p return res from functools import reduce def factors(n): return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))) def gcd(a, b): if a == b: return a while b > 0: a, b = b, a % b return a # discrete binary search # minimise: # def search(): # l = 0 # r = 10 ** 15 # # for i in range(200): # if isvalid(l): # return l # if l == r: # return l # m = (l + r) // 2 # if isvalid(m) and not isvalid(m - 1): # return m # if isvalid(m): # r = m + 1 # else: # l = m # return m # maximise: # def search(): # l = 0 # r = 10 ** 15 # # for i in range(200): # # print(l,r) # if isvalid(r): # return r # if l == r: # return l # m = (l + r) // 2 # if isvalid(m) and not isvalid(m + 1): # return m # if isvalid(m): # l = m # else: # r = m - 1 # return m ##############Find sum of product of subsets of size k in a array # ar=[0,1,2,3] # k=3 # n=len(ar)-1 # dp=[0]*(n+1) # dp[0]=1 # for pos in range(1,n+1): # dp[pos]=0 # l=max(1,k+pos-n-1) # for j in range(min(pos,k),l-1,-1): # dp[j]=dp[j]+ar[pos]*dp[j-1] # print(dp[k]) def prefix_sum(ar): # [1,2,3,4]->[1,3,6,10] return list(accumulate(ar)) def suffix_sum(ar): # [1,2,3,4]->[10,9,7,4] return list(accumulate(ar[::-1]))[::-1] def N(): return int(inp()) dx = [0, 0, 1, -1] dy = [1, -1, 0, 0] def YES(): print("YES") def NO(): print("NO") def Yes(): print("Yes") def No(): print("No") # ========================================================================================= from collections import defaultdict def numberOfSetBits(i): i = i - ((i >> 1) & 0x55555555) i = (i & 0x33333333) + ((i >> 2) & 0x33333333) return (((i + (i >> 4) & 0xF0F0F0F) * 0x1010101) & 0xffffffff) >> 24 class MergeFind: def __init__(self, n): self.parent = list(range(n)) self.size = [1] * n self.num_sets = n # self.lista = [[_] for _ in range(n)] def find(self, a): to_update = [] while a != self.parent[a]: to_update.append(a) a = self.parent[a] for b in to_update: self.parent[b] = a return self.parent[a] def merge(self, a, b): a = self.find(a) b = self.find(b) if a == b: return if self.size[a] < self.size[b]: a, b = b, a self.num_sets -= 1 self.parent[b] = a self.size[a] += self.size[b] # self.lista[a] += self.lista[b] # self.lista[b] = [] def set_size(self, a): return self.size[self.find(a)] def __len__(self): return self.num_sets def lcm(a, b): return abs((a // gcd(a, b)) * b) # # # to find factorial and ncr # tot = 100005 # mod = 10**9 + 7 # fac = [1, 1] # finv = [1, 1] # inv = [0, 1] # # for i in range(2, tot + 1): # fac.append((fac[-1] * i) % mod) # inv.append(mod - (inv[mod % i] * (mod // i) % mod)) # finv.append(finv[-1] * inv[-1] % mod) def comb(n, r): if n < r: return 0 else: return fac[n] * (finv[r] * finv[n - r] % mod) % mod def inp(): return sys.stdin.readline().rstrip("\r\n") # for fast input def out(var): sys.stdout.write(str(var)) # for fast output, always take string def lis(): return list(map(int, inp().split())) def stringlis(): return list(map(str, inp().split())) def sep(): return map(int, inp().split()) def strsep(): return map(str, inp().split()) def fsep(): return map(float, inp().split()) def nextline(): out("\n") # as stdout.write always print sring. def arr1d(n, v): return [v] * n def arr2d(n, m, v): return [[v] * m for _ in range(n)] def arr3d(n, m, p, v): return [[[v] * p for _ in range(m)] for i in range(n)] def ceil(a, b): return (a + b - 1) // b # co-ordinate compression # ma={s:idx for idx,s in enumerate(sorted(set(l+r)))} # mxn=100005 # lrg=[0]*mxn # for i in range(2,mxn-3): # if (lrg[i]==0): # for j in range(i,mxn-3,i): # lrg[j]=i def solve(): m = N() c = 2 p = [] while len(p) < 2 and c * c < m: if m % c == 0: m = m // c p.append(c) c += 1 if len(p) == 2 and m not in p: print("YES") print(*(p+[m])) else: print("NO") # solve() testcase(int(inp()))
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
# -*- coding: utf-8 -*- """ Created on Wed Jan 22 18:45:17 2020 @author: npuja """ """ t=int(input()) for i in range(0,t): a,b,c,n=(int(k) for k in input().split()) mac=0 if a>=b and a>=c: mac=a elif b>=a and b>=c: mac=b else: mac=c test=n-3*(mac)+a+b+c if test<0 or test%3!=0: print("NO") else: print("YES") """ # Product of three no t=int(input()) for i in range(0,t): n=int(input()) l=int(n**(1/3)) a=1 for k in range(2,l+1): if n%k==0: a=k break b=1 c=1 if a==1: print("NO") else: m=n/a l=int(m**(1/2)) for k in range(a+1,l+1): if m%k==0: b=k c=int(m/b) break if a!=1 and b!=1 and c!=1 and c!=b: print("YES") print(a,b,c) else: print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.*; import java.math.*; import java.text.*; import java.util.*; public class Solution{ BufferedReader br; PrintWriter out; static String input[]; static int id = 0; public String next() throws Exception{ if(input == null || input.length == id){ input = br.readLine().split(" "); id=0; } return input[id++]; } public String ns() throws Exception{ return next(); } public int ni() throws Exception{ return Integer.parseInt(next()); } public long nl() throws Exception{ return Long.parseLong(next()); } public double nd() throws Exception{ return Double.parseDouble(next()); } public int[] na(int n) throws Exception{ int[] arr = new int[n]; for(int i=0;i<n;i++){ arr[i] = ni(); } return arr; } public void run() throws Exception{ br = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); int T=1; for(int t=1;t<=T;t++){ solve(); } out.flush(); } public static void main(String[] args) throws Exception{new Solution().run();} public void solve() throws Exception{ int[] spf = SPF(100000); ArrayList<Integer> primes = getPrimes(spf); int x = primes.size(); int T = ni(); for(int t=0;t<T;t++){ int n = ni(); int sqrt = (int)Math.sqrt(n); int a=1; int i=0; while(i<x && primes.get(i) <= sqrt){ if(n%primes.get(i) == 0){ a = primes.get(i); break; } i++; } if(a == 1){ out.println("NO"); continue; } n = n/a; i = a + 1; int b = 1; while(i <= sqrt){ if(n%i== 0){ b = i; if(n/b == a || b*b == n){ b=1; } break; } i++; } if(b==1){ out.println("NO"); continue; } out.println("YES"); out.println(a+" "+b+" "+n/b); } } ArrayList<Integer> getPrimes(int[] spf){ int n = spf.length; ArrayList<Integer> res = new ArrayList<Integer>(); res.add(2); for(int i=3; i<n; i+=2){ if(spf[i]==i) res.add(i); } return res; } public int[] SPF(int n){ int[] arr = new int[n+1]; for(int i=2;i<=n;i+=2){ arr[i] = 2; arr[i-1] = i-1; } for(int i=3;i*i <= n; i++){ if(arr[i]==i){ for(int j=i*i; j<=n; j+=i){ if(arr[j] == j){ arr[j]=i; } } } } return arr; } }
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 product_of_3_numbers(n): for i in range(2, int(n ** (1 / 2)) + 1): if n % i == 0: d = n // i for j in range(i + 1, int(d ** (1 / 2)) + 1): if d % j == 0 and j != d // j: print("YES") print(i, j, d // j) return print("NO") t = int(input()) for _ in range(t): n = int(input()) product_of_3_numbers(n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from sys import stdin from collections import deque from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin def ii(): return int(stdin.readline()) def fi(): return float(stdin.readline()) def mi(): return map(int, stdin.readline().split()) def fmi(): return map(float, stdin.readline().split()) def li(): return list(mi()) def lsi(): x=list(stdin.readline()) x.pop() return x def si(): return stdin.readline() def sieve(x): a=[True]*(x+1) sq=floor(sqrt(x)) for i in range(3, sq+1, 2): if a[i]: for j in range(i*i, x+1, i): a[j]=False if x>1: p=[2] else: p=[] for i in range(3, x+1, 2): if a[i]: p.append(i) return p #vowel={'a', 'e', 'i', 'o', 'u', 'y', 'A', 'E', 'I', 'O', 'U', 'Y'} #pow=[1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, 134217728, 268435456, 536870912, 1073741824, 2147483648, 4294967296, 8589934592, 17179869184, 34359738368, 68719476736, 137438953472, 274877906944, 549755813888, 1099511627776, 2199023255552, 4398046511104, 8796093022208, 17592186044416, 35184372088832, 70368744177664, 140737488355328, 281474976710656, 562949953421312, 1125899906842624, 2251799813685248, 4503599627370496, 9007199254740992, 18014398509481984, 36028797018963968, 72057594037927936, 144115188075855872, 288230376151711744, 576460752303423488, 1152921504606846976, 2305843009213693952, 4611686018427387904, 9223372036854775808] ############# CODE STARTS HERE ############# p=sieve(32000) for _ in range(ii()): z=ii() n=z a=[] i=0 while n>1: if not n%p[i]: n//=p[i] a.append(p[i]) else: i+=1 if p[i]**2>z: break if n>1: a.append(n) f=0 #print(a) if len(a)>2: ans=[a[0]] c=a[1] x=2 if c==ans[0]: c*=a[2] x=3 ans.append(c) c=1 if x<len(a): for i in a[x:]: c*=i if c!=ans[0] and c!=ans[1]: ans.append(c) ans.sort() f=1 if f: print('YES') print(*ans) else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from collections import defaultdict as dd from sys import stdin input=stdin.readline for _ in range(int(input())): n=int(input()) br=0 for i in range(2,int(n**.5)+1): fl=0 if n%i==0: fl=1 x=i for j in range(2,int(i**.5)+1): if i%j==0 and len(set([j,i//j,n//i]))==3: br=1 print('YES') print(j,i//j,n//i) break if br: break for j in range(2,int((n//i)**.5)+1): if (n//i)%j==0 and len(set([i,(n//i)//j,j]))==3: br=1 print('YES') print(i,(n//i)//j,j) break if br: break if br: continue else: print('NO')
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
for i in range(int(input())): n = int(input()) ans = [] o = 0 for i in range(2,int(n**0.5)+1): if n % i == 0: if n//i == i: continue ans.append(i) o = n//i break for i in range(2,int(o**0.5)+1): if o % i == 0: if i not in ans: if i == o//i: continue ans.append(i) ans.append(o//i) break if len(ans) == 3: print("YES") print(*ans) continue print("NO")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) def yes(factors): print('YES') print(' '.join(map(str, factors))) def no(): print('NO') for _ in range(t): temp = n = int(input()) factors = [] i = 2 found = False while(i <= pow(n, 1/2)): while(n % i == 0): if len(factors) == 0 or i not in factors[-1]: factors.append({i:1}) else: factors[-1][i] += 1 n //= i i += 1 if len(factors) >= 3: rv = [list(factors[0].keys())[0], list(factors[1].keys())[0]] temp //= rv[0] temp //= rv[1] rv.append(temp) yes(rv) elif len(factors) == 2: rv = [list(factors[0].keys())[0], list(factors[1].keys())[0]] temp //= rv[0] temp //= rv[1] if temp == rv[0] or temp == rv[1] or temp == 1: no() else: rv.append(temp) yes(rv) elif len(factors) == 1: factor = list(factors[0].keys())[0] if factors[0][factor] < 6: if(factors[0][factor] < 3): no() else: rv = [factor, factor*factor] temp //= rv[0] temp //= rv[1] if temp == rv[0] or temp == rv[1] or temp == 1: no() else: rv.append(temp) yes(rv) else: rv = [factor, factor*factor] temp //= rv[0] temp //= rv[1] rv.append(temp) yes(rv) else: no()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.util.ArrayList; import java.util.Scanner; /** * * @author DELL */ public class Codechef { public static void main(String[] args) { Scanner sc=new Scanner(System.in); int t=sc.nextInt(); for(int i=0;i<t;i++) { int n=sc.nextInt(); ArrayList<Integer> a=new ArrayList<>(); for(int j=2;j<=Math.sqrt(n);j++) { if(n%j==0) { if(n/j==j) { a.add(j); } else { a.add(j); a.add(n/j); } } } int flag=0; if(a.size()>=3) { for(int j=0;j<a.size()-2;j++) { for(int r=j+1;r<a.size()-1;r++) { for(int y=j+2;y<a.size();y++) { if(a.get(j)*a.get(r)*a.get(y)==n&&(a.get(j)!=(a.get(r)))&&(a.get(j)!=(a.get(y)))&&(a.get(y)!=a.get(r))) { System.out.println("YES"); System.out.println(a.get(j)+" "+a.get(r)+" "+a.get(y)); flag=1; break; } } if(flag==1) break; } if(flag==1) break; } } if(flag==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.util.*; import java.io.*; public class ProductofThreeNumbers { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); int T=Integer.parseInt(br.readLine()); while(T-->0) { int n=Integer.parseInt(br.readLine()); Set<Integer> st=new HashSet<>(); for(int i=2;i*i<=n;i++) { if(n%i==0 && st.add(i)) { n/=i; break; } } for(int i=2;i*i<=n;i++) { if(n%i==0 && st.add(i)) { n/=i; break; } } if(st.size()<2 || st.contains(n) || n==1) { System.out.println("NO"); } else { System.out.println("YES"); st.add(n); for(int i:st) System.out.print(i+" "); 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
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const long long inf = 5e18; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; int t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> a; for (long long i = 2; i <= min(100000ll, n); i++) { if (n % i == 0) { a.push_back(i); n /= i; if (a.size() == 2) { break; } } } if (a.size() < 2) { cout << "NO\n"; } else { vector<long long> ans; ans = a; ans.push_back(n); sort(ans.begin(), ans.end()); if (ans[1] == ans[2] or ans[0] == ans[1] or ans[0] < 2) { cout << "NO\n"; } else { cout << "YES\n"; for (long long i : ans) { cout << i << ' '; } cout << '\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 sys input = sys.stdin.readline def find(n,fa,fb): f = 2 while f*f <= n: if n % f == 0 and f != fa and f != fb: return f f += 1 return n for _ in xrange(int(input())): n = int(input()) nn = n fa = find(n,None,None) n = n // fa fb = find(n,fa, None) fc = nn // fa // fb if fa*fb*fc == nn and fa >= 2 and fb >= 2 and fc >= 2 and fa != fb and fa != fc and fb != fc: print("YES") print fa,fb,fc 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
def foo(num): isSimple = True k = 0 while k < arr.__len__() and arr[k] <= math.sqrt(num): if num % arr[k] == 0: isSimple = False num = num / arr[k] break k += 1 return num import math n = int(input()) arr = [] root = math.sqrt(1000000000) for num in range(2, int(root) + 1): isSimple = True for delimiter in range(2, int(math.sqrt(num)) + 1): if num % delimiter == 0: isSimple = False break if isSimple: arr.append(num) for i in range(n): num = int(input()) res = foo(num) if res == num: print("NO") continue else: d1 = num / res num = res res = foo(num) if res == num: print("NO") continue else: d2 = num / res num = res if d1 == d2: res = foo(num) if res == num: print("NO") continue d2 *= num / res num = res if d1 != num and d2 != num and d1 != d2: print("YES") print("%d %d %d" % (d1, d2, 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
#include <bits/stdc++.h> using namespace std; void solve(long long N) { vector<pair<long long, long long>> factors; long long n = N; for (long long i = 2; i * i <= n; i++) { long long cnt = 0; if (n % i == 0) { while (n % i == 0) { cnt++; n /= i; } factors.push_back({i, cnt}); } if (factors.size() == 3) break; } if (n != 1) { factors.push_back({n, 1}); } if (factors.size() >= 2) { long long a = factors[0].first; long long b = factors[1].first; long long c = N / (a * b); if (c != a and c != b and c > 1) { cout << "YES" << '\n'; cout << a << " " << b << " " << c << '\n'; } else cout << "NO" << '\n'; } else if (factors.size() == 1 and factors[0].second >= 6) { cout << "YES" << '\n'; long long a = factors[0].first; long long b = a * a; long long c = N / (a * b); cout << a << " " << b << " " << c << '\n'; } else cout << "NO" << '\n'; } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ; long long t; cin >> t; while (t--) { long long n; cin >> n; solve(n); } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int t = Integer.parseInt(in.readLine()); for(int rc=0; rc<t; rc++) { int n = Integer.parseInt(in.readLine()); int a = -1, b = -1, c = -1; int cur = 2; int div = 1; while(cur <= Math.sqrt(n)) { if(n%cur==0) { div *= cur; n /= cur; if(a == -1) { a = div; div = 1; } else if(b == -1 && div != a) { b = div; c = n; break; } } else cur++; } if(a != -1 && b != -1 && c != -1 && c != b && c != a) { System.out.println("YES\n"+a+" "+b+" "+c); } else { System.out.println("NO"); } } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]) + '\n') import math,datetime,functools from collections import deque,defaultdict,OrderedDict import collections def primeFactors(n): pf=[] # Print the number of two's that divide n while n % 2 == 0: pf.append(2) n = n / 2 # n must be odd at this point # so a skip of 2 ( i = i + 2) can be used for i in range(3,int(math.sqrt(n))+1,2): # while i divides n , print i ad divide n while n % i== 0: pf.append(int(i)) n = n /i # Condition if n is a prime # number greater than 2 if n > 2: pf.append(int(n)) return pf def main(): starttime=datetime.datetime.now() if(os.path.exists('input.txt')): sys.stdin = open("input.txt","r") sys.stdout = open("output.txt","w") #Solving Area Starts--> for _ in range(ri()): n=ri() a=primeFactors(n) amult=1 for i in range(1,len(a)-1): amult=amult*a[i] # print(a) t=0 if len(a)<3: print("NO") else: z=len((set(a))) if z>=3: print("YES") ans=[a[0],a[-1],amult] t=1 if z==2: if len(a)>=4: print("YES") ans=[a[0],a[-1],amult] t=1 if t==0: print("NO") if z==1: if len(a)>=6: print("YES") ans=[a[0],a[0]*2,n//(a[0]**3)] t=1 if t==0: print("NO") if t==1: print(*ans) #<--Solving Area Ends endtime=datetime.datetime.now() time=(endtime-starttime).total_seconds()*1000 if(os.path.exists('input.txt')): print("Time:",time,"ms") class FastReader(io.IOBase): newlines = 0 def __init__(self, fd, chunk_size=1024 * 8): self._fd = fd self._chunk_size = chunk_size self.buffer = io.BytesIO() def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size)) 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, size=-1): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size)) 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() class FastWriter(io.IOBase): def __init__(self, fd): self._fd = fd self.buffer = io.BytesIO() self.write = self.buffer.write def flush(self): os.write(self._fd, self.buffer.getvalue()) self.buffer.truncate(0), self.buffer.seek(0) class FastStdin(io.IOBase): def __init__(self, fd=0): self.buffer = FastReader(fd) self.read = lambda: self.buffer.read().decode("ascii") self.readline = lambda: self.buffer.readline().decode("ascii") class FastStdout(io.IOBase): def __init__(self, fd=1): self.buffer = FastWriter(fd) self.write = lambda s: self.buffer.write(s.encode("ascii")) self.flush = self.buffer.flush if __name__ == '__main__': sys.stdin = FastStdin() sys.stdout = FastStdout() main()
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.net.Inet4Address; import java.util.*; import java.lang.*; import java.util.HashMap; import java.util.PriorityQueue; public class Solution implements Runnable { static class pair implements Comparable { int f; int s; pair(int fi, int se) { f=fi; s=se; } public int compareTo(Object o)//desc order { pair pr=(pair)o; if(s>pr.s) return -1; if(s==pr.s) { if(f>pr.f) return 1; else return -1; } else return 1; } public boolean equals(Object o) { pair ob=(pair)o; if(o!=null) { if((ob.f==this.f)&&(ob.s==this.s)) return true; } return false; } public int hashCode() { return (this.f+" "+this.s).hashCode(); } } public class triplet implements Comparable { int f; int s; double t; triplet(int f,int s,double t) { this.f=f; this.s=s; this.t=t; } public boolean equals(Object o) { triplet ob=(triplet)o; int ff; int ss; double tt; if(o!=null) { ff=ob.f; ss=ob.s; tt=ob.t; if((ff==this.f)&&(ss==this.s)&&(tt==this.t)) return true; } return false; } public int hashCode() { return (this.f+" "+this.s+" "+this.t).hashCode(); } public int compareTo(Object o)//asc order { triplet tr=(triplet)o; if(t>tr.t) return 1; else return -1; } } void merge1(int arr[], int l, int m, int r) { int n1 = m - l + 1; int n2 = r - m; int L[] = new int [n1]; int R[] = new int [n2]; for (int i=0; i<n1; ++i) L[i] = arr[l + i]; for (int j=0; j<n2; ++j) R[j] = arr[m + 1+ j]; int i = 0, j = 0; int k = l; while (i < n1 && j < n2) { if (L[i]<=R[j]) { arr[k] = L[i]; i++; } else { arr[k] = R[j]; j++; } k++; } while (i < n1) { arr[k] = L[i]; i++; k++; } while (j < n2) { arr[k] = R[j]; j++; k++; } } void sort1(int arr[], int l, int r) { if (l < r) { int m = (l+r)/2; sort1(arr, l, m); sort1(arr , m+1, r); merge1(arr, l, m, r); } } public static void main(String args[])throws Exception { new Thread(null,new Solution(),"Solution",1<<27).start(); } public void run() { try { InputReader in = new InputReader(System.in); PrintWriter out = new PrintWriter(System.out); int t=in.ni(); while(t--!=0) { int n=in.ni(); int a=0,b=0,c=0; for(int i=2;i<=Math.sqrt(n);i++) { if(n%i==0) { a=i; n=n/i; break; } } for(int i=a+1;i<Math.sqrt(n);i++) { if(n%i==0) { b=i; c=n/i; break; } } if(a==0 || b==0 || c==0) out.println("NO"); else { out.println("YES"); out.println(a+" "+b+" "+c); } } out.close(); } catch(Exception e){ System.out.println(e); } } static class InputReader { private final InputStream stream; private final byte[] buf = new byte[8192]; private int curChar, snumChars; public InputReader(InputStream stream) { this.stream = stream; } public int read() { if (snumChars == -1) throw new InputMismatchException(); if (curChar >= snumChars) { curChar = 0; try { snumChars = stream.read(buf); } catch (IOException e) { throw new InputMismatchException(); } if (snumChars <= 0) return -1; } return buf[curChar++]; } public int ni() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } int res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public long nl() { int c = read(); while (isSpaceChar(c)) { c = read(); } int sgn = 1; if (c == '-') { sgn = -1; c = read(); } long res = 0; do { res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public int[] nextIntArray(int n) { int a[] = new int[n]; for (int i = 0; i < n; i++) { a[i] = ni(); } return a; } public String readString() { int c = read(); while (isSpaceChar(c)) { c = read(); } StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isSpaceChar(c)); return res.toString(); } public String nextLine() { int c = read(); while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); do { res.appendCodePoint(c); c = read(); } while (!isEndOfLine(c)); return res.toString(); } public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } private boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; } } }
JAVA
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import ceil, sqrt def main(): t = int(input()) while t: n = int(input()) findProd(n) t -= 1 def findProd(n): a = 2 found = 0 temp = n while a <= ceil(sqrt(n)): if n%a == 0: n = n // a b = a + 1 while b <= ceil(sqrt(n)): c = n//b if n%b == 0 and c > 1 and c != b and c != a : found = 1 print("YES") print(a), print(b), print(c) break else: b += 1 if found: break else: a += 1 if not found: print("NO") main()
PYTHON
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
#include <bits/stdc++.h> using namespace std; bool isPrime(int n) { for (int i = 2; i * i <= n; i++) { if (n % i == 0) return false; } return true; } int main() { int tc; cin >> tc; while (tc--) { int n; cin >> n; if (isPrime(n)) { cout << "NO" << endl; } else { vector<int> factores; for (int i = 2; i * i <= n; i++) { if (n % i == 0) { if (factores.size() == 0) factores.push_back(i); else if (i > factores.back()) factores.push_back(i); n /= i; } } if (n > 2) factores.push_back(n); if (factores.size() < 3) { cout << "NO" << endl; } else { int f = 1; for (int i = 2; i < factores.size(); i++) f = f * factores[i]; if (f > factores[1]) { cout << "YES" << endl; cout << factores[0] << " " << factores[1] << " "; cout << f << endl; } else { cout << "NO" << endl; } } } } return 0; }
CPP
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
t = int(input()) for _ in range(t): n = int(input()) f = 0 for i in range(2, int(n**0.5)+1): if n % i == 0: a = i k = n // a for j in range(2, int(k ** 0.5)+1): if k % j == 0 and j != a and k // j != a and j != k // j: b = j c = k // j f = 1 break if f == 1: break if f == 0: print("NO") else: print("YES") print(a, b, c, sep=" ")
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
def factors(n): factor = [] for i in range(2, int(n**0.5)+1): if n % i == 0: factor.append(i) return factor t = int(input()) for l in range(t): n = int(input()) x = 0 factor = factors(n) lenfactor = len(factor) for i in range(lenfactor): for j in range(i+1, lenfactor): k = n/(factor[i]*factor[j]) if k%1 == 0 and k != factor[i] and k != factor[j]: print('YES') print(str(factor[i]) + ' ' + str(factor[j]) + ' ' + str(int(k)) ) x = 1 break if x == 1: break if x == 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 sys import stdin,stdout from math import sqrt from collections import Counter primes,primes_list = set([2]),None composites = set() def gen_primes(n): for i in range(3,n+1,2): if i not in composites: primes.add(i) for j in range(i*2,n+1,i): composites.add(j) def get_fact(n): fact = [] if n not in primes: for p in primes_list: if n%p==0: c = 0 while n%p==0: n//=p c+=1 fact.append((p,c)) if n==1: break elif len(fact) > 1: fact.append((n,1)) break else: fact.append((n,1)) return fact t = int(stdin.readline().strip()) ns = [int(stdin.readline().strip()) for _ in range(t)] gen_primes(int(sqrt(max(ns)))+1) primes_list = list(primes) primes_list.sort() #print(primes_list) for n in ns: fact = get_fact(n) #print(n,fact) div = [] if len(fact) == 3 or (len(fact) == 2 and fact[0][1]+fact[1][1]-2 > 1): a,b = fact[0][0],fact[1][0] div = [a,b,(n//a)//b] elif len(fact) == 1 and fact[0][1] >= 6: a = fact[0][0] b = a*a div = [a,b,(n//a)//b] if div: stdout.write("YES\n{} {} {}\n".format(*div)) else: stdout.write("NO\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
t=int(input()) for i in range(t): n=int(input()) def check(n): use=set() i=2 while i*i<=n: if n%i==0 and i not in use: use.add(i) n/=i break i+=1 i=2 while i*i<=n: if n%i==0 and i not in use: use.add(i) n/=i break i+=1 if n==1 or n in use or len(use)<2: return "NO" else: print "YES" use.add(n) for i in use: print i, return "" print check(n)
PYTHON
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
from math import sqrt def divide(n, start): for k in range(start, int(sqrt(n)) + 1): if n % k == 0: return k return n for _ in range(int(input())): n = int(input()) a = divide(n, 2) if a == n: print('NO') continue n //= a b = divide(n, a + 1) if b == n: print('NO') continue n //= b if n <= b: print('NO') continue print('YES') print(a, b, n)
PYTHON3
1294_C. Product of Three Numbers
You are given one integer number n. Find three distinct integers a, b, c such that 2 ≀ a, b, c and a β‹… b β‹… c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≀ t ≀ 100) β€” the number of test cases. The next n lines describe test cases. The i-th test case is given on a new line as one integer n (2 ≀ n ≀ 10^9). Output For each test case, print the answer on it. Print "NO" if it is impossible to represent n as a β‹… b β‹… c for some distinct integers a, b, c such that 2 ≀ a, b, c. Otherwise, print "YES" and any possible such representation. Example Input 5 64 32 97 2 12345 Output YES 2 4 8 NO NO NO YES 3 5 823
2
9
import math from collections import defaultdict as dq def primeFactors(n): d=dq(int) while n % 2 == 0: d[2]+=1 n = n // 2 for i in range(3,int(math.sqrt(n))+1,2): while n % i== 0: d[i]+=1 n = n // i if n>1: d[n]+=1 return d for _ in range(int(input())): n=int(input()) s=primeFactors(n) if len(s)>2: c=0 li=[] for i in s.keys(): li.append(i) c+=1 if c==2: break print("YES") print(li[0],li[1],n//(li[0]*li[1])) if len(s)==1: for i in s.keys(): c=i if s[c]>=6: print("YES") print(c,c*c,n//(c*c*c)) else: print("NO") if len(s)==2: li=[] for i in s.keys(): li.append(i) if n//(li[0]*li[1]) in s.keys() or n//(li[0]*li[1])==1 : print("NO") else: print("YES") print(li[0],li[1],n//(li[0]*li[1]))
PYTHON3