ABC

  abc.go.com
Work in HR? Unlock Free Profile

ABC Systems Analyst Interview Question

"Write a function that checks if a number's divisors sum up to that number, i.e. whether it's a perfect number or not."
Add Tags [?]
Answer

Part of a Systems Analyst Interview Review - one of 74 ABC Interview Reviews

Answers & Comments

0
of 0
votes

This is what my function ended up looking like. I know it's a naive implementation but I figured that solving it was more important than efficiency. How wrong I was...

bool isPerfect(int value) {
    int i, total = 0;
    for (i = 1; i <= value; i++) {
        if (value % i == 0) {
            total += i;
        }
    }
    if (total == value) {
        return TRUE;
    } else {
        return FALSE;
    }
}

When I was done, the guy asked me what I could do to improve the efficiency of the programme. For example, how would you make it so you could calculate, say, 4,000,000 trivially? I stumbled on this part and, after a few minutes of no progress, he decided to give me a different question.

- Interview Candidate on Apr 20, 2011

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.