解方程。计数 (x,y)

发布于 2024-11-11 13:42:53 字数 233 浏览 2 评论 0 原文

我的数学有问题:

假设我们有一个函数:F(x,y) = P;我的问题是:计算该函数合适的 (x,y) 图的最有效方法是什么?这意味着我不需要坐标本身,但我需要它们的数量。 P 的范围为:[0 ; 10^14]。 “x”和“y”是整数。是使用暴力破解还是有一些高级技巧(数学/编程语言(C,C++))来足够快地解决这个问题?

更具体地说,该函数为:x*y - ((x+y)/2) + 1。

I'm having a trouble with my math:

Assume that we have a function: F(x,y) = P; And my question is: what would be the most efficient way of counting up suitable (x,y) plots for this function ? It means that I don't need the coordinates themself, but I need a number of them. P is in a range: [0 ; 10^14]. "x" and "y" are integers. Is it solved using bruteforce or there are some advanced tricks(math / programming language(C,C++)) to solve this fast enough ?

To be more concrete, the function is: x*y - ((x+y)/2) + 1.

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

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

发布评论

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

评论(2

偷得浮生 2024-11-18 13:42:53

x*y - ((x+y)/2) + 1 == P 相当于 (2x-1)(2y-1) == (4P-3)代码>.

因此,您基本上是在寻找 4P-3 的分解次数。如何在 C 或 C++ 中对数字进行因式分解可能是一个不同的问题,但每次因式分解都会产生原始方程的解。 [编辑:实际上有两个解决方案,因为如果 A*B == C 那么当然 (-A)*(-B) == C 也]。

就编程语言 C 和 C++ 而言,只需确保您使用的类型足够大以包含 4 * 10^14 即可。 int 不行,所以尝试一下 long long

x*y - ((x+y)/2) + 1 == P is equivalent to (2x-1)(2y-1) == (4P-3).

So, you're basically looking for the number of factorizations of 4P-3. How to factor a number in C or C++ is probably a different question, but each factorization yields a solution to the original equation. [Edit: in fact two solutions, since if A*B == C then of course (-A)*(-B) == C also].

As far as the programming languages C and C++ are concerned, just make sure you use a type that's big enough to contain 4 * 10^14. int won't do, so try long long.

扬花落满肩 2024-11-18 13:42:53

您有一个二参数函数,并且想要求解给定常量。

这是数学中一个相当大的领域,可能有数十种算法可以求解方程。许多人使用的一个关键思想是,如果您找到一个 F 的点,然后找到一个 F>P 的点,那么某处在这两点之间,F 必须等于 P。

求根(或零,当然可以通过取 F'=FP 转换为零)的最基本算法之一是 牛顿法。我建议您从这里开始,然后阅读更高级的算法。这是一个非常广阔的研究领域,祝您阅读愉快!

维基百科有一个寻根算法列表,您可以将其用作起点。

You have a two-parameter function and want to solve it for a given constant.

This is a pretty big field in mathematics, and there are probably dozens of algorithms of solving your equation. One key idea that many use is the fact that if you find a point where F<P and then a point F>P, then somewhere between these two points, F must equal P.

One of the most basic algorithms for finding a root (or zero, which you of course can convert to by taking F'=F-P) is Newton's method. I suggest you start with that and read your way up to more advanced algorithms. This is a farily large field of study, so happy reading!

Wikipedia has a list of root-finding algorithms that you can use as a starting place.

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