Program to find out the sum of the number of divisor of the divisors in Python


Suppose we are given two integer numbers m and a. Now n = p1(a + 1) *p2(a + 2) *...*pm(a + m), where pi is the i-th prime number and i > 0. We have to find the value of k, where k = summation of f(x) values of n. Here f(x) values are the number of divisor values of each divisor of n.

So, if the input is like m = 2, a = 1, then the output will be 60.

  • So, n = 2^2 x 3^3
  • n = 4 x 27
  • n = 108

The divisors of 108 are: 1, 2, 3, 4, 6, 9, 12, 18, 27, 36, 54, 108

f(x) value of each divisor are: f(1) + f(2) + f(3) + f(4) + f(6) + f(9) + f(12) + f(18) + f(27) + f(36) + f(54) + f(108)

= 1 + 2 + 2 + 4 + 4 + 3 + 5 + 6 + 4 + 9 + 8 + 12

= 60.

To solve this, we will follow these steps −

  • MOD := 10^9 + 7
  • Define a function summ() . This will take n
    • return floor value of ((n * (n + 1)) / 2)
  • Define a function division() . This will take a, b, mod
    • if a mod b is same as 0, then
      • return floor value of a / b
    • a := a + mod * division((-a modulo b), (mod modulo b), b)
    • return floor value of (a / b) modulo mod
  • mat := a new list containing a value 1
  • while size of mat <= m + a, do
    • insert (last element of mat * summ(len(mat)+1)) mod MOD at the end of mat
  • return division(mat[m + a], mat[a], MOD)

Example

Let us see the following implementation to get better understanding −

MOD = 10**9 + 7
def summ(n):
   return ((n) * (n + 1)) // 2

def division(a, b, mod):
   if a % b == 0:
      return a // b
   a += mod * division((-a) % b, mod % b, b)
   return (a // b) % mod

def solve(m, a):
   mat = [1]
   while len(mat) <= m + a:
      mat.append((mat[-1] * summ(len(mat)+1)) % MOD)
   return division(mat[m + a] , mat[a], MOD)

print(solve(2, 1))

Input

2, 1

Output

60

Updated on: 20-Oct-2021

143 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements