Help us understand the problem. What is going on with this article?

# Project Euler 21 「友愛数」

More than 1 year has passed since last update.

## Problem 21 「友愛数」

d(n) を n の真の約数の和と定義する. (真の約数とは n 以外の約数のことである. )
もし, d(a) = b かつ d(b) = a (a ≠ b のとき) を満たすとき, a と b は友愛数(親和数)であるという.

また, 284 の約数は 1, 2, 4, 71, 142 なので d(284) = 220 である.
それでは10000未満の友愛数の和を求めよ.

```def hoge(num):
ans = 0
shinyakuwa = {}
for n in xrange(1, num):
shinyakuwa[n] = get_shinyakuwa(n)
for x, y in shinyakuwa.iteritems():
if  x != y \
and shinyakuwa.has_key(y) \
and x == shinyakuwa[y]:
ans += x
return ans

def get_shinyakuwa(n):
shinyaku = [1]
for m in xrange(2, (n/2)+1):
if n % m == 0:
shinyaku.append(m)
return sum(shinyaku)

print hoge(10000)
```

Why do not you register as a user and use Qiita more conveniently?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away