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 <vector>
using namespace std;
vector<int> res;
void Prime_factorize(int n){
for(int i = 2 ; i*i <= n ; i++){
while(n%i==0){
res.push_back(i);
n /= i;
}
}
if(n != 1) res.push_back(n);
}
int main(){
int n;
cin >> n;
cout << n << ':';
Prime_factorize(n);
for(int i = 0 ; i < res.size() ; i++){
cout << " " << res[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 | #include<iostream>
#include<vector>
#include<cmath>
using namespace std;
int main() {
int n;
cin >> n;
cout << n << ":";
while (n > 1) {
// 約数を探す
const double sqrtn = sqrt(n);
for (int i=2; i<=sqrtn; i++) {
if (n % i == 0) {
// iが約数
cout << " " << i;
n /= i;
goto LAST;
}
}
// nは素数なので終了
cout << " " << n << endl;
break;
LAST: 0;
}
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 = int(n**0.5)+2
is_prime = [1]*m
is_prime[0] = is_prime[1] = 0
for p in range(2,m):
for q in range(2*p,m,p):
is_prime[q] = 0
primes = [p for p, c in enumerate(is_prime) if c]
print(str(n)+': ', end='')
ans = []
for p in primes:
while n % p == 0:
ans.append(p)
n //= p
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 | n = int(input())
print("{}:".format(n), end="")
q = 2
while n>1 and q*q <= n:
if n % q == 0:
print(" {}".format(q), end="")
n //= q
else:
q += 1
if n>1:
print(" {}".format(n), 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 | import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
StringBuilder result = new StringBuilder();
result.append(n + ":");
int i;
while (n != 1) {
for (i = 2; i * i <= n; i++) {
if (n % i == 0) {
result.append(" " + i);
n /= i;
break;
}
}
if (i * i > n) {
result.append(" " + n);
break;
}
}
System.out.println(result.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 | #include <stdio.h>
int main(void)
{
int n;
int i;
scanf("%d", &n);
printf("%d:", n);
for (i = 2; i * i <= n; i++){
while (n % i == 0){
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 | n = int(input())
m = n
output = []
for i in range(2, int(n**0.5)+1):
while True:
if n % i != 0:
break
else:
output.append(i)
n //= i
if n != 1:
output.append(n)
print(str(m) + ": " + ' '.join(map(str, output)))
| 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, m;
cin >> n;
m = n;
cout << n << ":";
for(int i = 2;i * i <= m;i++){
while(!(n % i)){
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 | # coding: utf-8
# 73
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(n,end='')
print(':',end=' ')
print(*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 | #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
ll n,tmp,i;
vector<ll> ans;
cin >> n;
tmp=n;
for(i=2;i*i<=n;i++){
while(n%i==0){
ans.push_back(i);
n/=i;
}
}
if(n!=1) ans.push_back(n);
cout << tmp<<": ";
for(int i=0;i<ans.size();i++){
cout << ans[i];
if(i!=ans.size()-1) cout <<" ";
else 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 <cmath>
using namespace std;
int main(){
long long n, a=2, sq;
cin >> n;
cout << n << ":";
sq=sqrt(n);
while(n!=1){
if(n%a ==0){
n/=a;
cout << " " << a;
a=2;
}else{
a++;
}
if(a>sq){
cout << " " << n;
break;
}
}
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())
print("{}:".format(n), end='')
x = int(pow(n, 0.5))+1
for i in range(2, x):
while n % i == 0:
print(" {}".format(i), end='')
n //= i
print(' {}'.format(n) if n != 1 else '') | 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.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line = br.readLine();
int t = Integer.parseInt(line);
System.out.print(t+":");
while (t % 2 == 0) {
System.out.print(" ");
System.out.print(2);
t /= 2;
}
for (int i = 3; i * i <= t; i += 2) {
while (t % i == 0) {
System.out.print(" ");
System.out.print(i);
t /= i;
}
}
if (t > 1){
System.out.print(" ");
System.out.print(t);
}
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 | origin_n=int(input())
n=origin_n
dpair=[]
for i in range(2,int(n**(1/2))+1):
k=0
while True:
if n//i == n/i:
k+=1
n/=i
else:
break
if k!=0:
dpair.append([i,k])
if n!=1:
dpair.append([int(n),1])
print(f"{origin_n}:",end="")
for i in dpair:
for k in range(i[1]):
print(f" {i[0]}",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(){
long long i,n;
cin >> n;
cout << n << ":" ;
i=2;
while(i*i<=n){
if(n%i==0){
n/=i;
cout << " " << i;
}else{
i++;
}
}
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 n, m;
int main() {
cin >> n;
cout << n << ": ";
m=n;
for (int i=2; i*i<=m; i++) {
if (m%i == 0) {
cout << i << " ";
m/=i;
i-=1;
}
}
cout << m << 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())
def prime_factors(n):
i = 2
factors = []
while i * i <= n:
if n % i:
i += 1
else:
n //= i
factors.append(i)
if n > 1:
factors.append(n)
return factors
if __name__ == '__main__':
print(n,end=":")
print("",*prime_factors(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 | num=int(input())
print(str(num)+': ',end='')
i=2
a=[]
while i*i <= num:
while num % i == 0:
num //= i
a.append(i)
i += 1
if num != 1:
a.append(num)
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 | n = int(input())
a = []
x = n
y = 2
while y*y <= x:
while x%y == 0:
a.append(y)
x //= y
y += 1
if x > 1:
a.append(x)
print('%d:'%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 | import math
n = int(input())
def prime_factorization(num):
sqrt_num = math.sqrt(num)
prime_numbers = []
for i in range(2, int(sqrt_num) + 1):
# print(num)
while num % i == 0:
# print(num)
num = num / i
prime_numbers.append(i)
if num != 1:
prime_numbers.append(int(num))
return prime_numbers
print(str(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 | import math
N = int(input())
divided = N
prime_factor = []
for i in range(2, int(math.sqrt(N)//1)+1):
while divided%i == 0:
prime_factor.append(i)
divided //= i
if divided != 1:
prime_factor.append(divided)
print("{}: ".format(N, *prime_factor), end="")
print(*prime_factor)
| 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())
F = {}
tmp = n
i = 2
while i**2 <= tmp:
cnt = 0
while tmp % i == 0:
cnt += 1
tmp //= i
if cnt > 0:
F[i] = cnt
i += 1
if tmp != 1 or F == {}:
F[tmp] = 1
G = []
for p in F:
for i in range(F[p]):
G.append(str(p))
G = ' '.join(G)
print(f'{n}: {G}')
| 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=int(n**(1/2))
F=[]
n1=n
k=2
#rangeで処理していたのを変更:for i in range(m):
while k<=m:
if n%k==0:
F.append(k)
n//=k
#print(n)
while n%k==0:
F.append(k)
n//=k
k+=1
if n>m:
F.append(n)
print(n1,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 <iostream>
#include <vector>
using namespace std;
int main() {
int n, m;
cin >> n;
m = n;
cout << n << ':';
for (int i = 2; i * i < m; 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 | n=int(input())
nc=n
out=[]
while n%2==0:
out.append(2)
n//=2
for i in range(3,int(n**0.5)+1,2):
if n==1 : break
while n%i==0:
out.append(i)
n//=i
if n!=1 : out.append(n)
print("{}: {}".format(nc," ".join(map(str,out))))
| 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_hype = n
ans = []
for i in range(2,int(n**0.5)+2):
while True:
if n_hype%i==0:
ans.append(i)
n_hype /=i
else:
break
if n_hype!=1:
ans.append(int(n_hype))
print('{}:'.format(n),end = '')
for a in ans:
print('',a,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 | def main():
N = int(input())
ans = [str(N) + ':']
while not N % 2:
N //= 2
ans.append(2)
i = 3
while i ** 2 <= N:
while not N % i:
N //= i
ans.append(i)
i += 2
if N != 1: ans.append(N)
print(' '.join(map(str, ans)))
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 | #include <bits/stdc++.h>
using namespace std;
vector<int> f;
void solve(int n){
cout<<n<<":";
int i=0;
for(i=2;i*i<=n;i++)
while(n%i==0)f.push_back(i),n/=i;
if(n!=1)f.push_back(n);
for(int i=0;i<f.size();i++){
cout<<" "<<f[i];
}cout<<endl;
}
int main(){
int n;cin>>n;
solve(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())
factors = []
p = 2
m = n
while p * p <= m:
if m % p == 0:
m //= p
factors.append(p)
#m //= p
else:
p += 1
if m != 1:
factors.append(m)
print(f'{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 | #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 | #include<stdio.h>
#include<string.h>
#include<iostream>
#include<fstream>
#include<math.h>
using namespace std;
int main(){
std::istream & c_in = cin;
int n;
c_in >> n;
cout << n << ":";
int primes=0;
int i = 2;
while (n != 1)
{
if ((n % i) == 0) {
n /= i;
cout << " " << i;
continue;
}
i += 1 + (i & 1);
if (i > ::sqrt(n))
{
cout << " " << n;
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 | import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = scan.nextInt();
scan.close();
System.out.print(n +":");
for(int i = 2; i * i <= 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 | n = int(input())
n1 = n
p = 2
primes = []
while n1 != 1:
if n1%p == 0:
n1 /= p
primes.append(p)
elif n1 == 999993031:
primes = [999993031]
break
else:
p += 1
print((str(n)+":"),*primes,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 | n = int(input())
print('{}:'.format(n), end='')
i = 2
while i <= int(n ** .5):
if n % i == 0:
n //= i
print('', i, end='')
else:
i += 1
if n != 1:
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 <iostream>
#include <cstdio>
using namespace std;
int main(void){
int n,f;
scanf("%d", &n);
printf("%d:", n);
while (n%2==0) {
printf(" 2");
n/=2;
}
f = 3;
while (f*f<=n){
while (n%f==0){
printf(" %d", f);
n /= f;
}
f+=2;
}
if (n>=2) printf(" %d", n);
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 | #include <bits/stdc++.h>
using namespace std;
void solve(int n){
for (int i = 2; i*i <= n; i++){
if (n % i == 0) {
cout << i << " "; solve(n / i); return;
}
}
cout<<n<<endl;
}
int main() {
int n; cin >> n; cout << n << ": "; solve(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 |
def is_prime(N):
i = 0
if N <= 1:
return False, i
i = 2
while i*i <= N:
if N%i == 0:
return True, i
i += 1
return True, N
N = int(input())
print(str(N)+': ', end='')
ans = []
while True:
F, i = is_prime(N)
if F:
ans.append(i)
N //= i
else:
print(' '.join(map(str, ans)))
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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
public class Main {
/**
* @param args
* @throws IOException
* @throws NumberFormatException
*/
public static void main(String[] args) throws NumberFormatException, IOException {
// TODO Auto-generated method stub
PrimeNumberGenerator pg = new PrimeNumberGenerator();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
ArrayList<Integer> list = new ArrayList<Integer>();
int n2 = n;
while(true){
boolean divided = false;
int limit = (int)Math.sqrt(n2);
for(int i = 2; i <= limit ; i++){
if(!pg.isPrime(i)){
continue;
}
if(n2%i == 0){
n2 /= i;
list.add(i);
divided = true;
break;
}
}
if(!divided){
list.add(n2);
break;
}
}
System.out.print(n+":");
for(int i = 0; i < list.size() ; i++){
System.out.print(" "+list.get(i));
}
System.out.println();
}
}
class PrimeNumberGenerator {
private boolean[] isPrime= new boolean[100001];
public PrimeNumberGenerator() {
//Date from = new Date();
Arrays.fill(isPrime, true);
isPrime[0] = false;
isPrime[1] = false;
isPrime[2] = true;
int limit = (int)Math.sqrt(isPrime.length);
for(int i = 3; i <= limit; i+=2){
/*
if(i % 2 == 0){
isPrime[i] = false;
continue;
}
*/
if(isPrime[i] == false){
continue;
}
for(int j = i * 2; j <= isPrime.length - 1; j += i){
isPrime[j] = false;
}
}
//Date to = new Date();
//System.out.println("init takes "+ (to.getTime() - from.getTime())+ "milli sec");
}
public boolean isPrime(int index){
if(index % 2 == 0 && index != 2){
return false;
}
return isPrime[index];
}
} | 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 <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
int n;
signed main() {
cin >> n;
cout << n << ":";
for (int i = 2; i <= sqrt(n); 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 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static java.lang.Integer.parseInt;
/**
* Elementary Number Theory - Prime Factorize
*/
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String line;
while ((line = br.readLine()) != null && !line.isEmpty()) {
int n = parseInt(line);
StringBuilder sb = new StringBuilder();
sb.append(n + ":");
int d = 2;
while (n != 1) {
if (n % d == 0) {
sb.append(" " + d);
n /= d;
} else {
if (d == 2) d = 3;
else d += 2;
}
}
System.out.println(sb.toString());
}//end while
}//end main
} | 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 <bits/stdc++.h>
using namespace std;
int main() {
int64_t n;
cin>>n;
cout<<n<<':';
for(int64_t i=2;i*i<=n;i++){
if(n%i==0){
while(n%i==0){
cout<<' '<<i;
n/=i;
}
}
}
if(n!=1)
cout<<' '<<n<<endl;
else
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, i = 2;
cin >> n;
cout << n << ':';
while (i * i <= n)
{
if (n % i != 0)
{
i++;
continue;
}
cout << ' ' << i;
n /= i;
}
cout << ' ' <<n << 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, end = ":")
i = 2
ans_list = []
while i <= n:
if i * i > N and len(ans_list) == 0:
ans_list.append(N)
break
while n % i == 0:
ans_list.append(i)
n //= i
i += 1
for i in ans_list:
print(" ", end = "")
print(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 | ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))
import math
n = ii()
def calc(x):
nq = int(math.sqrt(x)+1)
for i in range(2,nq +1):
if x % i == 0:
return x//i, i
return -1,x
x = n
ans = []
while 1:
x,m = calc(x)
ans.append(m)
if x <= 1:
break
print(str(n)+': ',end='')
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 | import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
n = int(input())
ans = '{}:'.format(n)
prime_factors = []
i = 2
while i ** 2 <= n:
ext = 0
while n % i == 0:
ext += 1
n //= i
if ext:
prime_factors.append((i, ext))
i += 1
if n != 1:
prime_factors.append((n, 1))
for pf, num in prime_factors:
ans = '{} {}'.format(ans, ' '.join([str(pf)] * 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 | n=int(input())
i=2
ans=str(n)+":"
while n!=0 and i<=n**0.5:
while n%i==0:
n//=i
ans+=" "+str(i)
i+=1
if n==1:
print(ans)
exit()
print(ans+" "+str(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 soinnsuubunnkai(n):
ret = []
for i in range(2, int(n ** (1 / 2)) + 1):
if i > n:break
while n % i == 0:
n //= i
ret.append(i)
if n != 1:
ret.append(n)
return ret
n = int(input())
print(str(n)+": ",end="")
print(*soinnsuubunnkai(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())
ans = []
x = n
y = 2
while y*y <= x:
while x % y == 0:
ans.append(y)
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 | #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 <iostream>
using namespace std;
int main()
{
int n, a = 2;
cin>>n;
cout<<n<<":";
while (a*a <= n && n > 1)
{
if (n % a == 0)
{
cout<<" "<<a;
n = n/a;
}
else a++;
}
if (n > 1) cout<<" "<<n;
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 | #include <bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin >> n;
vector<int> p;
int i = 2;
int nn = n;
while( nn % i == 0 ) {
p.push_back( i );
nn /= i;
}
for( i = 3; i * i <= nn; i += 2 ) {
while( nn % i == 0 ) {
p.push_back( i );
nn /= i;
}
}
if( nn != 1 ) p.push_back( nn );
cout << n << ":";
for( int i = 0; i < p.size(); i++ ) {
cout << " " << p[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 | n=int(input())
m=n
ans=[]
for i in range(2,int(n**0.5)+1):
while n % i == 0:
ans.append(i)
n //= i
if n != 1:
ans.append(n)
l=str(m)+":"
print(l," ".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 | import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
StringBuilder sb = new StringBuilder();
sb.append(n).append(":");
ArrayList<Integer> ans = new ArrayList<>();
for (int i = 2; i <= Math.sqrt(n); i++) {
while (n % i == 0) {
ans.add(i);
n /= i;
}
}
if (n != 1) {
ans.add(n);
}
for (int x : ans) {
sb.append(" ").append(x);
}
System.out.println(sb);
}
}
| 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_factor(n):
ass = []
for i in range(2,int(n**0.5)+1):
while n % i==0:
ass.append(i)
n = n//i
if n != 1:
ass.append(n)
return ass
a = int(input())
print(str(a)+': ',end='')
print(*prime_factor(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>
#include <vector>
using namespace std;
int main() {
int n;
vector<int> f;
cin >> n;
int a = n;
for (int i = 2; i * i <= n; i++)
while (a % i == 0) {
f.push_back(i);
a /= i;
}
if (a != 1) f.push_back(a);
cout << n << ':';
for (int& e: f)
cout << ' ' << e;
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 long int N;
cin >> N;
cout << N << ":";
if( N <= 1 ) {
cout << " " << N << endl;
return 0;
}
long long int M = sqrtl( N ) + 1;
for( size_t i = 2; i <= M; 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 | // fakuto.cpp
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
int n;
double s;
cin >> n;
s=sqrt(n);
cout << n << ":";
while(true){
for(int i=2;i<s;i++){
if(n%i==0){
cout << " " << i;
n = n/i;
i=1;
continue;
}
}
if(n==1){break;}
cout << " " << n;
break;
}
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 pf(int n){
for(int i=2;i<=sqrt(n);i++){
if(n%i==0){
printf(" %d",i);
pf(n/i);
return;
}
}
printf(" %d\n",n);
}
int main(){
int n;
scanf("%d",&n);
printf("%d:",n);
pf(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 | n = input()
print "%d:"%n,
ans = []
x = 2
while x*x<=n:
while n%x<1:
ans += [str(x)]
n /= x
x += 1
if n-1: ans += [str(n)]
print " ".join(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 | def smallest_factor(integer):
j = 2
while j :
if j ** 2 > integer:
return integer
elif integer % j == 0:
return j
else:
j += 1
n = int(input())
start = str(n)
prime_factors = []
while n >= 2:
prime_factors.append(str(smallest_factor(n)))
n //= smallest_factor(n)
print(start + ': '+ ' '.join(prime_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 | n = int(input())
def prime_factorization(n):
factor = []
for i in range(2, int(n ** 0.5) + 1):
while (n % i == 0):
factor.append(i)
n //= i
if n != 1:
factor.append(n)
return factor
res = prime_factorization(n)
tmp = [str(n) + ':']
res = tmp + res
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<queue>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
int main(){
int n,i;
scanf("%d\n",&n);
printf("%d:",n);
for(i=2;i*i<=n;i++){
while(n%i==0){
printf(" %d",i);
n=n/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 | # 68
def factorization(n):
ans = []
_max = int(n ** 0.5 + 1)
while n % 2 == 0:
n //= 2
ans.append(2)
for i in range(3, _max+1, 2):
while n % i == 0:
n //= i
ans.append(i)
if n != 1:
ans.append(n)
return ans
n = int(input())
ans = factorization(n)
print(n, ": ", sep="", end="")
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 <iostream>
#include <vector>
using namespace std;
// vector
template<typename T>
vector<T> trialDivision(T a) {
vector<T> res;
T i = 2;
while (i * i <= a) {
if (a % i == 0) {
a /= i;
res.push_back(i);
}
else ++i;
}
if (a != 1) res.push_back(a);
return res;
}
int main() {
int n;
cin >> n;
cout << n << ':';
for (int& i : trialDivision(n)) cout << ' ' << 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 | # import numpy as np
import math
n = int(input());
orig = n
i = 2
l = []
while i<=math.sqrt(orig):
while n%i== 0:
n /= i
l.append(i)
i += 1
if n != 1:
l.append(int(n))
# if len(l) == 0:
# print("{0}: {1}".format(orig, orig))
# else:
print("{}:".format(orig), *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>
#include <vector>
using namespace std;
vector<int> factorize(int n) {
vector<int> ps;
for (int i = 2; i * i <= n; ++i) {
while (n % i == 0) {
ps.push_back(i);
n /= i;
}
}
if (n != 1) ps.push_back(n);
return ps;
}
int main()
{
int n;
cin >> n;
vector<int> ps = factorize(n);
cout << n << ':';
for (vector<int>::iterator it = ps.begin(); it != ps.end(); ++it) {
cout << ' ' << *it;
}
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 <cmath>
using namespace std;
int main()
{
unsigned long n = 0;
cin >> n;
cout << n << ":";
for (unsigned long i = 2; i <= sqrt(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.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.ArrayList;
import java.nio.charset.Charset;
import java.util.StringTokenizer;
import java.util.Map;
import java.io.OutputStreamWriter;
import java.io.OutputStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.util.Objects;
import java.util.List;
import java.util.Map.Entry;
import java.io.Writer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*
* @author mikit
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
LightScanner in = new LightScanner(inputStream);
LightWriter out = new LightWriter(outputStream);
NTL_1_A solver = new NTL_1_A();
solver.solve(1, in, out);
out.close();
}
static class NTL_1_A {
public void solve(int testNumber, LightScanner in, LightWriter out) {
// out.setBoolLabel(LightWriter.BoolLabel.YES_NO_FIRST_UP);
long n = in.longs();
Map<Long, Integer> m = IntMath.primeFactorize(n);
out.ans(n + ":");
List<Map.Entry<Long, Integer>> ents = new ArrayList<>(m.entrySet());
ents.sort(Comparator.comparing(Map.Entry::getKey));
for (Map.Entry<Long, Integer> ent : ents) {
for (int i = 0; i < ent.getValue(); i++) {
out.ans(ent.getKey());
}
}
out.ln();
}
}
static final class IntMath {
private IntMath() {
}
public static Map<Long, Integer> primeFactorize(long p) {
Map<Long, Integer> factor = new HashMap<>();
if ((p & 1) == 0) {
int c = 0;
do {
c++;
p >>= 1;
} while ((p & 1) == 0);
factor.put(2L, c);
}
for (long i = 3; i * i <= p; i += 2) {
if (p % i == 0) {
int c = 0;
do {
c++;
p /= i;
} while ((p % i) == 0);
factor.put(i, c);
}
}
if (p > 1) {
factor.put(p, 1);
}
return factor;
}
}
static class LightWriter implements AutoCloseable {
private final Writer out;
private boolean autoflush = false;
private boolean breaked = true;
public LightWriter(Writer out) {
this.out = out;
}
public LightWriter(OutputStream out) {
this(new BufferedWriter(new OutputStreamWriter(out, Charset.defaultCharset())));
}
public LightWriter print(char c) {
try {
out.write(c);
breaked = false;
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return this;
}
public LightWriter print(String s) {
try {
out.write(s, 0, s.length());
breaked = false;
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
return this;
}
public LightWriter ans(String s) {
if (!breaked) {
print(' ');
}
return print(s);
}
public LightWriter ans(Object obj) {
return ans(Objects.toString(obj));
}
public LightWriter ln() {
print(System.lineSeparator());
breaked = true;
if (autoflush) {
try {
out.flush();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
return this;
}
public void close() {
try {
out.close();
} catch (IOException ex) {
throw new UncheckedIOException(ex);
}
}
}
static class LightScanner {
private BufferedReader reader = null;
private StringTokenizer tokenizer = null;
public LightScanner(InputStream in) {
reader = new BufferedReader(new InputStreamReader(in));
}
public String string() {
if (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
return tokenizer.nextToken();
}
public long longs() {
return Long.parseLong(string());
}
}
}
| 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 soinsu(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 [str(_) for _ in a]
ans = str(n) + ': ' + ' '.join(soinsu(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 | public class Main{
public static void main(String[] args){
int i,j;
int val = new java.util.Scanner(System.in).nextInt();
int a=2;
System.out.print(val + ":");
while(val>=a*a){
if(val%a==0){
System.out.print(" " + a);
val/=a;
}else{
a++;
}
}
System.out.println(" " + val);
}
} | 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
import copy
n = int(input())
ncopy = copy.deepcopy(n)
ans = []
while True:
if n % 2 == 1:
break
ans.append(str(2))
n //= 2
i = 3
while True:
if i**2 > n:
break
if n % i == 0:
ans.append(str(i))
n //= i
else:
i += 2
if n != 1:
ans.append(str(n))
print(str(ncopy)+": "+(" ".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 | 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(f"{n}:", " ".join(list(map(str, 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 | n = int(input())
a = []
now = n
for i in range(2, n):
while now % i == 0:
now //= i
a.append(i)
if i * i > n:
break
if now != 1:
a.append(now)
print(str(n) + ":", end = "")
for i in a:
print(" " + str(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 | n = int(input())
n1 = n
a = 2
x = []
while a*a <= n:
while n % a == 0:
n //= a
x.append(str(a))
a += 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 | #include<math.h>
#include <iostream>
using namespace std;
void Factorization(int v){
int k = 2;
while ( k <= (int)sqrt((double) v)){
if (v % k == 0){
v = v / k;
cout<<" "<<k;
k = 2;
}
else
k++;
}
cout<<" "<<v;
}
int main(){
int n;
cin>>n;
cout<<n<<":";
Factorization(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<cstdio>
#include<vector>
using namespace std;
typedef long long int ll;
int N;
vector<int>X;
int main()
{
scanf("%d",&N);
int M=N;
for(int i=2;i*i<=M;i++){
while(true){
if(N%i==0){
X.push_back(i);
N/=i;
}
else break;
}
}
if(N!=1)X.push_back(N);
printf("%d:",M);
for(int i=0;i<X.size();i++){
printf(" %d",X[i]);
}
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 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 | n = int(input())
tmp = n
fact = []
for i in range(2,int(-(-n**0.5//1))+1):
while tmp%i == 0:
fact.append(str(i))
tmp //= i
if tmp != 1:
fact.append(str(tmp))
#print(fact)
print(str(n) + ': ' + " ".join(fact))
| 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())
A = []
def is_prime(n):
if n<2:return False
for i in range(2,n):
if i*i>n:break
if n%i==0:return False
return True
n = N
if is_prime(n):
A.append(n)
n=1
for i in range(2,N):
if n%i==0:
while n>1:
A.append(i)
n//=i
if n%i!=0:break
if n==1:break
print(str(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 <bits/stdc++.h>
using namespace std;
int main(){
long long 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<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int N;
vector<int> v;
int main() {
cin >> N;
int n = N;
cout << N << ":";
for (int i = 2; i*i <N; ++i) {
while (n%i == 0) {
cout <<" " << i;
n /= i;
}
if (n == 1) 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())
ans = []
m = n
for p in range(2, n + 1):
if p**2 > n or m == 1:
break
while m % p == 0:
m //= p
ans.append(p)
if m > 1:
ans.append(m)
print('{}: '.format(n), end='')
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 <cmath>
#include <iostream>
using namespace std;
/*int a[1000000001];
int devidenumber(int m) {
if(a[m]!=0) return m/a[m];
else {
int k=2;
while(m%k!=0) ++k;
a[m]=k;
return m/k;
}
}
*/
int n;
int main() {
cin >> n;
cout << n << ":";
while(n !=1) {
int k=2;
while((n%k!=0) && (k <= sqrt(n))) ++k;
if (k > sqrt(n)) {
cout << " " << n;
break;
} else {
n = n/k;
cout << " " << k;
k=2;
}
}
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.IOException;
import java.io.InputStream;
import java.util.*;
public class Main {
public static void main(String[] args) {
FastScanner sc = new FastScanner();
int n = sc.nextInt();
TreeMap<Integer, Integer> map = new TreeMap<>();
int m = n;
for (int i = 2; i <= Math.sqrt(n); i++) {
int count = 0;
while (m % i == 0) {
count++;
m /= i;
}
if (count > 0) {
map.put(i, count);
}
}
if (m != 1) {
map.put(m, 1);
}
System.out.print(n + ":");
for (int key: map.keySet()) {
System.out.print(" ");
for (int i = 0; i < map.get(key); i++) {
System.out.print(key);
if (i != map.get(key) - 1) {
System.out.print(" ");
}
}
}
System.out.println();
}
}
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 || Integer.MAX_VALUE < nl) {
throw new NumberFormatException();
}
return (int) nl;
}
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 | #include <iostream>
#include <math.h>
using namespace std;
void Factorization(int v){
int k = 2;
while (v != 1 && k <= sqrt((double) v)){
if (v % k == 0){
v = v / k;
cout<<" "<<k;
k = 2;
}
else
k++;
}
if(v == 1) return;
cout<<" "<<v;
}
int main(){
int n;
cin>>n;
cout<<n<<":";
Factorization(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;
int main(){
int n;
cin >> n;
cout << n << ':';
for (int i = 2; i * i <= n; i++){
if (n % i == 0){
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 | 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 | #include<iostream>
#include<math.h>
using namespace std;int main(){int n;cin>>n;cout<<n<<":";for(int i=2;i<sqrt(n)+1;i++){while(1){if(n%i!=0)break;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())
# n<= 10**9なので、高速化する
# 約数列挙でroot N に抑えるか?
def prime_divide(n):
res = []
i = 2
while True:
if n % i == 0:
res.append(i)
n //= i
else:
i += 1
if i > n ** (0.5):
break
if n != 1:
res.append(n)
return res
print(n, end="")
print(":", *prime_divide(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())
def prime_factorize(n):
fac = []
if n < 2: return fac
while n%2 == 0:
n //= 2
fac.append(2)
for i in range(3,int(n**0.5)+1,2):
while n%i == 0:
n //= i
fac.append(i)
if n != 1: fac.append(n)
return fac
print("{}: {}".format(n," ".join(map(str,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 | #include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
int n;
cin >> n;
cout << n << ":";
while (!(n % 2)) {
cout << " 2";
n /= 2;
}
for (int i = 3; i <= sqrt(n); i += 2) {
while (!(n % i)) {
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.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main{
public static void main(String[] args){
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
long n = Long.parseLong(br.readLine());
System.out.print(n + ":");
primeFact(n);
} catch (Exception e) {
e.printStackTrace();
}
}
static void primeFact (long n) {
for (long sqrtRel = 2; sqrtRel*sqrtRel <= n;) {
if (n%sqrtRel == 0) {
System.out.print(" " + sqrtRel);
n = n/sqrtRel;
} else {
sqrtRel++;
}
}
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 | #include<stdio.h>
int main(){
int a,b;
scanf("%d",&a);
printf("%d:",a);
b=2;
while(a>=b*b){
if(a%b==0){
printf(" %d",b);
a=a/b;
} else {
b++;
}
}
printf(" %d\n",a);
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<cstdio>
int main() {
int n, k;
scanf("%d", &n);
printf("%d:", n);
while (n % 2 == 0) {
printf(" 2");
n /= 2;
}
for (k = 3; n>1; k += 2) {
if (k*k > n) {
printf(" %d", n);
break;
}
while (n%k == 0) {
printf(" %d", k);
n /= k;
}
}
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 | #coding utf-8
import math
import copy
n = int(input())
m = copy.copy(n)
A = []
for i in range(2,int(math.sqrt(m))+2):
if n == 1:
break
if n % i == 0:
while n % i == 0:
A.append(str(i))
n //= i
if n > 1:
A.append(str(n))
print(str(m) + ': ' + ' '.join(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;int x=n;
cout << n << ":";
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 | import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
long n = Long.parseLong(br.readLine());
printFactor(n);
} catch (Exception e) {
e.printStackTrace();
}
}
private static void printFactor(long n) {
System.out.print(n + ":");
factorize(n, 3);
}
private static void factorize(long n, long r) {
if (n == 1) {
System.out.println();
return;
}
System.out.print(" ");
if (isPrime(n)) {
System.out.print(n);
System.out.println();
return;
} else if (n % 2 == 0) {
System.out.print(2);
n = n / (long) 2;
} else {
for (long i = r; i <= n; i += 2) {
if (n % i == 0) {
r = i;
System.out.print(i);
n = n / i;
break;
}
}
}
factorize(n, r);
}
private static boolean isPrime(long n) {
if (n == 2) {
return true;
}
if (n < 2 || n % 2 == 0) {
return false;
}
int i = 3;
while (i <= Math.sqrt((double) n)) {
if (n % i == 0) {
return false;
}
i = i + 2;
}
return true;
}
} | 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
n = int(input())
k = n
l = []
for i in range(2, int(math.sqrt(n))+1):
while k % i ==0:
l.append(i)
k = k // i
if k == 1:
break
if k != 1:
l.append(k)
print("{}: ".format(n),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 | n=int(input())
x=n
ans=[]
for i in range(2,int(x**0.5)+1):
if n%i==0:
while n%i==0:
ans.append(i)
n//=i
if ans==[]:
ans.append(x)
elif n!=1:
ans.append(n)
print(str(x)+": "+" ".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 | import math
i = int(input())
print(i,end="")
print(":",end="")
while i>1:
d=2
while i%d != 0:
if d>=math.sqrt(i):
d=i
break
d += 1
print(" ",end="")
print(d, end="")
i = i // d
print()
| PYTHON3 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.