FastPrepSum of Distinct Prime Divisors
Problems/Sum of Distinct Prime Divisors

Sum of Distinct Prime Divisors

Microsoft logoMicrosoft● MediumNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: A Microsoft Data Scientist internship report describes a coding task as the sum of prime divisors. The wording is unclear, so we chose to count each prime once, to use a positive long input, to return a set answer for n=1, and the limits.

Given a positive integer n, return the sum of its distinct prime divisors.

Each prime divisor contributes once, regardless of its exponent in the factorization. For n = 1, return 0.

Function

sumDistinctPrimeDivisors(n: long) → long

Examples

Example 1

n = 12return = 5

The distinct prime divisors of 12 are 2 and 3, whose sum is 5.

Example 2

n = 13return = 13

Because 13 is prime, it is its only prime divisor.

Constraints

  • 1 <= n <= 10^12

More Microsoft Onsite Interview questions

  • Bad Request AlertsONSITE INTERVIEW · Seen Nov 2026
  • Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2026
  • Valid ParenthesesONSITE INTERVIEW · Seen Nov 2026
  • Count a User's Actions in an Event LogONSITE INTERVIEW · Seen Nov 2026
  • Smallest Batch Size Within a Step LimitONSITE INTERVIEW · Seen Nov 2026
  • Count Subarrays with Equal Even and Odd CountsONSITE INTERVIEW · Seen Nov 2026
  • Minimum Time to Rot All OrangesONSITE INTERVIEW · Seen Nov 2026
  • Coin ChangeONSITE INTERVIEW · Seen Oct 2026
  • Daily USD Totals with Effective-Dated Exchange RatesONSITE INTERVIEW · Seen Oct 2026
  • Number Words to Digits in Any LanguageONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Random Bingo Card GeneratorUber · ONSITE INTERVIEWUber interview questions
  • Path Between Two Nodes of a Fibonacci TreeDatabricks · PHONE SCREEN · ONSITE INTERVIEWDatabricks interview questions
  • Streaming Entropy, Part 2: Numerically Stable EntropyOpenAI · PHONE SCREEN · ONSITE INTERVIEWOpenAI interview questions
  • Integers With Multiple Sum of Two CubesCharta Health · PHONE SCREEN · ONSITE INTERVIEWCharta Health interview questions
  • Dice-Walk Winning ProbabilityGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
  • Retrieve Vectors by Cosine SimilarityHarvey · ONSITE INTERVIEWHarvey interview questions
  • Integer BreakAmazon · ONSITE INTERVIEW
  • Knight Probability in ChessboardGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Count Staircases with Strictly Increasing StepseBay · ONSITE INTERVIEWeBay interview questions
  • Babysitter Quote with Hourly RatesUpstart · ONSITE INTERVIEWUpstart interview questions

Interview reports that mention this question

  • Microsoft AI/ML Intern Interviews: 114 Experiences (Part 1 of 2)

Microsoft interview experiences

  • Microsoft OA Questions, October 2026: 4 Experiences
  • Microsoft Experienced SWE Phone Screen: 1 Experience
  • Microsoft Explore and Student SWE: 12 Experiences (Part 6 of 6)
  • Microsoft SWE Intern, Early 2025: 41 Experiences (Part 5 of 6)
  • Microsoft SWE Intern, Mid 2025: 42 Experiences (Part 4 of 6)
All Microsoft interview questionsSee Microsoft hiring insights
Saved
class Solution {
    public long sumDistinctPrimeDivisors(long n) {
      // Write your code here.
    }

}
Checking account…