-3

So there is a website named interviewstreet.com. Here we can find challenging programming problems. Unfortunately you have to be logged in to see the questions.

Here's a brief description of the problem I'm attempting to solve:

Find the no of positive integral solutions for the equations (1/x) + (1/y) = 1/N! (read 1 by n factorial) Print a single integer which is the no of positive integral solutions modulo 1000007.

For example, when N=3, (x,y) can be: (7,42), (9,18), (8,24), (12,12), (42,7), (18,9), (24,8). Or so I thought.

Help me please, especially you who have solved this problem. I have just coded for the problem Equations. There is something wrong with my algorithm, can I ask for output for the first 10 integers? i.e. N=2, N=3, N=4 ... N=10 so that I can find out the flaw in my algorithm. Thanks :)

EDIT: Oh, please don't post solution code as it will ruin the fun for me and for people trying to solve this :)

vgru
  • 49,838
  • 16
  • 120
  • 201
  • If you've already coded up a solution, please post the code. – Timo Geusch Dec 28 '11 at 01:08
  • 2
    I'm sorry, I don't think it will be nice to post solutions. I just need the output of those testcases I put, for me to evaluate my algorithm – Reinardus Surya Pradhitya Dec 28 '11 at 04:25
  • To clarify, I asked that *you* post your solution if you want us to check over your algorithm. I wasn't suggesting that someone here post a solution to solve the problem for you. – Timo Geusch Dec 28 '11 at 04:52
  • 1
    But then I will spoil it for others. Actually I was asking for "what your program outputs when given the above inputs", not for my code to be checked. Nevermind, I have solved it finally. Thanks for your help :) In case anyone stumbled upon this problem, here is the output of sample testcases I asked for: N=1, ans=1; N=2, ans=3; N=3, ans=9; N=4, ans=21; N=5, ans=63; N=6, ans=135; N=7, ans=405; N=8, ans=675; N=9, ans=1215; N=10, ans=2295; – Reinardus Surya Pradhitya Dec 28 '11 at 06:12
  • You missed (10,15) and (15,10). – n. m. could be an AI Dec 28 '11 at 07:14
  • I got my code figuring out the answers for small N but it isn't ideal for large values of N. Any hints on how to solve for large values of N (the second test case is 32327 which gets too large for a Java long when figuring it's factorial value). I can use a BigInteger but I don't think that's the correct approach. Just a quick please, no solution. – Justin Feb 25 '12 at 14:56

4 Answers4

3

My solutions was accepted by interview street. Firstly, my solutions wasn't accepted, but after saw @Reinardus Surya Pradhit post, i realized, if pair (x, y) will be count twice, so i change it a litter bit and got success I will not post my solution here, but i can tell you the test case for all variable from N = 3 -> N = 10 Here the result

N=3: 9
N=4: 21
N=5: 63 
N=6: 135
N=7: 405
N=8: 675
N=9: 1215
N=10: 2295

My hint is: try to express N! in primes from like p1^q1 * p2^q2 * ... * pn^qn

kiennt
  • 1,514
  • 2
  • 14
  • 13
2

Disregarding the special form of N! for the moment, to solve the equation

1/k = 1/x + 1/y

write x = k + d. Then

1/y = 1/k - 1/(k + d) = d/(k*(k+d))

The task of determining the number of solutions from that is left as an exercise for the reader.

Daniel Fischer
  • 181,706
  • 17
  • 308
  • 431
0

to arrive at final result we need to calculate (2*q1+1)*(2*q2+1)*(2*q3+1)... But how we will store the result , let say N=32327 which will overflow above result. Please correct me if I'm wrong

shashank
  • 61
  • 1
  • 5
0

It is important to only deal with integers to avoid rounding errors: start by rearranging the equation to:

N!(X+Y)=XY

I'm not sure where to go from there.