コード例 #1
0
ファイル: projecteuler.py プロジェクト: ogun/ProjectEuler
def problem23():
    """ Non-abundant sums
    Find the sum of all the positive integers which cannot be written
    as the sum of two abundant numbers.

    """
    abundants = [x for x in range(1, 28124) if mathhelper.sum_factors(x, proper=True) > x]
    abundants_sum = {x + y for (x, y) in itertools.product(abundants, repeat=2) if x + y < 28124}
    return sum(x for x in range(1, 28124) if x not in abundants_sum)
コード例 #2
0
ファイル: test_mathhelper.py プロジェクト: ogun/ProjectEuler
 def test_sum_factors(self):
     self.assertEqual(mathhelper.sum_factors(-1), 1)
     self.assertEqual(mathhelper.sum_factors(0), 0)
     self.assertEqual(mathhelper.sum_factors(1), 1)
     self.assertEqual(mathhelper.sum_factors(2), 3)
     self.assertEqual(mathhelper.sum_factors(3), 4)
     self.assertEqual(mathhelper.sum_factors(4), 7)
     self.assertEqual(mathhelper.sum_factors(5), 6)
     self.assertEqual(mathhelper.sum_factors(6), 12)
     self.assertEqual(mathhelper.sum_factors(10), 18)
     self.assertEqual(mathhelper.sum_factors(12), 28)
     self.assertEqual(mathhelper.sum_factors(25), 31)
     self.assertEqual(mathhelper.sum_factors(-1, True), 0)
     self.assertEqual(mathhelper.sum_factors(0, True), 0)
     self.assertEqual(mathhelper.sum_factors(1, True), 0)
     self.assertEqual(mathhelper.sum_factors(2, True), 1)
     self.assertEqual(mathhelper.sum_factors(3, True), 1)
     self.assertEqual(mathhelper.sum_factors(4, True), 3)
     self.assertEqual(mathhelper.sum_factors(5, True), 1)
     self.assertEqual(mathhelper.sum_factors(6, True), 6)
     self.assertEqual(mathhelper.sum_factors(10, True), 8)
     self.assertEqual(mathhelper.sum_factors(12, True), 16)
     self.assertEqual(mathhelper.sum_factors(25, True), 6)