SHARE
TWEET

Untitled

PlotnikovPhilipp Sep 22nd, 2019 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. """
  2.  
  3.    Сумма всех множителей числа n
  4.  
  5. """
  6. # Используем алгоритм, раскладывающий число n на простые множители
  7. def factors(number):
  8.     arrayOfSimpleNumbers = []
  9.     currentNumber = 2
  10.     while currentNumber**2 <= number:
  11.         while number % currentNumber == 0:
  12.             arrayOfSimpleNumbers.append(currentNumber)
  13.             number //= currentNumber
  14.         currentNumber += 1
  15.     if number > 1:
  16.         arrayOfSimpleNumbers.append(number)
  17.     return arrayOfSimpleNumbers
  18.  
  19. def sumOfPrimeFactors(number):
  20.     arrayOfPrimeFactors = factors(number)
  21.     arrayOfUsedNumber = []
  22.     result = 1
  23.     for i in arrayOfPrimeFactors:
  24.         for j in arrayOfUsedNumber:
  25.             if j == i: break
  26.         else:
  27.             result *= (i**(arrayOfPrimeFactors.count(i) + 1) - 1) // (i - 1)
  28.             arrayOfUsedNumber.append(i)
  29.     return result
  30. print(sumOfPrimeFactors(12)) # вводим любой положительное целое число
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top