`{"id":"4e98e657-d844-4f7c-91fd-0b959636fdb0","name":"Prime Factorisation Of A Number","description":"<p>1. You are required to display the prime factorisation of a number.</p><p>2. Take as input a number n.</p><p>3. Print all its prime factors from smallest to largest.</p><p><br></p><p>For example:</p><p>for n = 1440, the output should be: 2 2 2 2 2 3 3 5</p>","inputFormat":"<p>n, an integer</p>","outputFormat":"<p>p1 p2 p3 p4.. all prime factors of n</p>","constraints":"<p>2 &lt;= n &lt; 10 ^ 9</p>","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\nint main(int argc, char **argv){\r\n int n;\r\n cin >> n;\r\n\r\n //write your code here\r\n\r\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) {\r\n // write your code here \r\n }\r\n}"},"python":{"code":"def primeFac(n):\n # write your code here\n\ndef main():\n n = int(input())\n primeFac(n)\n\nif __name__==\"__main__\":\n main()"}},"points":10,"difficulty":"easy","sampleInput":"1440","sampleOutput":"2 2 2 2 2 3 3 5","questionVideo":"https://www.youtube.com/embed/P97Ms8kSzjg","hints":[],"associated":[{"id":"08ada9bb-a18a-4d91-a39d-fd9e331653e6","name":"Which one of the following is the most optimized method for this problem?","slug":"which-one-of-the-following-is-the-most-optimized-method-for-this-problem","type":4},{"id":"5bed8eb0-83f1-47de-bfd0-14788fe8c83f","name":"What is the time complexity of the Trial Division Method?","slug":"what-is-the-time-complexity-of-the-trial-division-method","type":4},{"id":"8f3c3fe2-f791-42a5-bb54-3ca21f3cb12c","name":"What is the time complexity of the sieve of eratosthenes ?","slug":"what-is-the-time-complexity-of-the-sieve-of-eratosthenes","type":4},{"id":"967c655a-c2bc-4a6c-a2d3-35c977b9469c","name":"What is the space complexity of the Trial Division Method?","slug":"what-is-the-space-complexity-of-the-trial-division-method","type":4},{"id":"c1cce531-9623-406e-a0e6-1b16dc4a0910","name":"What is the space complexity of the sieve of eratosthenes ?","slug":"what-is-the-space-complexity-of-the-sieve-of-eratosthenes","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"72157774-7fd0-4b8e-88dc-037800acd626","name":"Getting Started","slug":"getting-started-9996","type":0},{"id":"9dd7eb3a-d777-42a7-a098-778cd7c89ba0","name":"Prime Factorisation Of A Number","slug":"prime-factorisation-of-a-number","type":1}],"next":{"id":"932b4611-7872-49bb-8975-6b5090f7e0f0","name":"Prime Factorisation Of A Number","type":3,"slug":"prime-factorisation-of-a-number"},"prev":{"id":"2b40107a-a78c-4a0e-9a90-db3f529150bb","name":"Gcd And Lcm","type":3,"slug":"gcd-and-lcm"}}}`

# Prime Factorisation Of A Number

<p>1. You are required to display the prime factorisation of a number.</p><p>2. Take as input a number n.</p><p>3. Print all its prime factors from smallest to largest.</p><p><br></p><p>For example:</p><p>for n = 1440, the output should be: 2 2 2 2 2 3 3 5</p>

`{"id":"4e98e657-d844-4f7c-91fd-0b959636fdb0","name":"Prime Factorisation Of A Number","description":"<p>1. You are required to display the prime factorisation of a number.</p><p>2. Take as input a number n.</p><p>3. Print all its prime factors from smallest to largest.</p><p><br></p><p>For example:</p><p>for n = 1440, the output should be: 2 2 2 2 2 3 3 5</p>","inputFormat":"<p>n, an integer</p>","outputFormat":"<p>p1 p2 p3 p4.. all prime factors of n</p>","constraints":"<p>2 &lt;= n &lt; 10 ^ 9</p>","sampleCode":{"cpp":{"code":"#include <iostream>\r\nusing namespace std;\r\nint main(int argc, char **argv){\r\n int n;\r\n cin >> n;\r\n\r\n //write your code here\r\n\r\n}"},"java":{"code":"import java.util.*;\r\n\r\npublic class Main{\r\n\r\npublic static void main(String[] args) {\r\n // write your code here \r\n }\r\n}"},"python":{"code":"def primeFac(n):\n # write your code here\n\ndef main():\n n = int(input())\n primeFac(n)\n\nif __name__==\"__main__\":\n main()"}},"points":10,"difficulty":"easy","sampleInput":"1440","sampleOutput":"2 2 2 2 2 3 3 5","questionVideo":"https://www.youtube.com/embed/P97Ms8kSzjg","hints":[],"associated":[{"id":"08ada9bb-a18a-4d91-a39d-fd9e331653e6","name":"Which one of the following is the most optimized method for this problem?","slug":"which-one-of-the-following-is-the-most-optimized-method-for-this-problem","type":4},{"id":"5bed8eb0-83f1-47de-bfd0-14788fe8c83f","name":"What is the time complexity of the Trial Division Method?","slug":"what-is-the-time-complexity-of-the-trial-division-method","type":4},{"id":"8f3c3fe2-f791-42a5-bb54-3ca21f3cb12c","name":"What is the time complexity of the sieve of eratosthenes ?","slug":"what-is-the-time-complexity-of-the-sieve-of-eratosthenes","type":4},{"id":"967c655a-c2bc-4a6c-a2d3-35c977b9469c","name":"What is the space complexity of the Trial Division Method?","slug":"what-is-the-space-complexity-of-the-trial-division-method","type":4},{"id":"c1cce531-9623-406e-a0e6-1b16dc4a0910","name":"What is the space complexity of the sieve of eratosthenes ?","slug":"what-is-the-space-complexity-of-the-sieve-of-eratosthenes","type":4}],"solutionSeen":false,"tags":[],"meta":{"path":[{"id":0,"name":"home"},{"id":"0c54b191-7b99-4f2c-acb3-e7f2ec748b2a","name":"Data Structures and Algorithms","slug":"data-structures-and-algorithms","type":0},{"id":"72157774-7fd0-4b8e-88dc-037800acd626","name":"Getting Started","slug":"getting-started-9996","type":0},{"id":"9dd7eb3a-d777-42a7-a098-778cd7c89ba0","name":"Prime Factorisation Of A Number","slug":"prime-factorisation-of-a-number","type":1}],"next":{"id":"932b4611-7872-49bb-8975-6b5090f7e0f0","name":"Prime Factorisation Of A Number","type":3,"slug":"prime-factorisation-of-a-number"},"prev":{"id":"2b40107a-a78c-4a0e-9a90-db3f529150bb","name":"Gcd And Lcm","type":3,"slug":"gcd-and-lcm"}}}`

Editor

# Prime Factorisation Of A Number

easy

1. You are required to display the prime factorisation of a number.

2. Take as input a number n.

3. Print all its prime factors from smallest to largest.

For example:

for n = 1440, the output should be: 2 2 2 2 2 3 3 5

2 <= n < 10 ^ 9

## Format

n, an integer

### Output

p1 p2 p3 p4.. all prime factors of n

## Example

Sample Input

`.css-23h8hz{color:inherit;font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;}1440`

### Sample Output

`.css-3oaykw{color:var(--chakra-colors-active-primary);font-size:0.875rem;line-height:1.125rem;letter-spacing:0.016rem;font-weight:var(--chakra-fontWeights-normal);white-space:pre-wrap;font-family:Monospace;}2 2 2 2 2 3 3 5`

Question Video

Discussions

Show Discussion

Related Resources