Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Given x,y, How to find whether x! is divisible by y or not?

computing x! can be very costly and might often result in overflow. Is there a way to find out whether x! is divisible by y or not without computing x!?

  • For y < x, its trivial;
  • But,for y > x, e.g. x = 5 and y = 60; I am struggling to find a way without computing x!
like image 816
Ritesh Mahato Avatar asked Dec 06 '22 02:12

Ritesh Mahato


1 Answers

Compute the prime factorization of x! and y. You can do this without computing x! by factorizing every number from 2 to x and collecting all of the factors together. If the factors of y is a subset of the factors of x! then it is divisible.

like image 77
IronMensan Avatar answered Jan 29 '23 13:01

IronMensan