n! means n

    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.

     

    Answer:
    31626
    1. #!/usr/bin/env python
    2. import math
    3. def Findsum (num ):
    4.     sum= 1
    5.     for i in range ( 2, int ( math. sqrt (num ) +1 ) ):
    6.         if num%i== 0:
    7.             sum+=i
    8.             if i!=num/i:
    9.                 sum+=num/i
    10.     return sum
    11.  
    12. def JlFindsum ( ):
    13.     result= { }
    14.     for i in range ( 10000 ):
    15.         result [i ]=Findsum (i )
    16.     return result
    17.  
    18. def main ( ):
    19.     answer= 0
    20.     result=JlFindsum ( )
    21.     for i in range ( 1, 10000 ):
    22.             if result [i ]< 10000 and i!=result [i ] and i==result [result [i ] ]:
    23.                 answer+=i
    24.     print answer
    25.  
    26. if __name__== "__main__":
    27.     main ( )

     

    ( n − 1) × ... × 3 × 2 ×1

     

    Find the sum of the digits in the number 100!

     

    Answer:
    648

    备注:python真强大,一句话搞掂,以pythonic为荣

    代码:

     

    #!/usr/bin/env python
    print sum ( int (x ) for x in str ( reduce ( lambda x,y:x*y, range ( 1, 101 ) ) ) )