Strange order
Practice
4.6 (5 votes)
Mathematics
Approved
Easy Medium
Factorization
Problem
94% Success 3064 Attempts 30 Points 2s Time Limit 512MB Memory 1024 KB Max Code
Given an integer n. Initially you have permutation p of size n: \(p_i = i\). To build new array a from p following steps are done while permutation p is not empty:
- Choose maximum existing element in p and define it as x;
- Choose all such y in p that \(\gcd(x, y) \neq 1\);
- Add all chosen numbers into array a in decreasing order and remove them from permutation.
Your task is to find a after p became empty.
Note: \(\gcd(a, b)\) is the greatest common divisor of integers a and b.
Input format
Input contains single integer n (\(1 \leq n \leq 2 \cdot 10^6\)) — the size of permutation p.
Output format
Print n integers — array a.
Submissions
Please login to view your submissions
Similar Problems
Points:30
2 votes
Tags:
Integer FactorizationMathImplementationMathematicsSieveBasics of ImplementationNumber Theory
Points:30
Tags:
MathematicsEasy-MediumFactorization
Points:30
1 votes
Tags:
Hash functionData StructuresEasy-MediumMathematicsapprovedFactorization
Editorial