# Finding divisors of Factorials

I was solving uva 13279 - Divisors but I can’t find my bug. I am getting “wrong” or “runtime error”.

``````import math as mt

def called_af(myList):

result = 1
for x in myList:
result = result * x
return result

def divisors(number):
#i = 1
lis = list()
#lis.append(1)
#lis.append(number)
for i in range(1, number+1):
if (number%i == 0):
#if(i!=1 and i!=number):
lis.append(i)
#i = i + 1

return lis

def main():
LIMIT = 5000001
lis = list()
divisor = list()
test_case = int(input())
assert(test_case <= 101)
i = 1

while(i <= test_case):
number = int(input())
assert(number < LIMIT and 0 < number)
for j in range(1, number+1):
tmp = mt.factorial(j)
lis.append(tmp)
print(lis)
AF = called_af(lis)
print(AF)
divisor = divisors(AF)
print(divisor)
result = len(divisor)
result = result % 100000007
print(result)
i = i + 1

zero = int(input())
assert(zero == 0)

if __name__ == "__main__":
main()
``````

Here you go buddy. It was a pdf, so I’m sending you a ss. Was going through it myself😀

1 Like

Question plz ??

You can optimize your divisors function further .

1 Like

Is there any bug exists that you found??

Your code was wrong, you were taking test cases as input but you need to read the file until you get 0 as input. Here is your code:

``````import math as mt

def called_af(myList):

result = 1
for x in myList:
result = result * x
return result

def divisors(number):
#i = 1
lis = list()
#lis.append(1)
#lis.append(number)
for i in range(1, number+1):
if (number%i == 0):
#if(i!=1 and i!=number):
lis.append(i)
#i = i + 1

return lis

def main():
LIMIT = 5000001
lis = list()
divisor = list()
number = int(input())
while(number != 0):

assert(number < LIMIT and 0 < number)
for j in range(1, number+1):
tmp = mt.factorial(j)
lis.append(tmp)
print(lis)
AF = called_af(lis)
print(AF)
divisor = divisors(AF)
print(divisor)
result = len(divisor)
result = result % 100000007
print(result)
number = int(input())

if __name__ == "__main__":
main()
``````

But this would give TLE, study sieve algorithms and some number theory stuff before attempting this.
Do tell me if you want the code, I’ll write it.

1 Like

Thank you for fixing the problem…