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
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
def f(n): a=[] while n%2==0: a.append(2) n=n//2 f=3 while f*f<=n: if n%f==0: a.append(f) n=n//f else: f+=2 if n!=1: a.append(n) return(a) n=int(input()) a=f(n) b=[str(i) for i in a] A=" ".join(b) print(f"{n}: {A}")
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include<iostream> using namespace std; int main(){ int i,x,n; cin >> x; n = x; cout << x << ":"; for(i=2;i*i<=x;i++){ while(n%i==0){ cout << " " << i; n /= i; } } if(n!=1) cout << " " << n; cout << endl; return 0; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include <iostream> #include <sstream> #include <string> int main() { unsigned int n; std::stringstream ss; std::cin >> n; ss << n << ": "; for(unsigned int i = 2; i * i <= n; i++) { if(!(n % i)) { n /= i; ss << i << " "; i = 1; } } if(n != 1) ss << n << " "; std::string s = ss.str(); std::cout << s.substr(0, s.size() - 1) << std::endl; return 0; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include <iostream> #include <cmath> #include <vector> using namespace std; int main() { int N; cin >> N; vector<int> factors; cout << N << ":"; for (int i = 2; i <= sqrt(N); i++) { while (N % i == 0) { factors.push_back(i); N /= i; } if (N == 1) break; } if (N != 1) factors.push_back(N); for (int i = 0; i < factors.size(); i++) cout << " " << factors[i]; cout << "\n"; return 0; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
import java.util.Scanner; public class Main{ public static boolean isPrime(long n){ if(n % 2 == 0) return false; for(int i = 3 ; i <= Math.sqrt(n) ; i+= 2){ if(n % i == 0) return false; } return true; } public static void main(String[] agrs){ Scanner sc = new Scanner(System.in); long n = sc.nextLong(); if(isPrime(n)) System.out.println(n + ": " + n); else{ System.out.print(n + ":"); while(n % 2 == 0){ System.out.print(" " + 2); n /= 2; } for(int i = 3 ; i <= Math.sqrt(n) ; i += 2){ if(n % i == 0 && isPrime(i)){ while(n % i == 0){ System.out.print(" " + i); n /= i; } } if(n == 1) break; else if(isPrime(n)){ System.out.print(" " + n); break; } } System.out.println(); } } }
JAVA
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
def factor(n): a=[] suu=n for i in range(2,int(n**0.5//1)+1): if suu%i==0: sosuu=0 while suu%i==0: sosuu+=1 suu//=i for j in range(sosuu): a.append(i) if suu!=1: a.append(suu) print(n,end='') print(':',*a) n=int(input()) factor(n)
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include <bits/stdc++.h> #define REP(i,n) for(int i = 0;i < (n);i++) using namespace std; int n; int main(){ cin >> n; int def_half_n = n/2+2; int def_n = n; cout << n << ":"; while(n%2==0){ cout << " " << 2; n /= 2; } if(n==1){cout << endl; return 0;} for(int i = 3;i<def_half_n;i+=2){ while(n%i==0){ cout << " " << i; n /= i; } if(n==1)break; } if(n == def_n)cout << " " << n; cout << endl; return 0; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
def factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a n = int(input()) print(str(n)+':', ' '.join([str(i) for i in factorize(n)]))
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include<iostream> using namespace std; int main(){ int n;cin >> n;int x=n; cout << x << ":"; for(int i=2;i*i<=x;i++){ while(n%i==0) { cout << " " << i; n/=i; } } if(n!=1) cout << " " << n; cout << endl; return 0; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include<bits/stdc++.h> using namespace std; void factorise(int n){ int a=2; while(sqrt(n)>=a){ while(n%a==0){ n/=a; cout<<" "<<a; } a++; } if(n!=1) cout<<" "<<n; return; } int main(){ int n; cin>>n; cout<<n<<":"; factorise(n); cout<<endl; return 0; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
import math mod = 10 ** 9 + 7 def f(num): i = 2 d = dict() while i * i <= num: if num % i == 0: num //= i d[i] = d.get(i, 0) + 1 else: i += 1 d[num] = d.get(num, 0) + 1 return d n = int(input()) ans = [] for k, v in f(n).items(): for _ in range(v): ans.append(k) print(str(n)+":", *ans)
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include <bits/stdc++.h> typedef long long LL; using namespace std; int main(){ int n; cin >> n; cout << n << ":"; int m = sqrt(n); while (n % 2 == 0) { n /= 2; cout << " " << 2; } int i = 3; while (i <= m) { if (n % i == 0) { cout << " " << i; n /= i; } else { i += 2; } } if (n != 1) { cout << " " << n; } cout << endl; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include <stdio.h> int main(){ int n; scanf("%d",&n); printf("%d:",n); while(n%2==0){ n/=2; printf(" 2"); } for(int i=3;i*i<=n;i++){ while(n%i==0){ n/=i; printf(" %d",i); } } if(n!=1)printf(" %d",n); printf("\n"); }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
p=lambda x:print(x,end=' ') n=input();p(n+':') n=int(n);s=n**.5 while n%2==0 and n>3:p(2);n//=2 d=3 while s>d and n>d: if n%d==0:p(d);n//=d else:d+=2 print(n)
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
n = input() print(n + ":", end="") n = int(n) while n % 2 == 0: print(" 2", end="") n //= 2 if n<2: print() exit() st = 3 while 1: for d in range(st, int(n ** 0.5) + 2, 2): if n % d == 0: print(" " + str(d), end="") st = d n //= d break else: print(" " + str(n)) break
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include<iostream> using namespace std; bool flag[1000010]; int main(){ int n, p; cin >> n; p = n; cout << n << ":"; while (1){ if (n == 1){ cout << endl; break; } for (int i = 2;i< 1000010; i++){ if (n%i == 0){ cout << " " << i; n /= i; break; } } if (n == p){ cout << " " << p << endl; break; } } }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
n = int(input()) def function(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a a = function(n) print("{0}:" . format(n), end=" ") for i in range(len(a) - 1): print(a[i], end=" ") print(a[len(a) - 1])
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
from collections import defaultdict N=int(input()) def prime_factor(n): i = 2 table = defaultdict(int) while i * i <= n: while n % i == 0: n //= i table[i]+=1 i += 1 if n > 1: table[n]+=1 return table table=prime_factor(N) s=str(N)+":" for i,j in table.items(): for _ in range(j): s+=" "+str(i) print(s)
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
def ifprime(n): if n%2==0: print(' 2',end="") return(int(n/2)) else: for i in range(3,int(n**0.5)+1): if n%i==0: print(f' {i}',end="") return(int(n/i)) print(f' {n}',end="") return(1) n=int(input()) print(f'{n}:',end="") while 1: n=ifprime(n) if n==1:break print()
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
n=int(input()) m=n lst=[] while n%2==0: lst.append(2) n//=2 f=3 while f*f<=n: if n%f==0: lst.append(f) n//=f else: f+=2 if n!=1: lst.append(n) print("{}:".format(m),*lst)
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
N = int(input()) n = N ans = [] for i in range(2,int(N**0.5)+1): # intに変換すること while(n%i==0): n //= i # 整数除算(//)を使うこと ans.append(i) if n!=1: ans.append(n) ans = [str(a) for a in ans] ans = str(N)+": " + " ".join(ans) print (ans)
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
def main(): from math import sqrt n = int(input()) N = n i = 2 ans = [] while i<=sqrt(n): if n%i==0: n //= i ans.append(str(i)) else: i += 1 if n != 1: ans.append(str(n)) print(str(N)+':', ' '.join(ans)) main()
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include "bits/stdc++.h" #define rep(i,n) for(int i=0;i<n;i++) using namespace std; using ll = long long; int main() { int n; cin >> n; cout << n << ":"; for (int i = 2; i * i <= n; i++) { while (n % i == 0) { cout << " " << i; n /= i; } } if (n != 1) cout << " " << n; cout << "\n"; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include <iostream> using namespace std; int n,m; int main(void){ cin>>n; cout<<n<<':'; m=n; for(int i=2;i*i<=n;i++){ while(m%i==0){ m/=i; cout<<" "<<i; } } if(m!=1)cout<<" "<<m; cout<<endl; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include <iostream> #include <vector> using namespace std; int main(){ vector<int> v; int n; cin >> n; cout << n << ":"; for(int i = 2; i*i <= n; i++){ while(n % i == 0){ v.push_back(i); n /= i; } } if(n != 1) v.push_back(n); for(auto x: v) cout << " "<< x; cout << endl; return 0; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a N = int(input()) ans = map(str,sorted(prime_factorize(N))) print(str(N)+': '+' '.join(ans))
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); System.out.print(n + ":"); int tmp = n; for (int i = 2; i * i <= n; i++) { while (tmp % i == 0) { System.out.print(" " + i); tmp /= i; } } if (tmp != 1) { System.out.print(" " + tmp); } System.out.println(); sc.close(); } }
JAVA
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include<iostream> #include<string> #include<cmath> using namespace std; int main(void){ int n; cin>>n; int N=n; string ret=to_string(n)+ ":"; int cnt=0; while(n%2==0){ n/=2; ret+=" 2"; cnt++; } int i=3; while(n>1){ if(i>(N/2))break; while(n%i==0){ n/=i; ret+=(" "+to_string(i)); cnt++; } i+=2; } if(cnt==0)ret+=" "+to_string(n); cout<<ret<<endl; return 0; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
N = int(input()) n = N m = N ** 0.5 L = [] i = 3 print(str(N) + ': ', end = '') while n%2 == 0: n = n/2 L.append(2) while i <= m: while n%i == 0: n = n/i L.append(i) i += 2 if n not in L: L.append(int(n)) if 1 in L: L.remove(1) if len(L) == 0: L.append(N) print(' '.join(map(str, L)))
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include <iostream> using namespace std; int main(){ int n;cin>>n; cout << n << ": "; for(int i = 2; n >= i*i; i++){ if(n%i==0){ cout << i << " "; n/=i; i--; } } cout << n << endl; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include <bits/stdc++.h> using namespace std; int main() { long long n, tmp; cin >> n; tmp = n; cout << n << ":"; for(long long i = 2; i * i <= n; ++i){ while(tmp % i == 0){ cout << " " << i; tmp /= i; } } if(tmp != 1) cout << " " << tmp; cout << endl; return 0; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
import math N = int(input()) x = N ans = [] y = 2 while y <= math.sqrt(x): while x % y == 0: ans.append(y) x = x //y y += 1 if x > 1: ans.append(x) print("%d:" %N,*ans)
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
def prime_factorization(n): arr = [] tmp = n for i in range(2, int(-(-n**0.5//1))+1): if tmp % i == 0: while tmp % i == 0: arr.append(i) tmp //= i if(tmp != 1): arr.append(tmp) if not arr: arr.append(n) return arr n = int(input()) ans = str(n) + ": " + " ".join(map(str, prime_factorization(n))) print(ans)
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
n = int(input()) def prime_factorize(n): a = [] while n % 2 == 0: a.append(2) n //= 2 f = 3 while f * f <= n: if n % f == 0: a.append(f) n //= f else: f += 2 if n != 1: a.append(n) return a print('{}:'.format(n), *prime_factorize(n))
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
def prime_fact(n): i = 2 table = [] while i*i<=n: while n%i ==0: n /=i table.append(i) i+=1 if n>1: table.append(n) return table n = input() anslist = prime_fact(n) print str(n)+":", for ans in anslist: print str(ans),
PYTHON
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner s = new Scanner(System.in); double input = Double.parseDouble(s.nextLine()); System.out.print((int)input + ":"); for(int i=2 ; (int)Math.floor(Math.sqrt(input))+1 > i ;) { if(input%i == 0) { System.out.print(" " + i); input = input / i; }else i++; } if(input!=1) System.out.print(" " + (int)input); System.out.println(""); } }
JAVA
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
def factorization(n): y=n list=[] print(n, end=":") for i in range(2,int(n**(1/2)//1)+1): if y%i==0: c=0 while y%i==0: c += 1 y=y//i list.append([i, c]) for j in range(c): print("", i, end="") if y!=1: print("", y, end="") print() n=int(input()) factorization(n)
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; int x = n; vector<int> ans; for(int i = 2; i * i <= x; i++) { while(x % i == 0) { x /= i; ans.push_back(i); } } if(x > 1) { ans.push_back(x); } sort(ans.begin(), ans.end()); cout << n << ":"; for(int i = 0; i < ans.size(); i++) { cout << " " << ans[i]; } cout << endl; return 0; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
n=int(input()) a=2 s=[] N=n while a*a<=n: while n%a==0: n//=a s.append(str(a)) a+=1 if n>1: s.append(str(n)) print(str(N) + ": " + " ".join(s))
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << n << ':'; int sqrt_n = sqrt(n); for (int i = 2; i <= sqrt_n; ++i) { while (n % i == 0) { cout << ' ' << i; n /= i; } } if (n != 1) cout << ' ' << n; cout << endl; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
# coding: utf-8 # Your code here! n = int(input()) print(n, ": ", sep = "", end = "") pri = [] while n % 2 == 0: pri.append(2) n //= 2 for i in range(3, int(n ** 0.5 + 1)): while n % i == 0: pri.append(i) n //= i i += 2 if n != 1: pri.append(n) for i in range(len(pri)): print(pri[i], end = "") if i < len(pri) - 1: print(" ", end = "") print("")
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
# 素因数分解 # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=NTL_1_A&lang=ja import math n = int(input()) origin = n ans = [] i = 2 while i <= math.sqrt(n): if n % i == 0: n //= i ans.append(str(i)) else: i += 1 if n != 1: ans.append(str(n)) print(f'{origin}: {" ".join(ans)}')
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
import math n = int(input()) def dev(n,x): while n % x == 0: print ('',x,end='') n //= x return n print ('{}:'.format(n),end='') n = dev(n,2) for x in range(3,int(math.sqrt(n))+1,2): if n == 1: break n = dev(n,x) if n > 1: print ('',n) else: print ('')
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include<iostream> #include<algorithm> using namespace std; int main(){ int n; cin>>n; cout<<n<<":"; int t=2; while(true){ if(n%t==0){ cout<<" "<<t; n/=t; } else{ t++; if(t*t>n)break; } } if(n!=1)cout<<" "<<n; cout<<endl; return 0; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
n = int(input()) tn = n t = [] for i in range(2, int(n ** 0.5) + 1): while n % i == 0: n //= i t.append(i) if n != 1: t.append(n) print("{}: {}".format(tn, " ".join(map(str, t))))
PYTHON3
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
#include <iostream> #include <cmath> using namespace std; inline void prime_fac(int n){ int m=(int)floor(sqrt(n)+0.5); for (int i=2;i<=m;++i){ if (n%i==0){ while (n%i==0) cout <<" "<< i,n/=i ; } } if (n>1) cout << " " << n ; } int main(){ int x; cin >> x; cout << x << ":"; prime_fac(x); cout << endl; return 0; }
CPP
p02467 Prime Factorize
Factorize a given integer n. Constraints * 2 ≤ n ≤ 109 Input n An integer n is given in a line. Output Print the given integer n and :. Then, print prime factors in ascending order. If n is divisible by a prime factor several times, the prime factor should be printed according to the number of times. Print a space before each prime factor. Examples Input 12 Output 12: 2 2 3 Input 126 Output 126: 2 3 3 7
7
0
import math s = "{0}:" s2 = " {0}" def prime_factorize(n): m = math.sqrt(n)+1 i = 2 prime = [] while n != 1 and i < m: if n % i == 0: prime.append(i) n //= i else: i += 1 if n != 1: prime.append(n) return prime n = int(input()) lst = prime_factorize(n) print(s.format(n),end="") for i in range(len(lst)): print(s2.format(lst[i]),end="") print()
PYTHON3