Problem 021

A place to air possible concerns or difficulties in understanding ProjectEuler problems. This forum is not meant to publish solutions. This forum is NOT meant to discuss solution methods or giving hints how a problem can be solved.
Forum rules
As your posts will be visible to the general public you are requested to be thoughtful in not posting anything that might explicitly give away how to solve a particular problem.

This forum is NOT meant to discuss solution methods for a problem.

In particular don't post any code fragments or results.

Don't start begging others to give partial answers to problems

Don't ask for hints how to solve a problem

Don't start a new topic for a problem if there already exists one


See also the topics:
Don't post any spoilers
Comments, questions and clarifications about PE problems.
Post Reply
bfeist
Posts: 1
Joined: Fri Feb 01, 2008 7:53 pm

Problem 021

Post by bfeist »

For the purposes tof this problem, is a number considered amicable if its partner is not in the 1-9999 range? (I assume so, but I want to be sure before I put in more effort!)

Thanks,
Bruce Feist
User avatar
ed_r
Posts: 1009
Joined: Sun Jul 29, 2007 10:57 am

Re: Problem 21: Must both entries in an amicable pair be < 10000

Post by ed_r »

Yes, it is: you assumed correctly.
!647 = &8FDF4C
dbdweeb
Posts: 1
Joined: Fri Feb 22, 2008 2:14 am

Problem 21

Post by dbdweeb »

The problem explanation needs to be clarified. Quoting: "...a and b are an amicable pair and each of a and b are called amicable numbers." :shock:

I believe it should say, "and each DIVISOR of a and b are called amicable numbers."

Also, the problem calls for the sum of the amicable numbers but does not specify that repeated numbers should be counted. A prior problem indicated that a unique set should be used but this problems allows for duplicates. "Consistency is the hobgoblin of simple minds" so simplify! :?
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 21

Post by daniel.is.fischer »

No, the divisors are not amicable numbers. a is an amicable number if d(a) [ne] a and d(d(a)) = a. Then (a,d(a)) is an amicable pair. And each amicable number is to be included only once in the sum.
Il faut respecter la montagne -- c'est pourquoi les gypa&egrave;tes sont l&agrave;.
tOmcOlins
Posts: 7
Joined: Sun Apr 27, 2008 11:25 pm

Problem 21 clarification

Post by tOmcOlins »

If there is an amicable pair where one of the numbers is less than 10000 and the other is greater than 10000, is the number less than 10000 still to be counted?
User avatar
daniel.is.fischer
Posts: 2400
Joined: Sun Sep 02, 2007 11:15 pm
Location: Bremen, Germany

Re: Problem 21 clarification

Post by daniel.is.fischer »

Yes, it is an amicable number according to the definition, so it has to be counted.
Il faut respecter la montagne -- c'est pourquoi les gypa&egrave;tes sont l&agrave;.
tOmcOlins
Posts: 7
Joined: Sun Apr 27, 2008 11:25 pm

Re: Problem 21 clarification

Post by tOmcOlins »

Thank you, Daniel.
tOmcOlins
Posts: 7
Joined: Sun Apr 27, 2008 11:25 pm

Re: Problem 21 clarification

Post by tOmcOlins »

Although the problem defines an amicable pair as satisfying d(a) = b and d(b) = a, where a ≠ b,
I think it should be reiterated that pairs such as 6,6 and 28,28 are not to be counted. Reading the problem comments, it seems many people had frustration with this.
shadowboy
Posts: 4
Joined: Mon Sep 01, 2008 9:59 am

Problem 21

Post by shadowboy »

For the amicable pairs problem...

Do I consider perfect numbers as an amicable number (since it can be considered to be paired with itself)?
User avatar
jaap
Posts: 588
Joined: Tue Mar 25, 2008 3:57 pm
Contact:

Re: Problem #21, quick question?

Post by jaap »

No, it says a not equal to b in the problem statement.
shadowboy
Posts: 4
Joined: Mon Sep 01, 2008 9:59 am

Re: Problem #21, quick question?

Post by shadowboy »

Yeah, I just saw that. Guess I overlooked that.

Found out the real problem with my code. I made an incorrect assumption in a check. Changed one line of code and it worked.

I knew something was wrong when I was getting 12 and 56 as perfect numbers, too.

My code also reported d(10) = 5, which clued me in that something was definitely wrong.
Last edited by shadowboy on Mon Sep 01, 2008 10:35 am, edited 1 time in total.
User avatar
jaap
Posts: 588
Joined: Tue Mar 25, 2008 3:57 pm
Contact:

Re: Problem #21, quick question?

Post by jaap »

shadowboy wrote:Yeah, I just saw that. Guess I overlooked that.
That happened to me often enough too. If your program doesn't work, but you can't see what's wrong, it often pays to read the problem statement a couple of times to see if it really matches what your program is doing. If something in the problem isn't clear, it can usually be resolved or deduced after rereading a few times.

On the other hand, it doesn't always help of course. You wouldn't believe how often I read #89 (considered to be one of the easier ones), and how often I rewrote the core of my program, and how often I got the same wrong answer. In the end it was a dumb error in my bookkeeping code that caused everything to be double-counted.
shadowboy
Posts: 4
Joined: Mon Sep 01, 2008 9:59 am

Re: Problem #21, quick question?

Post by shadowboy »

That's why I have lots of debug output and look for anything that's wrong.

I knew something was wrong when I was getting:

d(10) = 5

and d(12) = 12.

What I did was in my sum divisors routine, I set the max value of the loop to floor[sqrt(num)], then if num%i == 0, I added i, and num/i to the acuumulator. The loop stopped at one less than floor[sqrt(num)]

After the loop I checked if [(num%sqrt(num)]==0, and if it did, I added sqrt(num).

Well, it didn't work for 12 because floor[sqrt(12)] is 3. Because I didn't include the num/sqrt(num), the 3 got counted, but not the 4. My assumption was that sqrt(num) only got counted once, but I momentarily forgot that we are dealing with integers here. As soon as I did a check for 'perfect square', the case of 12 included the 4 and I got all the right numbers. My answer was then correct (at this point I was omitting perfect numbers).
msc920
Posts: 3
Joined: Fri Jan 06, 2012 1:04 pm

About problem 21

Post by msc920 »

Hi everyone,
My struggle is about problem 21!
The problem appears as:
Let d(n) be defined as the sum of proper divisors of n (numbers less than n which divide evenly into n).
If d(a) = b and d(b) = a, where a ≠ b, then a and b are an amicable pair and each of a and b are called amicable numbers.

For example, the proper divisors of 220 are 1, 2, 4, 5, 10, 11, 20, 22, 44, 55 and 110; therefore d(220) = 284. The proper divisors of 284 are 1, 2, 4, 71 and 142; so d(284) = 220.

Evaluate the sum of all the amicable numbers under 10000.

But in the example above 4 does not evenly divide 220 because the result is 220/4=55 (odd)
AnywaY, I searched for the solution in both ways.
proper divisors or not. But I got no solution.
thundre
Posts: 356
Joined: Sun Mar 27, 2011 10:01 am

Re: About problem 21

Post by thundre »

Questions about the problems are supposed to go in the "ProjectEuler Problems" forum. There's actually a thread for 021 already at viewtopic.php?f=50&t=1078
msc920 wrote:But in the example above 4 does not evenly divide 220 because the result is 220/4=55 (odd).
The phrase "divide evenly" means that the result is an integer with no remainder. Odd integers are OK, fractions are not.
Image
msc920
Posts: 3
Joined: Fri Jan 06, 2012 1:04 pm

Re: Problem 021

Post by msc920 »

Someone has said each number has to be summed once. Yes, but I have already evaluated each amicable number only once. However it is clear from the example. Evenly division is not a must because 4 oddly divides 220 or 44 oddly divides it.
shriram.goal
Posts: 1
Joined: Mon Feb 06, 2012 10:40 am

Re: Problem 021

Post by shriram.goal »

Often, the word evenly divisible is confused. The word even in this context means 'equal'(as it is interpreted in the phrase 'even Steven'). Don't misinterpret it as the mathematical term 'even'(as it is interpreted in the phrase 'even number').
Kozimierz
Posts: 1
Joined: Mon Aug 12, 2013 2:18 pm

Re: Problem 021

Post by Kozimierz »

Looks like I have problem with this one. I should be getting 14 amicable numbers?

EDIT

nevermind, missed this important rule: d(a) = b and d(b) = a, where a =/= b

Now worked good.
Post Reply