Interviewstreet 的示例测试用例:方程

发布于 2024-12-22 21:10:10 字数 662 浏览 2 评论 0原文

于是就有了一个名为 Interviewstreet.com 的网站。在这里我们可以找到具有挑战性的编程问题。不幸的是,您必须登录才能查看问题。

以下是我试图解决的问题的简要描述:

求方程组的正积分解的个数(1/x) + (1/y) = 1/N!(读1乘n阶乘)打印一个整数,即以 1000007 为模的正积分解的数量。

例如,当 N=3 时,(x,y) 可以是:(7,42)(9,18)(8,24)(12,12)(42,7) >,<代码>(18,9),<代码>(24,8)。或者说我是这么想的。

请帮助我,特别是已经解决了这个问题的你。我刚刚为问题方程编写了代码。我的算法有问题,我可以要求输出前 10 个整数吗?即 N=2N=3N=4 ... N=10 这样我就可以找出我的算法中的缺陷。谢谢:)

编辑:哦,请不要发布解决方案代码,因为它会破坏我和试图解决这个问题的人的乐趣:)

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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

萌逼全场 2024-12-29 21:10:10

我的解决方案被采访街接受了。
首先,我的解决方案没有被接受,但是在看到@Reinardus Surya Pradhit 的帖子后,我意识到,如果对 (x, y) 会被计算两次,所以我稍微改变了它并获得了成功
我不会在这里发布我的解决方案,但我可以告诉您 N = 3 -> 中所有变量的测试用例数 = 10
这是结果

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

我的提示是:尝试表达N!素数如 p1^q1 * p2^q2 * ... * pn^qn

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

猫性小仙女 2024-12-29 21:10:10

暂时忽略 N! 的特殊形式,求解方程时

1/k = 1/x + 1/y

写为 x = k + d。然后

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

确定解决方案数量的任务留给读者作为练习。

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.

笛声青案梦长安 2024-12-29 21:10:10

重要的是只处理整数以避免舍入错误:首先将方程重新排列为:

N!(X+Y)=XY

我不确定从哪里开始。

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.

春庭雪 2024-12-29 21:10:10

为了得到最终结果,我们需要计算 (2*q1+1)*(2*q2+1)*(2*q3+1)...
但是我们将如何存储结果,假设 N=32327 将会溢出到结果之上。
如果我错了请纠正我

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文