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 | #include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int n;
int factorization(int n){
if(n==1) return 0;
cout << n << ": ";
for(int i = 2; i <= sqrt(n); i++){
if(n % i == 0){
cout << i << " ";
n = n / i;
i = 1;
}
}
cout << n << endl;
return 0;
}
void solve(){
cin >> n;
factorization(n);
}
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
solve();
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;
int main() {
long long N;
cin >> N;
int i = 2;
cout << N << ':';
while (i <= sqrt(N)) {
if (N % i == 0) {
cout << ' ' << i;
N /= i;
}
else {
++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 | #include <bits/stdc++.h>
using namespace std;
int main(){
long n; cin>>n;
cout<<n<<':';
long x=n;
while(x%2==0){cout<<' '<<2;x/=2;}
for(int i=3;i*i<=n;i+=2){
while(x%i==0){
cout<<' '<<i;
x/=i;
}
}
if(x!=1)cout<<' '<<x;
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 |
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main{
public static void main(String[] args) {
// TODO 自動生成されたメソッド・スタブ
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
try {
String strNum = br.readLine();
sb.append(strNum + ":");
int number = Integer.parseInt(strNum);
int devideNum = 2;
while (number % devideNum == 0) {
sb.append(" ");
sb.append(devideNum);
number /= 2;
}
devideNum++;
while (number != 1) {
if (number % devideNum == 0) {
sb.append(" ");
sb.append(devideNum);
number /= devideNum;
} else {
devideNum +=2;
}
}
// for (int i= devideNum; i <= number; i++) {
// if (number < devideNum) {
// break;
// }
// devideNum = i;
// while ((number % devideNum) == 0) {
// number /= devideNum;
// sb.append(" ");
// sb.append(devideNum);
// }
// }
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
}
System.out.println(sb.toString());
}
}
| 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 | n=int(input())
n1=n
l=[]
def isprime(n):
if n==2:
return True
elif n==1:
return False
else:
for i in range(2,int(n**0.5)+1):
if n%i==0:
return False
return True
for i in range(2,int(n**0.5)+1):
while n1%i==0:
l.append(i)
n1=n1//i
if isprime(n1):
l.append(n1)
break
w=str(n)+":"
for i in l:
w+=" "+str(i)
print(w)
| 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())
print(n,': ',sep='',end='')
a=2
A=[]
while a*a<=n:
while n%a==0:
n //= a
A.append(str(a))
a+=1
if n>1:
A.append(str(n))
A=' '.join(A)
print(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 <bits/stdc++.h>
using namespace std;
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 << 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>
int main()
{
int n;
scanf("%d", &n);
printf("%d:", n);
for (int i = 2; i * i <= n && n != 1; i++)
{
while (!(n % i))
{
printf(" %d", i);
n /= i;
}
}
if (n != 1) printf(" %d", n);
printf("\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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
public class Main {
static BufferedReader in;
static PrintWriter out;
static StringTokenizer tok;
void solve() throws IOException {
int n = ni();
TreeMap<Integer, Integer> map = primeFactorize(n);
out.print(n + ":");
Set<Integer> set = map.keySet();
for (int x : set) {
for (int i = 0; i < map.get(x); i++) {
out.print(" " + x);
}
}
out.println();
}
TreeMap<Integer, Integer> primeFactorize(int n) {
Prime p = new Prime((int) Math.sqrt(n) + 1);
ArrayList<Integer> primes = p.getPrimes();
TreeMap<Integer, Integer> ret = new TreeMap<>();
for (int i = 0; i < primes.size(); i++) {
int x = primes.get(i);
if (n % x == 0) {
int cnt = 0;
while (n % x == 0) {
cnt++;
n /= x;
}
ret.put(x, cnt);
}
}
if (n > 1) {
ret.put(n, 1);
}
return ret;
}
class Prime {
int n;
boolean[] isPrime;
ArrayList<Integer> primes;
Prime(int n) {
this.n = n;
isPrime = new boolean[n + 1];
primes = new ArrayList<>();
sieve();
}
void sieve() {
for (int i = 2; i < n; i++) {
if (!isPrime[i]) {
primes.add(i);
for (long j = (long) i * i; j < n; j += i) {
isPrime[(int) j] = true;
}
}
}
}
ArrayList<Integer> getPrimes() {
return primes;
}
}
String ns() throws IOException {
while (!tok.hasMoreTokens()) {
tok = new StringTokenizer(in.readLine(), " ");
}
return tok.nextToken();
}
int ni() throws IOException {
return Integer.parseInt(ns());
}
long nl() throws IOException {
return Long.parseLong(ns());
}
double nd() throws IOException {
return Double.parseDouble(ns());
}
String[] nsa(int n) throws IOException {
String[] res = new String[n];
for (int i = 0; i < n; i++) {
res[i] = ns();
}
return res;
}
int[] nia(int n) throws IOException {
int[] res = new int[n];
for (int i = 0; i < n; i++) {
res[i] = ni();
}
return res;
}
long[] nla(int n) throws IOException {
long[] res = new long[n];
for (int i = 0; i < n; i++) {
res[i] = nl();
}
return res;
}
public static void main(String[] args) throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
tok = new StringTokenizer("");
Main main = new Main();
main.solve();
out.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>
using namespace std;
int judge(long long n)
{
if(n<2)return 0;
else if(n==2)return 1;
if(n%2==0)return 0;
for(int i=3;i<=n/i;i+=2){
if(n%i==0)return 0;
}
return 1;
}
int main()
{
long long n;
cin>>n;
cout<<n<<":";
if(judge(n))cout<<" "<<n;
else{
for(int i=2;i<=n;i++){
if(n%i==0){
cout<<" "<<i;
n/=i;
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 | def factorize(n):
b = 2
fct = []
while b * b <= n:
while n % b == 0:
n //= b
fct.append(str(b))
b = b + 1
if n > 1:
fct.append(str(n))
return fct
n = int(input())
ans = factorize(n)
# str_ans = str(ans)
# print(''.join(str_ans))
# print(str_ans)
# print(*ans)
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 | #include <bits/stdc++.h>
using namespace std;
int main(){
int n = 0;
int limit;
scanf("%d",&n);
printf("%d:",n);
limit = sqrt(n) ;
for(int i = 2;i <= n ;){
if(n%i == 0){
printf(" %d",i);
n /=i;
}
else i++;
if(i > limit) {printf(" %d",n);break;}
}
putchar('\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 | N = int(input())
N_ = N
arr = []
for x in range(2,int(pow(N,0.5) + 1)):
while N % x == 0:
arr.append(x)
N = N // x
if N != 1:
arr.append(N)
print(f"{N_}:", *arr)
| 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.*;
public class Main{
public static void main(String[] args){
new Main().run();
}
Scanner sc = new Scanner(System.in);
int n;
boolean[] p;
void run(){
p = new boolean[100000000];
setP();
while(sc.hasNext()){
int n = sc.nextInt();
if(n>=2){
System.out.print(n+":");
solve(n);
}
}
}
void solve(int n){
int i=2;
while(n>1){
// ??????????????????????卒???属??????
if(n<p.length && p[n]){
System.out.print(" "+n);
n = n/n;
continue;
}
// ??????????其????????卒???属??????????????????????????????
if(i>=p.length){
System.out.print(" "+n);
n = 1;
continue;
}
// ?卒???属??則????????????
while(p[i] && n%i==0){
n = n/i;
System.out.print(" "+i);
}
if(i>2) i+= 2;
else i++;
}
System.out.println();
}
void setP(){
Arrays.fill(p, true);
p[0] = p[1] = false;
for(int i=2; i<p.length; i++){
if(p[i])
for(int j=i*2; j<p.length; j+=i)
if(p[j]) p[j] = false;
}
}
}
| 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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) throws Exception {
FastScanner scanner = new FastScanner(System.in);
int n = (int) scanner.nextInt();
StringBuffer str = new StringBuffer();
str.append(n +":");
for (int i = 2; i * i <= n; i++) {
while (n%i==0) {
n = n/i;
str.append(" "+ i);
}
}
if (n>1) {
str.append(" "+ n);
}
PrintWriter printWriter = new PrintWriter(System.out);
printWriter.printf("%s\n", str.toString());
printWriter.close();
}
static class FastScanner {
private BufferedReader reader = null;
private StringTokenizer tokenizer = null;
public FastScanner(InputStream in) {
reader = new BufferedReader(new InputStreamReader(in));
tokenizer = null;
}
public String next() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public long nextInt() {
return Integer.parseInt(next());
}
}
} | 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 | import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long input = in.nextLong();
Map<Long, Integer> m = primeFactorize(input);
System.out.print(input+":");
for(Entry<Long, Integer> e : m.entrySet()) {
long prime = e.getKey();
int ite = e.getValue();
for (int i=0;i<ite;i++) {
System.out.print(" "+prime);
}
}
System.out.println();
}
static public Map<Long, Integer> primeFactorize(long n) {
Map<Long, Integer> res = new LinkedHashMap<Long, Integer>();
long tmp=n;
for (long i=2;i*i<=n;i++) {
int count=0;
while (tmp%i==0) {
tmp/=i;
count++;
}
if (count!=0) res.put(i, count);
}
if (tmp!=1) res.put(tmp, 1);
if (res.size()==0) res.put(n, 1);
return res;
}
} | 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 | n=input()
print(n+': ',end='')
n=int(n)
x = 2
ans = []
while x * x <= n:
while n % x == 0:
n //= x
ans.append(x)
x = x + 1
if n > 1:
ans.append(n)
print(" ".join(list(map(str, 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 factorize_rec(n, factor):
for i in range(2, math.floor(math.sqrt(n)) + 1):
if n % i == 0:
factor.append(i)
return factorize_rec(n/i, factor)
factor.append(int(n))
return factor
def factorize(n):
return factorize_rec(n, [])
print(str(n) +":", end=" ")
# for i in factorize(n):
# print(i, end=" ")
print(*factorize(n), sep=' ') | 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.ArrayList;
import java.util.List;
import java.util.Scanner;
//?´??????°????§£?????????????????°??????
public class Main {
public static void main(String[] args) {
// TODO ?????????????????????????????????????????????
Scanner sc = new Scanner(System.in);
long n = Long.parseLong(sc.nextLine());
System.out.print(n + ":");
List<Long> pf = new ArrayList<>();
while (true) {
if (n == 1) {
break;
}
for (long i = 2; i <= Math.ceil(Math.sqrt(n)); i++) {
if (n % i == 0) {
n = n / i;
pf.add(i);
break;
}
if (i == Math.ceil(Math.sqrt(n))) {
pf.add(n);
n = 1;
break;
}
}
}
for (long i : pf) {
System.out.print(" " + i);
}
System.out.print("\n");
}
} | 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 | n=int(input())
A=[]
B=n
while n%2==0:
n//=2
A.append(2)
while n%3==0:
n//=3
A.append(3)
while n%5==0:
n//=5
A.append(5)
while n%7==0:
n//=7
A.append(7)
if n>=10000000:
A.append(n)
else:
for j in range(3,n+1,2):
while n%j==0:
n//=j
A.append(j)
print(B,end="")
print(':',*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 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 << 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 java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
import java.math.BigInteger;
public class Main implements Runnable {
static int mod = 1000000007;
public static void main(String[] args) {
new Thread(null, new Main(), "", 1024 * 1024 * 1024).start();
}
public void run() {
PrintWriter out = new PrintWriter(System.out);
FastScanner sc = new FastScanner();
long n = sc.nextLong();
out.print(n + ": ");
ArrayList<Long> l = primeFactorization(n);
for(int i=0;i<l.size()-1;i++){
out.print(l.get(i) + " ");
}
out.println(l.get(l.size()-1));
out.flush();
}
static ArrayList<Long> primeFactorization(long n) {
ArrayList<Long> l = new ArrayList<>();
long i = 3;
while (n % 2 == 0) {
n /= 2;
l.add((long)2);
}
while (n != 1 && i*i <= n) {
while(n%i == 0){
n /= i;
l.add(i);
}
i += 2;
}
if(n > 1){ //nは素数
l.add(n);
}
return l;
}
}
class FastScanner {
private final InputStream in = System.in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
private boolean hasNextByte() {
if (ptr < buflen) {
return true;
} else {
ptr = 0;
try {
buflen = in.read(buffer);
} catch (IOException e) {
e.printStackTrace();
}
if (buflen <= 0) {
return false;
}
}
return true;
}
private int readByte() {
if (hasNextByte())
return buffer[ptr++];
else
return -1;
}
private static boolean isPrintableChar(int c) {
return 33 <= c && c <= 126;
}
public boolean hasNext() {
while (hasNextByte() && !isPrintableChar(buffer[ptr]))
ptr++;
return hasNextByte();
}
public String next() {
if (!hasNext())
throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while (isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext())
throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {
throw new NumberFormatException();
}
while (true) {
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
} else if (b == -1 || !isPrintableChar(b)) {
return minus ? -n : n;
} else {
throw new NumberFormatException();
}
b = readByte();
}
}
public int nextInt() {
long nl = nextLong();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
throw new NumberFormatException();
return (int) nl;
}
public int[] nextintArray(int n){
int[] a = new int[n];
for(int i=0;i<n;i++){
a[i] = nextInt();
}
return a;
}
public long[] nextlongArray(int n){
long[] a = new long[n];
for(int i=0;i<n;i++){
a[i] = nextLong();
}
return a;
}
public Integer[] nextIntegerArray(int n){
Integer[] a = new Integer[n];
for(int i=0;i<n;i++){
a[i] = nextInt();
}
return a;
}
public double nextDouble() {
return Double.parseDouble(next());
}
}
| 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 | n = int(input())
n1 = n
i = 2
x = []
while i*i <= n:
while n % i == 0:
n //= i
x.append(str(i))
i += 1
if n > 1:
x.append(str(n))
print(str(n1) + ": " + " ".join(x))
| 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 | public class Main{
public void run(java.io.InputStream in, java.io.PrintStream out){
java.util.Scanner sc = new java.util.Scanner(in);
/*answer*/
int n, i;
n = sc.nextInt();
System.out.print(n + ":");
for(;n != 1;){
for(i = 2;i * i < (n + 1);i++){
if(n % i == 0){
System.out.print(" " + i);
n = n / i;
break;
}
}
if(i * i > n){
System.out.print(" " + n);
break;
}
}
System.out.println();
/*end*/
sc.close();
}
public static void main(String[] args){
(new Main()).run(System.in, System.out);
}
} | 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 | n = int(input())
print(f'{n}:', end='')
temp = n
for i in range(2, int(n**(1/2))+1):
if temp % i == 0:
while temp % i == 0:
print(f' {i}', end='')
temp //= i
if temp != 1:
print(f' {temp}', 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 | #include<bits/stdc++.h>
using namespace std;
int main(){
unsigned n; cin >> n;
cout << n << ":";
for(unsigned i = 2;i * i <= n; 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 | x=n=int(input())
a=[]
while n%2==0:
a.append(2)
n=n//2
m=3
while m*m<=n:
if n%m==0:
a.append(m)
n=n//m
else:
m+=2
if n!=1:
a.append(n)
b=''
for i in range(len(a)):
b=b+' '+str(a[i])
i+=1
print(str(x)+':'+b)
| 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.io.InputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
InputStream in = System.in;
PrintStream out = System.out;
public void _main(String[] args) {
Scanner sc = new Scanner(in);
int n = sc.nextInt();
sc.close();
out.print(n + ":");
List<Integer> ans = new ArrayList<>();
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
ans.add(i);
n /= i;
}
}
// 1以外が残るのは、元のnが素数だった場合
if (n != 1) {
ans.add(n);
}
for (int x : ans) {
out.print(" " + x);
}
out.println();
}
public static void main(String[] args) {
new Main()._main(args);
}
}
| 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 <cmath>
using namespace std;
long long div(long long n1) {
for (long long i = 2; i <= sqrt(n1);) {
if (n1 % i == 0) {
return i;
}
else {
i++;
}
}
return -1;
}
int main() {
long long n;
cin >> n;
cout << n << ":";
while (1) {
if(div(n) == -1) {
cout << " " << n;
break;
}
cout << " " << div(n);
n = n / div(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())
N = n
print(N,":",sep="",end=" ")
def prime_factorize(n):
a = []
while n % 2 == 0:
a.append(2)
n //= 2
b = 3
while b * b <= n:
if n % b == 0:
a.append(b)
n //= b
else:
b += 2
if n != 1:
a.append(n)
return a
A = prime_factorize(n)
print(*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 | #73 素因数分解
import math
n = int(input())
a = n
ans = []
i = 2
while i <= math.sqrt(n):
if n % i == 0:
n = n //i
ans.append(str(i))
else:
i += 1
if n != 1:
ans.append(str(n))
print(str(a) + ":" + " " + " ".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 | #include <iostream>
#include <math.h>
int main(void) {
long int in;
long int i = 2;
std::cin >> in;
std::cout << in << ":";
while (in != 1) {
if (i > sqrt(in)) {
std::cout << " " << in;
break;
} else if (in % i != 0) {
i += 1;
} else {
in = in / i;
std::cout << " " << i;
i = 2;
}
}
std::cout << std::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;
map< int64_t, int > prime_factor(int64_t n) {
map< int64_t, int > ret;
for(int64_t i = 2; i * i <= n; i++) {
while(n % i == 0) {
ret[i]++;
n /= i;
}
}
if(n != 1) ret[n] = 1;
return ret;
}
int main() {
int N;
cin >> N;
cout << N << ":";
for(auto p : prime_factor(N)) {
while(p.second--) cout << " " << p.first;
}
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 <map>
#include <vector>
using namespace std;
map<int, int> factorize(int n) {
map<int, int> m;
for (int i = 2; i * i <= n; i++) {
while (n % i == 0) {
++m[i];
n /= i;
}
}
if (n != 1) m[n] = 1;
return m;
}
int main() {
int n;
cin >> n;
cout << n << ":";
for (auto p : factorize(n)) {
for (int i = 0; i < p.second; i++) {
cout << " " << p.first;
}
}
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())
def fac(m, p):
step = 1 if p == 2 else 2
for i in range(p, int(math.sqrt(m)+1), step):
if m % i == 0:
return i
return m
result = str(n) + ":"
r = n
p = 2
while r != 1:
p = fac(r,p)
r = r//p
result = result + " " + str(p)
print(result) | 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_factorize(N):
# 素因数分解
import math as m
a = []
for i in range(2, int(m.sqrt(N)) + 1):
while N % i == 0:
a.append(i)
N //= i
if N > 1:
a.append(N)
return a
def resolve():
N = int(input())
a = prime_factorize(N)
print(str(N) + ":", *a)
resolve()
| 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 | b = int(input());
n = b;
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)
print("{}:".format(b),end = '');
for i in range(0,len(a)):
print('',a[i],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 | #include <iostream>
using namespace std;
int main(void){
int n;
cin>>n;
cout<<n<<":";
int i=2,m=n;
while(m!=1){
if(m%i==0){
m/=i;
cout << " " << i;
}else{
if(i>=3){i+=2;}
else{i++;}
}
if(i*i>n) {
cout << " " << m;
break;
}
}
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>
using namespace std;
int main(void){
int num;
cin >> num;
cout << num << ":";
for(int i = 2; i*i <= num; ++i){
while(num % i == 0){
num /= i;
cout << " " << i;
}
}
if(num != 1){
cout << " " << num;
}
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 | from math import sqrt
n = int(input())
def prime_factors(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
factors = prime_factors(n)
print("{}:".format(n), *factors)
| 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 p(n):
l = [1]*(n+1)
l[0] = l[1] = 0
for i in range(2,int(n ** 0.5) + 1):
if l[i]:
for j in range(2*i, n+1, i):
l[j] = 0
return l
n = input()
l = []
l += [str(n)+":"]
from itertools import compress, count
P = p(int(n ** 0.5))
for i in compress(count(0), P):
while n % i == 0:
n /= i
l += [i]
if n != 1: l += [n]
print " ".join(map(str,l)) | 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 | # -*- coding: utf-8 -*-
# モジュールのインポート
import math
# 標準入力を取得
n = int(input())
# 求解処理
ans = []
t = n
while True:
is_prime = True
for i in range(2, int(math.sqrt(t)) + 1):
if t % i == 0:
ans.append(i)
t /= i
is_prime = False
break
if is_prime:
ans.append(t)
break
ans = map(int, ans)
# 結果出力
print(f"{n}:", " ".join(map(str, 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 | p=lambda x:print(x,end=' ')
n=input();p(n+':')
n=int(n);s=n**.5;d=3
while n%2==0 and n>3:p(2);n//=2
while s>d and n>d:
if n%d>0:d+=2
else:p(d);n//=d
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 | #include<stdio.h>
#include<math.h>
int main()
{
int n, i;
while(scanf("%d", &n)!=EOF){
printf("%d: ", n);
for(i=2; i<=sqrt(n); i++){
if(n%i==0){
printf("%d ", i);
n/=i;
i=1;
}
}
printf("%d\n", 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 | #include "bits/stdc++.h"
using namespace std;
int main() {
long long N;
cin >> N;
cout << N << ":";
for (long long i = 2; i * i <= N; i++) {
if (N % i == 0) cout << " " << i, N /= i, i--;
}
if (N != 1) 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 | import java.util.Scanner;
public class Main
{
public static void main(String[]args)
{
Scanner in=new Scanner(System.in);
int n=in.nextInt();
System.out.print(n+":");
for(int i=2;i<=Math.sqrt(n);i++)
{
if(n%i==0)
{
while(n%i==0)
{
System.out.print(" "+i);
n=n/i;
}
}
}
if(n!=1)
System.out.print(" "+n);
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 | #!/usr/bin/env python
from collections import deque
import itertools as it
import sys
import math
import random
sys.setrecursionlimit(1000000)
INF = 10 ** 18
n = input()
ls = []
n_ = n
i = 2
while True:
if i * i > n:
break
while n % i == 0:
n /= i
ls.append(i)
i += 1
if n != 1:
ls.append(n)
print str(n_) + ": " + " ".join(map(str, ls))
| 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 | def main():
import sys
N = int(sys.stdin.readline())
SN = N
def calc(N):
import math
L = []
for i in range(2, int(math.sqrt(N))+2):
while N % i==0:
L += [i]
N = N//i
if N !=1:
L += [N]
print(str(SN) + ': ' + ' '.join(map(str,L)))
calc(N)
if __name__=='__main__':
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 | N = int(input())
res = []
x = N
y = 2
while y*y <= x:
while x % y == 0:
res.append(y)
x//= y
y += 1
if x > 1:
res.append(x)
print("%d:"%N,*res)
| 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;
typedef long long ll;
ll n;
void solve(ll n) {
for (ll i = 2; i * i <= n; i++) {
if (n % i == 0) {
cout << " " << i;
solve(n / i);
return;
}
}
cout << " " << n;
return;
}
int main() {
cin >> n;
cout << n << ":";
solve(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 a,n;
scanf("%d",&n);
printf("%d:",n);
a=2;
while(n>=a*a){
if(n%a==0){
printf(" %d",a);
n=n/a;
} else {
a++;
}
}
printf(" %d\n",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 math
n = int(input())
num = [str(n)+":"]
i = 2
while i <= math.sqrt(n):
while n % i == 0:
num.append(str(i))
n//=i
i+=1
if n != 1:
num.append(str(n))
print(num[0]+" "+str(n) if len(num) == 1 else " ".join(num))
| 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;i*i<=n;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>
using namespace std;
int main(){
int N, n;
bool flg = false;
cin >> N;
cout << N << ":";
n = N;
while(n != 1){
flg = false;
for(int i=2;i*i<=N;i++){
if(n%i == 0){
n /= i;
cout << " " << i;
flg = true;
break;
}
}
if(!flg){ cout << " " << n; n /= 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 | n=int(input())
ans=[str(n)+":"]
i=2
while i*i<=n:
while n%i==0:
n//=i
ans.append(i)
i+=1
if n!=1:ans.append(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 | i = 2
n = int(input())
n_ = n
ans = []
while i*i <= n:
while n % i == 0:
ans.append(i)
n //= i
i += 1
if n > 1:
ans.append(n)
print(str(n_) + ': ' + ' '.join([str(i) for i in 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>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
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 <cstdio>
const int LIM=1e6;
int a[LIM];
int main() {
int n;
scanf("%d", &n);
printf("%d:", n);
for(int i=2; i<=n/i; i++) {
while(n%i==0) printf(" %d", i), n/=i;
}
if(n>1) printf(" %d", n);
putchar('\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 | #include <bits/stdc++.h>
using namespace std;
void factorize( int n ) {
cout << n << ':';
while( n % 2 == 0 ) {
cout << ' ' << 2;
n /= 2;
}
int d = 3;
int e = sqrt( n );
while( n >= d ) {
if( d > e ) {
cout << ' ' << n;
break;
}
if( n % d == 0 ) {
cout << ' ' << d;
n /= d;
}
else {
d += 2;
}
}
cout << endl;
}
int main() {
ios_base::sync_with_stdio( false );
int n;
cin >> n;
factorize( 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 | import java.util.ArrayList;
import java.util.Scanner;
public class Main {
static Scanner sc = new Scanner(System.in);
static ArrayList<Integer> pf = new ArrayList<Integer>();
public static void main(String[] args) {
primeFactorize( sc.nextInt() );
}
private static void primeFactorize(int nextInt) {
int n = nextInt;
int p = 2;
while(n > 1 ) {
for( p = 2; p <= Math.sqrt(n); p++) {
if ( n % p == 0 ) {
n /= p;
pf.add(p);
break;
}
}
if (p * p > n) {
pf.add(n);
break;
}
}
System.out.printf("%d:", nextInt);
for (int i : pf) {
System.out.printf(" %d", i);
}
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 | import java.util.Scanner;
public class Main {
public static void main(String args[]){
try(Scanner sc=new Scanner(System.in)){
int n=sc.nextInt();
System.out.print(n+":");
int x=n;
for(int i=2; i*i<=x; i++) {
while(n%i==0) {
System.out.print(" "+i);
n/=i;
}
}
if(n!=1)
System.out.println(" "+n);
else
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 | import math
def soi(x):
y = x
a = []
for i in range(2,int(math.sqrt(x))+1):
while x%i == 0:
a.append(i)
x/=i
if len(a)==0 or x!=1:
a.append(int(x))
a.sort()
print(str(y)+':',*a)
n = int(input())
soi(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 factorize(n):
if n < 4:
return [n]
res = []
i = 2
while i*i <= n:
while n%i == 0:
res.append(i)
n //= i
i += 1
if n != 1:
res.append(n)
res.sort()
return res
N = int(input())
f = factorize(N)
print(str(N)+": ", end="")
print(*f)
| 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;
map<int, int> prime_factor(long long n) {
map<int, int> res;
for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {
++res[i];
n /= i;
}
}
if (n != 1) res[n] = 1;
return res;
}
int main() {
int n;
cin >> n;
map<int, int> m = prime_factor(n);
cout << n << ":";
for (auto i : m) {
for (int j = 0; j < i.second; ++j) {
cout << " " << i.first;
}
}
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 | import java.util.*;
import static java.lang.System.*;
import java.io.*;
public class Main {
static FastScanner sc = new FastScanner(System.in);
public static void main(String[] args) {
int n = sc.nextInt();
int d = (int)Math.sqrt(n);
out.print(n+":");
for (int i=2; i<=d; i++) {
while (n%i==0) {
n /= i;
out.print(" "+i);
}
if (i==d && n>1) {out.print(" "+n);}
}
out.println();
}
}
class FastScanner implements Closeable {
private final InputStream in;
private final byte[] buffer = new byte[1024];
private int ptr = 0;
private int buflen = 0;
public FastScanner(InputStream in) {this.in = in;}
private boolean hasNextByte() {
if (ptr < buflen) {return true;}
else{
ptr = 0;
try {buflen = in.read(buffer);}
catch (IOException e) {e.printStackTrace();}
if (buflen <= 0) {return false;}
}
return true;
}
private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
public String next() {
if (!hasNext()) throw new NoSuchElementException();
StringBuilder sb = new StringBuilder();
int b = readByte();
while(isPrintableChar(b)) {
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
public long nextLong() {
if (!hasNext()) throw new NoSuchElementException();
long n = 0;
boolean minus = false;
int b = readByte();
if (b == '-') {
minus = true;
b = readByte();
}
if (b < '0' || '9' < b) {throw new NumberFormatException();}
while(true){
if ('0' <= b && b <= '9') {
n *= 10;
n += b - '0';
}else if(b == -1 || !isPrintableChar(b)){return minus ? -n : n;}
else{throw new NumberFormatException();}
b = readByte();
}
}
public int nextInt() {
long nl = nextLong();
if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
return (int) nl;
}
public double nextDouble() { return Double.parseDouble(next());}
public void close() {
try {in.close();}
catch (IOException e) {}
}
}
| 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 prime_fact(n):
ret = []
if n == 1:
return [1]
for d in [2] + list(range(3, int(n ** 0.5) + 1, 2)):
while n % d == 0:
ret.append(d)
n //= d
if n != 1:
ret.append(n)
return ret
n = int(input())
print("{}: ".format(n), end = "")
print(*prime_fact(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 | import math
n = int(input())
def factor(m, p):
step = 1 if p == 2 else 2
for i in range(p, int(math.sqrt(m)+1), step):
if m % i == 0:
return i
return m
res = str(n) + ":"
p = 2
while n != 1:
p = factor(n,p)
n = n//p
res = res + " " + str(p)
print(res) | 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<<":";
int j=n;
for(int i=2;i*i<=j;i++){
while(n%i==0){
cout<<" "<<i;
n=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>
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(0);
int n;
std::cin >> n;
std::cout << n << ":";
for (int i = 2; i * i <= n; i++) {
while (n % i == 0){
std::cout << " " << i;
n /= i;
}
if(i != 2)
i++;
if(n == 1)
break;
}
if(n != 1) {
std::cout << " " << n;
}
std::cout << std::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 | import math
n=input()
N=n
a=[]
x=2
while x*x<=N:
while n%x==0:
a.append(str(x))
n=n/x
if n==1: break
x+=1
else:
a.append(str(n))
print str(N)+": "+" ".join(a)
| 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.*;
import java.util.stream.Collectors;
public class Main {
public static void main(String[] args) {
final Scanner sc = new Scanner(System.in);
final long n = sc.nextLong();
final List<Map<Long, Integer>> pfs = primeFactorize(n);
System.out.print(n + ":");
for (Map<Long, Integer> pf : pfs) {
for (Map.Entry<Long, Integer> entry : pf.entrySet()) {
for (int i = 0; i < entry.getValue(); i++) {
System.out.print(" " + entry.getKey());
}
}
}
System.out.println();
}
private static List<Map<Long, Integer>> primeFactorize(long n) {
List<Map<Long, Integer>> res = new ArrayList<>();
for (long a = 2; a*a <= n; a++) {
if (n % a != 0) {
continue;
}
int ex = 0;
while (n % a == 0) {
ex++;
n /= a;
}
res.add(Collections.singletonMap(a, ex));
}
if (n != 1) {
res.add(Collections.singletonMap(n, 1));
}
return res;
}
}
| 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<cstdio>
#include<vector>
using namespace std;
int main(){
int n;
vector<int> G;
scanf("%d",&n);
if(n == 1){
printf("%d: %d\n",n,n);
return 0;
}
int a = n;
for(int i = 2; i * i <= n; i++){
while(a%i == 0){
G.push_back(i);
a /= i;
}
}
if(a != 1)G.push_back(a);
printf("%d:",n);
for(int i = 0; i < G.size(); i++){
printf(" %d",G[i]);
}
puts("");
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())
k=n
i=2
l=[]
while i**2<=n:
while n%i==0:
n//=i
l.append(i)
i+=1
if n>1:
l.append(n)
print(k,end="")
print(":",*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 | import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
long n = scan.nextLong();
run(n);
scan.close();
System.exit(0);
}
private static void run(long n) {
System.out.print(n + ":");
double max = Math.sqrt(n);
for (long i = 2; i <= max && i < n;) {
if (n % i == 0) {
System.out.print(" " + i);
n /= i;
} else
i++;
}
if (n == 1)
System.out.println();
else
System.out.println(" " + n);
}
} | 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 | n = int(input())
def function(n):
a = []
if n < 2:
return a
while n%2 ==0:
a.append(2)
n = n//2
i = 3
while i*i <= n:
if n%i ==0:
a.append(i)
n = n//i
else:
i += 2
if n > 1:
a.append(n)
return a
print(str(n)+":",*function(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 = int(input())
print(str(n) + ':', end='')
while n > 1:
for p in range(2, n+1):
if n % p == 0:
n //= p
print(' ' + str(p), end='')
break
elif p * p > n:
print(' ' + str(n), end='')
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 | def f(n) -> list:
if n==1:
return [1]
ret = []
i = 2
while i*i<=n:
while n%i==0:
n //= i
ret.append(i)
i += 1
if n!=1:
ret.append(n)
return ret
n=int(input())
print("{}:".format(n),*f(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 | import math
n = int(input())
nc = n
result = []
i = 2
while i <= math.sqrt(n):
if n%i == 0:
n //= i
result.append(str(i))
else:
i += 1
if n != 1:
result.append(str(n))
print(str(nc) + ": " + " ".join(result))
| 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<<":";
while(n%2==0)
{
cout<<" "<<2;
n/=2;
}
for(int i=3;i*i<=n;i+=2)
{
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 | import math
def factorize(p):
while p % 2 == 0:
p //= 2
yield 2
r = 3
while r < int(math.sqrt(p)+1):
if p % r == 0:
p //= r
yield r
else:
r += 2
if p != 1:
yield p
n = int(input())
l = factorize(n)
print(str(n)+":",*list(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 | n=int(input())
print(str(n)+': ',end='')
a = []
i = 2
while i*i<=n:
while n%i==0:
n//= i
a.append(i)
i+=1
if n!=1:
a.append(n)
print(*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 <bits/stdc++.h>
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){
n/=i;
cout << " " << 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 | from collections import defaultdict
def factorize(n):
result = defaultdict(int)
m = n
p = 2
while p*p <= m:
while n % p == 0:
n = n // p
result[p] += 1
p += 1
if n > 1:
result[n] += 1
return result
n = int(input())
factors = factorize(n)
ans = '{}:'.format(n)
for p, num in factors.items():
ans += ' {}'.format(p) * num
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 | #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define SZ(a) int((a).size())
#define FOR(var,a,b) for(int var=(a);var<(b);var++)
#define REP(var,n) FOR(var,0,n)
#define INT(n) int n;scanf("%d",&n);
int main(){
INT(n);
printf("%d:", n);
FOR(i, 2, 100000){
if (n < i * i){break;}
while (n % i == 0){
printf(" %d", i);
n /= i;
}
}
if (1 < n){printf(" %d", n);}
printf("\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 | def factorization(n):
arr=[]
tmp=n
for i in range(2,int(n**0.5)+1):
if(tmp%i==0):
cnt=0
while tmp%i==0:
cnt+=1
tmp//=i
arr.append([i,cnt])
if(tmp!=1):
arr.append([tmp,1])
return arr
n=int(input())
s=str(n)+':'
arr=factorization(n)
for x,y in arr:
s+=(' '+str(x))*y
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 s(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(f'{n}: ',end='')
print(*s(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 ll long long
#define INF 1000000005
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;
typedef pair<int,int>P;
const int MAX_N = 1000000;
void prime_factor(int n)
{
for(int i=2;i*i<=n;i++){
while(n%i == 0){
printf(" %d",i);
n /= i;
}
}
if(n != 1){
printf(" %d",n);
}
return;
}
int main()
{
int n;
scanf("%d",&n);
printf("%d:",n);
prime_factor(n);
printf("\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 | #include <bits/stdc++.h>
using namespace std;
int get_min_p(int n) {
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return i;
}
}
return n;
}
int main() {
int n;
cin >> n;
cout << n << ":";
while (n > 1) {
int p = get_min_p(n);
while (n % p == 0) {
n /= p;
cout << " " << p;
}
}
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 | n = int(input())
b = 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)
print(f'{b}:',*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 <bits/stdc++.h>
using namespace std;
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<<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 | import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.util.ArrayList;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author silviase
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
PrimeFactorize solver = new PrimeFactorize();
solver.solve(1, in, out);
out.close();
}
static class PrimeFactorize {
public void solve(int testNumber, Scanner in, PrintWriter out) {
ArrayList<Integer> primes = Prime.eratosthenes(100000);
int n = in.nextInt();
out.print(n + ": ");
for (int p : primes) {
while (n % p == 0) {
out.print(p);
n /= p;
if (n != 1) out.print(" ");
}
}
if (n != 1) out.print(n);
out.println();
}
}
static class Prime {
public static ArrayList<Integer> eratosthenes(int n) {
// n以下の素数をすべて列挙する(計算量は O(N log(log N)))
// ただし10^5が耐用限界っぽい感じはする
ArrayList<Integer> res = new ArrayList<>();
ArrayList<Integer> primes = new ArrayList<>();
for (int i = 2; i <= n; i++) {
res.add(i);
}
while (res.size() > 0) {
primes.add(res.get(0));
res.removeIf(a -> a % res.get(0) == 0);
}
return primes;
}
}
}
| 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 | import math
def factorize(p):
l = []
while p % 2 == 0:
p //= 2
l.append(2)
r = 3
while r < int(math.sqrt(p)+1):
if p % r == 0:
p //= r
l.append(r)
else:
r += 2
if p != 1:
l.append(p)
return l
n = int(input())
l = factorize(n)
print(str(n)+":",*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 | a=int(input())
n=a
i=2
fc=[]
while i*i<=a:
while a%i==0:
a//=i
fc.append(i)
i+=1
if a>1:
fc.append(a)
print(str(n)+": "+" ".join(str(b) for b in fc))
| 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;
int main(){
int n;
cin >> n;
cout << n << ":";
for(int i = 2; i <= sqrt(n); i++){
if(n % i == 0){
while(n % i == 0){
n /= i;
cout << " " << 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 | n = int(input())
m = str(n) + ":"
a = True
l = n
i = 2
while a:
if l % i == 0:
l /= i
m += ' ' + str(i)
i -= 1
a = i < l**0.5
i += 1
if l != 1:
m += ' ' + str(int(l))
print(m)
| 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 << ':';
for (int i = 2; i * i <= n; ++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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
long n = Long.parseLong(str);
System.out.print(n + ":");
long div = n;
Boolean isBig = true;
for (long i = 2; isBig; i++) {
if (div % i == 0) {
div = div / i;
System.out.print(" " + i);
i--;
}
isBig = i < Math.pow(div, 0.5);
}
if (div != 1) {
System.out.println(" " + div);
} else {
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 | N = int(input())
def prime_factorization(n):
table = []
for x in range(2, int(n**0.5)+2):
while n % x == 0:
table.append(x)
n //= x
if n > 1:
table.append(n)
return table
print("{}:".format(N), *prime_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;
// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()
// code starts
int main()
{
int n;cin>>n;
int m=n;
int i;
vector<int> ans(0);
for(i=2;i*i<=m;i++)
{
while(n%i==0)
{
ans.emplace_back(i);
n/=i;
}
}
if(n>1)ans.emplace_back(n);
cout<<m<<':';
rep(i,ans.size())
{
cout<<' '<<ans[i];
}
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 | def factorize(n):
i = 2
m = n
factors = []
while i*i <= m:
if m%i==0:
m //= i
factors.append(i)
else:
i += 1
if m > 1:
factors.append(m)
return factors
n = int(input())
primes = factorize(n)
print("{0}: {1}".format(n, " ".join(list(map(str,primes)))))
| PYTHON3 |