tag:blogger.com,1999:blog-4115025577315673827.post8152582735196300214..comments2019-10-21T14:10:54.375+05:30Comments on CSE Blog - quant, math, computer science puzzles: Equations PuzzleUnknownnoreply@blogger.comBlogger9125tag:blogger.com,1999:blog-4115025577315673827.post-49168528032189916092014-06-24T03:53:27.366+05:302014-06-24T03:53:27.366+05:30Thanks a ton. Nice solutionThanks a ton. Nice solutionPratik Poddarhttps://www.blogger.com/profile/11577606981573330954noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-90503052803695327152014-06-24T03:50:22.803+05:302014-06-24T03:50:22.803+05:30Also, -1 is also not needed, as the trivial soluti...Also, -1 is also not needed, as the trivial solution is also acceptable here. ThanksPratik Poddarhttps://www.blogger.com/profile/11577606981573330954noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-25380208268431882192014-06-24T03:48:49.089+05:302014-06-24T03:48:49.089+05:30You do not need to divide by 2. There is no double...You do not need to divide by 2. There is no double counting here as (1,2) is different from (2,1) when (x,y) is the solution to an equation. ThanksPratik Poddarhttps://www.blogger.com/profile/11577606981573330954noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-5606417071462446532014-06-24T03:40:34.280+05:302014-06-24T03:40:34.280+05:30And so, answer will be a function of N.And so, answer will be a function of N.Pratik Poddarhttps://www.blogger.com/profile/11577606981573330954noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-77704965432031823552013-06-09T12:52:56.058+05:302013-06-09T12:52:56.058+05:30Solving for a fixed N.
1/a = 1/(a+k) + k/a(a+k).....Solving for a fixed N.<br /><br />1/a = 1/(a+k) + k/a(a+k)...........(1)<br /><br />If a(a+k)/k is an integer, we have a solution for 1/a = 1/a+k + 1/b, where b = a(a+k)/k<br /><br />Therefore in this case, we are looking for all k such that N!(N!+k)/k is an integer.<br /><br />Basically this means k divides N!^2<br /><br />So we need the number of divisors of N!^2.<br /><br />One way of calculating the power of p in the decompsoition of N! is the famous expression<br />a(p) = sum over j((n/p) + n/p^2)....+ (n/p^j)+....)<br />Based on this, we know a(p) for all the primes, and therefore the number of divisors is <br />(product over all primes(2a(p)+1) - 1)/2 <br />(Divide by 2 to account for double counting)Gautamhttps://www.blogger.com/profile/07248556360293734740noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-58145197473743618972013-05-08T07:13:35.335+05:302013-05-08T07:13:35.335+05:30This comment has been removed by the author.Vivek Ranjan Nemahttps://www.blogger.com/profile/04863121359660229833noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-45844916131895793252013-05-07T19:03:53.829+05:302013-05-07T19:03:53.829+05:30That's fair Vivek, but I believe the conventio...That's fair Vivek, but I believe the convention with this type of question is that capital-letter N is an arbitrary input for an algorithm, and not a variable of the problem in the same sense as x and y.JDGMhttps://www.blogger.com/profile/11829357060109505064noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-42001656775287651302013-05-06T11:37:59.719+05:302013-05-06T11:37:59.719+05:30I do not know ... it is infinite? Because if
x = ...I do not know ... it is infinite? Because if <br />x = 2 * N! and <br />y = 2 * N!<br /><br />Then for any N greater than 2 it will be an equality. <br />As many N, those many solutions.<br />So infiniteVivek Ranjan Nemahttps://www.blogger.com/profile/04863121359660229833noreply@blogger.comtag:blogger.com,1999:blog-4115025577315673827.post-27839975468829644032013-05-05T14:39:58.518+05:302013-05-05T14:39:58.518+05:30N, x, y > 0 so we may multiply both sides by N!...N, x, y > 0 so we may multiply both sides by N!xy:<br /><br />N!y + N!x = xy<br /><br />fiddle about with it:<br /><br />0 = xy - N!x - N!y = (x-N!)(y-N!) - N!N!<br /><br />(x-N!)(y-N!) = N!N!<br /><br />Both factors on the left are positive as x, y > 0 and hence x, y > N! otherwise the product would be non-positive or too small.<br /><br />The problem is now how many distinct ways the factors of N!N! may be shared between (x-N!) and (y-N!). We may consider just the possible factors in (x-N!) because whatever is left over will be in (y-N!).<br /><br />Decompose N! into prime powers p₁ᵅ¹p₂ᵅ²...pᵢᵅⁱ then we may have between zero and the full 2α₁ of N!N!'s p₁ powers in the (x-N!) factor and the rest in the (y-N!) factor.<br /><br />And so on, for p₂, p₃, ..., pᵢ. <br /><br />The number of solutions is therefore (2α₁+1)(2α₂+1)...(2αᵢ+1) because for each power p we have 2α+1 choices available to us as to how it shall be split between (x-N!) and (y-N!).<br /><br />It is straightforward to write an algorithm to find the α values of N!'s prime factorisation for given N, and hence calculate the answer using the preceding formula.<br /><br />For the second part, are we to similarly take arbitrary N, or is the solution to be taken across all values of x, y, N in Z₁₀₀₀₀₀₇? There can only be at most a finite 1000007³ such combinations of x, y, N so the solution in the latter case <i>would</i> be defined.<br /><br />Anyway, choose arbitrary M = 1/N! mod 1000007 and we require the number of solutions to 1/x + 1/y = M mod 1000007.<br /><br />My algorithm here is to tally ab=1 mod 1000007 for 0<a≤b<1000007 then build an array of that size and fill it with the a values for which ab=1 mod 1000007 through all compliant b. These are the possible 1/x and 1/y values - crucially note that 1/x or 1/y is not necessarily defined for all x, y in Z₁₀₀₀₀₀₇ which is why this step is necessary. The algorithm has effectively calculated just over half of the Z₁₀₀₀₀₀₇ multiplication table (includes diagonal) and stored the inverses where they exist, by picking out the corresponding factor where the entry in a row is 1. The next step of my algorithm is to go through this array, looking for values also in the array which add to the current value to make M mod 1000007. For each it finds, it adds 2 to the total number of solutions (because there is also a solution in the table on the other side of the diagonal - the table is symmetric), except in the case where the value lies on the diagonal when it adds only 1 to the total number of solutions (1000007 is odd, so the diagonal is its own reflection).<br /><br />If the question requires the number of all solutions over all x, y, N then we may repeat for all 0 < 1/N! < 1000007 and sum them. If not, and there is a single solution for all N then one calculation will suffice, though one may wish to calculate them all anyway to prove that they are the same.<br /><br />I believe Interview Street does not wish its answers publicly published so let's leave it there.JDGMhttps://www.blogger.com/profile/11829357060109505064noreply@blogger.com