Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. my homework-amicable numbers

my homework-amicable numbers

Scheduled Pinned Locked Moved C / C++ / MFC
c++csshelptutorial
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sugaragga
    wrote on last edited by
    #1

    Hi I have a homework about finding amicable numbers [[[[ Amicable numbers:Two numbers are called Amicable(or friendly)if each equals to the sum of the aliquot divisors of the other.Aliquot divisors mean all the divisors excluding the number itself. For example, aliquot divisors of number 220 are 1,2,4,5,10,11,20,22,44,55 and 110. The aliquot divisors of number 284 are 1,2,4,71 and 142. If we represent anamicable pair by(m,n)and sum of aliquot divisors of m and n by(m)and(n)respectively,then for amicable pair(220,284)we get (m)=(220)=1+2+4+5+10+11+20+22+44+55+110=284=n (n)=(284)=1+2+4+71+142=220=m ]]]] my teacher wanted this programs code in C++ without using any arrays(we are allowed to do this with if,while,for,do while).And also the program must be like this: 220 and 284 are amicable numbers. Number of amicable number less than 1000 is 1. 1184 and 1210 are amicable numbers. 2620 and 2924 are amicable numbers. 5020 and 5564 are amicable numbers. 6232 and 6368 are amicable numbers. Number of amicable number less than 10000 is 5. .... .... .... .... It must survive up to 10^10. Please help me,I will so appreciate...:((

    B D S 3 Replies Last reply
    0
    • S sugaragga

      Hi I have a homework about finding amicable numbers [[[[ Amicable numbers:Two numbers are called Amicable(or friendly)if each equals to the sum of the aliquot divisors of the other.Aliquot divisors mean all the divisors excluding the number itself. For example, aliquot divisors of number 220 are 1,2,4,5,10,11,20,22,44,55 and 110. The aliquot divisors of number 284 are 1,2,4,71 and 142. If we represent anamicable pair by(m,n)and sum of aliquot divisors of m and n by(m)and(n)respectively,then for amicable pair(220,284)we get (m)=(220)=1+2+4+5+10+11+20+22+44+55+110=284=n (n)=(284)=1+2+4+71+142=220=m ]]]] my teacher wanted this programs code in C++ without using any arrays(we are allowed to do this with if,while,for,do while).And also the program must be like this: 220 and 284 are amicable numbers. Number of amicable number less than 1000 is 1. 1184 and 1210 are amicable numbers. 2620 and 2924 are amicable numbers. 5020 and 5564 are amicable numbers. 6232 and 6368 are amicable numbers. Number of amicable number less than 10000 is 5. .... .... .... .... It must survive up to 10^10. Please help me,I will so appreciate...:((

      B Offline
      B Offline
      Bob Flynn
      wrote on last edited by
      #2

      I'll point you in the right direction to help you do it yourself. First off you clearly need a function to compute the aliquot divisor of a number. Second you need to decide how to find the pairs. (assume that you need to detect/avoid duplicates) I think a simple loop can handle this problem. You need to go through the thought process. You can get help for that here - maybe.

      S 1 Reply Last reply
      0
      • S sugaragga

        Hi I have a homework about finding amicable numbers [[[[ Amicable numbers:Two numbers are called Amicable(or friendly)if each equals to the sum of the aliquot divisors of the other.Aliquot divisors mean all the divisors excluding the number itself. For example, aliquot divisors of number 220 are 1,2,4,5,10,11,20,22,44,55 and 110. The aliquot divisors of number 284 are 1,2,4,71 and 142. If we represent anamicable pair by(m,n)and sum of aliquot divisors of m and n by(m)and(n)respectively,then for amicable pair(220,284)we get (m)=(220)=1+2+4+5+10+11+20+22+44+55+110=284=n (n)=(284)=1+2+4+71+142=220=m ]]]] my teacher wanted this programs code in C++ without using any arrays(we are allowed to do this with if,while,for,do while).And also the program must be like this: 220 and 284 are amicable numbers. Number of amicable number less than 1000 is 1. 1184 and 1210 are amicable numbers. 2620 and 2924 are amicable numbers. 5020 and 5564 are amicable numbers. 6232 and 6368 are amicable numbers. Number of amicable number less than 10000 is 5. .... .... .... .... It must survive up to 10^10. Please help me,I will so appreciate...:((

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        sugaragga wrote:

        Please help me...

        Exactly which part do you need help with? What code do you have in place so far? What doesn't work?


        "Approved Workmen Are Not Ashamed" - 2 Timothy 2:15

        "Judge not by the eye but by the heart." - Native American Proverb

        1 Reply Last reply
        0
        • B Bob Flynn

          I'll point you in the right direction to help you do it yourself. First off you clearly need a function to compute the aliquot divisor of a number. Second you need to decide how to find the pairs. (assume that you need to detect/avoid duplicates) I think a simple loop can handle this problem. You need to go through the thought process. You can get help for that here - maybe.

          S Offline
          S Offline
          sugaragga
          wrote on last edited by
          #4

          I cannot do it by myself.I found these codes in this site but it has an array like int get_sumf(int val).We are not allowed to do that.How can I do it without ant array??? #include #define MAX 10000000000 int get_sumf(int val) { int sum = 1; int k; for (k = 2; k <= val / 2; ++k) if (val % k == 0) sum += k; return sum; } int main() { int i, k; for (i = 2; i < MAX; ++i) { int val = get_sumf(i); for (k = 0; k < i; ++k) if (val == k && get_sumf(k) == i) printf("%d %d\n", i, k); } return 0; }

          1 Reply Last reply
          0
          • S sugaragga

            Hi I have a homework about finding amicable numbers [[[[ Amicable numbers:Two numbers are called Amicable(or friendly)if each equals to the sum of the aliquot divisors of the other.Aliquot divisors mean all the divisors excluding the number itself. For example, aliquot divisors of number 220 are 1,2,4,5,10,11,20,22,44,55 and 110. The aliquot divisors of number 284 are 1,2,4,71 and 142. If we represent anamicable pair by(m,n)and sum of aliquot divisors of m and n by(m)and(n)respectively,then for amicable pair(220,284)we get (m)=(220)=1+2+4+5+10+11+20+22+44+55+110=284=n (n)=(284)=1+2+4+71+142=220=m ]]]] my teacher wanted this programs code in C++ without using any arrays(we are allowed to do this with if,while,for,do while).And also the program must be like this: 220 and 284 are amicable numbers. Number of amicable number less than 1000 is 1. 1184 and 1210 are amicable numbers. 2620 and 2924 are amicable numbers. 5020 and 5564 are amicable numbers. 6232 and 6368 are amicable numbers. Number of amicable number less than 10000 is 5. .... .... .... .... It must survive up to 10^10. Please help me,I will so appreciate...:((

            S Offline
            S Offline
            sugaragga
            wrote on last edited by
            #5

            how can I insert these informations: "Number of amicable number less than 1000 is 1." "Number of amicable number less than 10000 is 5." like this: "220 and 284 are amicable numbers. Number of amicable number less than 1000 is 1. 1184 and 1210 are amicable numbers. 2620 and 2924 are amicable numbers. 5020 and 5564 are amicable numbers. 6232 and 6368 are amicable numbers. Number of amicable number less than 10000 is 5." . I can only write these numbers like: 220 284 1184 1210 2620 2924 5020 5564 6232 6368 .... .... Please help me:((

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups