问题描述
因此,有一个名为interviewstreet.com的网站。在这里我们可以找到具有挑战性的编程问题。很抱歉,您必须登录才能看到问题。
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:
当 N = 3
,(x,y)
可以是:(7,42)
,(9,18)
,(8,24)
,(12,12)
,(42,7)
,(18,9)
,(24,8)
。或者所以我想。
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.
帮助我,特别是你解决了这个问题。我刚刚编码的问题方程。我的算法有问题,我可以要求输出前10个整数吗?即 N = 2
, N = 3
, N = 4
... N = 10
,以便我可以找出我的算法的缺陷。感谢:)
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 :)
编辑:哦,请不要发布解决方案代码,因为它会破坏我的乐趣,试图解决这个问题的人)。
Oh, please don't post solution code as it will ruin the fun for me and for people trying to solve this :)
推荐答案
我的解决方案被采访街接受。
首先,我的解决方案不被接受,但看到@Reinardus Surya Pradhit后,我意识到,如果对(x,y)将被计数两次,所以我改变它一个垃圾位和成功
我不会在这里发布我的解决方案,但我可以告诉你测试用例所有变量从N = 3 - > N = 10
这里的结果
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 successI will not post my solution here, but i can tell you the test case for all variable from N = 3 -> N = 10Here 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
我的提示是:尝试表达N!从 p1 ^ q1 * p2 ^ q2 * ... * pn ^ qn
My hint is: try to express N! in primes from like p1^q1 * p2^q2 * ... * pn^qn
这篇关于Interviewstreet的示例测试用例:公式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!