Thread: The "nearly perfect number" problem

  1. #1
    Registered User
    Join Date
    Jul 2015
    Posts
    22

    The "nearly perfect number" problem

    Hey guys,
    I will head to the problem right now.
    N is a natural number. K is one of the divisors of N satisfied K<N.
    Then, S is the sum of all K.

    For example: S(18) = 1+3+6+9 = 21

    The problem is: given 2 number L and D (2<=L<=1000, 0<=D<=10000). Find the number of natural numbers (<L) such that the difference between each natural number and its S can't be greater than D.

    For example: L = 10, D = 1. Then we obtain 5 numbers satisfied: 1, 2, 4, 6 and 8.

    Any ideas???
    Many thanks.

  2. #2
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    No. Your definitions and your example do not match; the puzzle is ill-defined. Contradictory.

    Let's redefine the variables.

    Let Ki(N) be the divisors of N, with 1 ≤ Ki(N) < N.
    Let A(N) be the sum of Ki, i.e. the sum of the divisors of N.
    Let Si(N) be A(N) - Ki(N), i.e. the sum of the divisors of N except one divisor. Then,
    N is a perfect number if and only if N = A(N)
    and
    N is a nearly perfect number if N = Si(N) exists
    (it does not matter for which i, as long as it exists)
    Note that each N corresponds to a single value A(N), but one or more Si(N).

    (The number of i for Si(N) is the number of divisors in N, including 1 as a divisor.)

    The issue with your problem statement is that you treat Si(N) as if it was unique. It isn't. Therefore, "Si(N) can't be greater than D" is ambiguous.

    As an example, the divisors of 18 are 1, 2, 3, 6, and 9. So,
    K1(18) = 1
    K2(18) = 2
    K3(18) = 3
    K4(18) = 6
    K5(18) = 9
    A(18) = 1 + 2 + 3 + 6 + 9 = 21
    S1(18) = 21 - 1 = 20
    S2(18) = 21 - 2 = 19
    S3(18) = 21 - 3 = 18
    S4(18) = 21 - 6 = 15
    S5(18) = 21 - 9 = 12


    I suspect that you are trying to:
    Count the number of natural numbers N, 2 ≤ NL, for which ∥Si(N) - N∥ ≤ D exists.
    The problem is limited to 2 ≤ L ≤ 1000 and 0 ≤ D ≤ 10000.

    There are other interpretations, too -- in particular, you might be looking at combinations with 0 to D Ki's subtracted from A instead --, so you do need to redefine your problem before any help is possible.
    Last edited by Nominal Animal; 09-18-2015 at 11:51 AM.

  3. #3
    Registered User
    Join Date
    Jul 2015
    Posts
    22
    I'm sorry I didn't make it clear. You can look at the following example:
    Given L = 10, D = 1.
    Then we obtain 5 numbers: 1, 2, 4, 6 and 8 because:
    - all of them are < 10
    + with N = 1: it has no such divisor K like that so S = 0 -> N - S = 1 - 0 = 1 = D (satisfied)
    + with N = 2: it has only one divisor K = 1 -> S = 1 -> N - S = 2 - 1 = 1 = D (satisfied)
    + with N = 4: K= 1; 2 -> S = 1+2 = 3 -> N - S = 4 - 3 = 1 = D (satisfied)
    ,...etc

    What i want is only to find the number of natural numbers N satisfied. That means, in above example, 5

  4. #4
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    Quote Originally Posted by Nhân Trần View Post
    I'm sorry I didn't make it clear.
    You didn't make it any clearer, though.

    Let me put it simply. Your example for S, "S(18) = 1+3+6+9 = 21", makes no sense, because the divisors of 18 are 1, 2, 3, 6, and 9.

  5. #5
    Registered User
    Join Date
    Jul 2015
    Posts
    22
    That's my typo mistake. Can u just concentrate on the example with given L and D

  6. #6
    Ticked and off
    Join Date
    Oct 2011
    Location
    La-la land
    Posts
    1,728
    It is not a typo; if it were, then we'd be talking about perfect numbers, not nearly perfect numbers.

    A perfect number is one whose divisors (including 1 but excluding the number itself) add up to the number itself.

    A nearly perfect number is one whose divisors (including 1 but excluding the number itself), if you omit one of those divisors, add up to the number itself. Check out this PDF about nearly perfect numbers.

    Your problem as is is ill-defined; like asking how many blue apples you have, if you have two deflated balloons. It does not make sense, because it is self-contradictory. You need to first fix your problem definition, before we can help you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 12-08-2014, 08:12 PM
  2. Problem with coding "Random Number Guessing Game" (Beginner)
    By DecoratorFawn82 in forum C++ Programming
    Replies: 13
    Last Post: 03-02-2013, 01:38 AM
  3. Pixel perfect collision / "terrain" destruction
    By cboard_member in forum Game Programming
    Replies: 1
    Last Post: 09-09-2006, 12:54 PM
  4. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 08:25 AM
  5. "CWnd"-"HWnd","CBitmap"-"HBitmap"...., What is mean by "
    By L.O.K. in forum Windows Programming
    Replies: 2
    Last Post: 12-04-2002, 07:59 AM