Interviewstreet 的示例测试用例:方程
于是就有了一个名为 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=2
、N=3
、N=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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我的解决方案被采访街接受了。
首先,我的解决方案没有被接受,但是在看到@Reinardus Surya Pradhit 的帖子后,我意识到,如果对 (x, y) 会被计算两次,所以我稍微改变了它并获得了成功
我不会在这里发布我的解决方案,但我可以告诉您 N = 3 -> 中所有变量的测试用例数 = 10
这是结果
我的提示是:尝试表达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
My hint is: try to express N! in primes from like
p1^q1 * p2^q2 * ... * pn^qn
暂时忽略
N!
的特殊形式,求解方程时写为
x = k + d
。然后确定解决方案数量的任务留给读者作为练习。
Disregarding the special form of
N!
for the moment, to solve the equationwrite
x = k + d
. ThenThe task of determining the number of solutions from that is left as an exercise for the reader.
重要的是只处理整数以避免舍入错误:首先将方程重新排列为:
我不确定从哪里开始。
It is important to only deal with integers to avoid rounding errors: start by rearranging the equation to:
I'm not sure where to go from there.
为了得到最终结果,我们需要计算 (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