Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Count Total Prime Factors Including Repetitions

Basic Acceptance 87.32% Points 10.00

You are given a positive integer n. Your task is to return the total number of prime factors, counting repeated factors separately.

Examples
Example 1

Input: n = 60
Output: 4
Explanation: The prime factorization of 60 is 2 × 2 × 3 × 5. Counting repeated factors, there are 4 prime factors in total.

Example 2

Input: n = 8
Output: 3
Explanation: The prime factorization of 8 is 2 × 2 × 2. Therefore, the total number of prime factors is 3.

Example 3

Input: n = 1
Output: 0
Explanation: The number 1 has no prime factors, so the total count is 0.

Constraints
  • 1 = n = 10¹²
Companies
Apple ServiceNow
Topics
Data Structures Basics Hashing Basics
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions