Pls Help me with this problem...

This is a discussion on Pls Help me with this problem... within the C++ Programming forums, part of the General Programming Boards category; Gregorio is very interested in discovering properties of non-negative integers. In one of his mathematical excursions, he tried adding all ...

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    3

    Pls Help me with this problem...

    Gregorio is very interested in discovering properties of non-negative integers. In one of his mathematical excursions, he tried adding all the digits of a number. Of course he ended up with a new number. He performed the same process using this new number and he got another number. If this process is one repeatedly, he realized that it always converge to a number. For example, the number 12345 converges to 6 and 99999 converges to 9.
    12345 >> 15 >> 6 >> 6
    99999 >> 45 >> 9 >> 9
    Gregorio tasked himself in discovering the number of non-negative integers from x to y that converge to a given number z. Help Gregorio develop a program that will automate this task.

    INPUT FORMAT
    The input consists of several input lines. Each input line consists of three non-negative integers: x, y, and z. The numbers x and y are respectively the start and end points of the given range of integers. The number z is the point of convergence.

    OUTPUT FORMAT
    For each input line, output the number of non-negative integers from x to y that converge to z. If
    x > y then output 0.

    SAMPLE INPUT
    0 10 1
    12345 12347 7


    SAMPLE OUTPUT
    2
    1


    Or just give me some clues on how to solve this.. =)) thx..

  2. #2
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    Heres a clue, call it a nudge in the right direction if you will...

    "Do some work"

    Then post some kind of effort that shows at least you have bothered to think about how to do it. Instead of just copying and pasting your problem out.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  3. #3
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by rogster001 View Post
    Heres a clue, call it a nudge in the right direction if you will...

    "Do some work"

    Then post some kind of effort that shows at least you have bothered to think about how to do it. Instead of just copying and pasting your problem out.
    btw..do you understand what he wants to do? Because, I don't..but it looks like it might be good for a beginner like me to program..

    so x and y are the inputs and z is the result

    but what should we do, or rather do you want to do on x and y

    i get this part
    12345 >> 15 >> 6 >> 6
    99999 >> 45 >> 9 >> 9
    but it doesn't make sense with this:



    prolink24
    Pls Help me with this problem...
    Gregorio is very interested in discovering properties of non-negative integers. In one of his mathematical excursions, he tried adding all the digits of a number. Of course he ended up with a new number. He performed the same process using this new number and he got another number. If this process is one repeatedly, he realized that it always converge to a number. For example, the number 12345 converges to 6 and 99999 converges to 9.
    12345 >> 15 >> 6 >> 6
    99999 >> 45 >> 9 >> 9
    Gregorio tasked himself in discovering the number of non-negative integers from x to y that converge to a given number z. Help Gregorio develop a program that will automate this task.

    INPUT FORMAT
    The input consists of several input lines. Each input line consists of three non-negative integers: x, y, and z. The numbers x and y are respectively the start and end points of the given range of integers. The number z is the point of convergence.

    OUTPUT FORMAT
    For each input line, output the number of non-negative integers from x to y that converge to z. If
    x > y then output 0.

    SAMPLE INPUT
    12345 12347 7


    SAMPLE OUTPUT
    1

    how did you get 1 as output?
    You ended that sentence with a preposition...Bastard!

  4. #4
    Registered User rogster001's Avatar
    Join Date
    Aug 2006
    Location
    Liverpool UK
    Posts
    1,438
    btw..do you understand what he wants to do?
    mate a post like that gets about one nanosecond of reading time in my case.

    After reading it i see it is purest wofflese, it could be an interesting puzzle if it were explained properly, at present it makes about 0 sense, its like 'so what'? obviously you can expect a number? is there supposed to be some kind of special relationship going on?

    how did you get 1 as output?
    He means essentially 'true or false'

    I think its supposed to (or i would) output each number 'string' tested and then show a 0 or 1 for its result
    it would probably be cool to show each number stepping down to its final figure but that has not been stated as a requirement.
    Last edited by rogster001; 01-18-2011 at 08:46 AM.
    Thought for the day:
    "Are you sure your sanity chip is fully screwed in sir?" (Kryten)
    FLTK: "The most fun you can have with your clothes on."

    Stroustrup:
    "If I had thought of it and had some marketing sense every computer and just about any gadget would have had a little 'C++ Inside' sticker on it'"

  5. #5
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by rogster001 View Post
    mate a post like that gets about one nanosecond of reading time in my case.
    harsh..lol

    but yeah, it made sense until the very end..and I am like..wt..f!!
    hopefully the OP clarifies what he wants
    You ended that sentence with a preposition...Bastard!

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Eman View Post
    btw..do you understand what he wants to do? Because, I don't..but it looks like it might be good for a beginner like me to program..
    It's numerology....

    12345 = 1 + 2 + 3 + 4 + 5 = 15 = 1 + 5 = 6

    1900 + 45 = 1945 = 1 + 9 + 4 + 5 = 19 = 1 + 9 = 10 = 1 + 0 = 1

    You keep adding the individual digits of a number until you resolve (converge) it to a single digit number...
    Last edited by CommonTater; 01-18-2011 at 08:51 AM.

  7. #7
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    yeah I got that part, I am not sure as to how he got 7 with this:

    12345 12347 7

    perhaps he meant 9?
    You ended that sentence with a preposition...Bastard!

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,159
    No, he got 1 with that, not 7. (Remember, the output is a count, not the result of any particular recursive sum.)
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    the reason I am asking is that..if 1 and 0 are the respective output
    why was is
    Sample Output 2 for the first input?
    You ended that sentence with a preposition...Bastard!

  10. #10
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,159
    Quote Originally Posted by Eman
    the reason I am asking is that..if 1 and 0 are the respective output
    why was is
    Sample Output 2 for the first input?
    Because the recursive sum of the digits of 1 and 10 are both 1, hence the count is 2.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  11. #11
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Quote Originally Posted by laserlight View Post
    Because the recursive sum of the digits of 1 and 10 are both 1, hence the count is 2.
    yeah..so the count for this:
    12345 12347 7
    is 0?
    You ended that sentence with a preposition...Bastard!

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,159
    No, it is 1. I don't know (and don't care) which of 12345, 12346 and 12347 is the one, but whatever it is it took me about 2 minutes to write and run a program to determine that the answer was 1. Do the same and modify it to find out.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    oh, I see.
    now while it took you 2mins..give me 20hrs
    You ended that sentence with a preposition...Bastard!

  14. #14
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    Ok.. i managed to do it..the most inefficient way but it works..

    so if x > y output 0
    otherwise I should output the count?
    You ended that sentence with a preposition...Bastard!

  15. #15
    Registered User
    Join Date
    Jan 2011
    Posts
    3
    thank you for trying to solve this problem.. but can you pls tell me how you solved this?? because i don't have an idea how to solve this..

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. pls help with this tutorial problem
    By pelisa in forum C++ Programming
    Replies: 1
    Last Post: 04-19-2010, 12:47 PM
  2. minor problem in up down counter - pls help
    By bondage in forum C Programming
    Replies: 15
    Last Post: 01-15-2010, 01:42 AM
  3. Bin packing problem....
    By 81N4RY_DR460N in forum C++ Programming
    Replies: 0
    Last Post: 08-01-2005, 06:20 AM
  4. Spot the problem..a test question, pls help!
    By Unregistered in forum C++ Programming
    Replies: 10
    Last Post: 02-05-2002, 01:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21