真正的大数字和 Objective-C

发布于 2024-07-25 09:55:30 字数 285 浏览 5 评论 0原文

我一直在研究一些 Project Euler 问题,自然会遇到很多需要处理的问题long long 类型的数字。 我致力于使用 Cocoa 和 Objective-C(我需要在工作中保持敏锐),但找不到一种优雅的方式(阅读:库)来处理这些非常大的数字。

我很想使用 GMP,但听起来与 Xcode 一起使用它是一个完全的伤害世界。

有谁知道还有其他选择吗?

I've been toying around with some Project Euler problems and naturally am running into a lot that require the handling of bigger than long long type numbers. I am committed to using Cocoa and Objective-C (I need to stay sharp for work) but can't find an elegant way (read: library) to handle these really big numbers.

I'd love to use GMP but is sounds like using it with Xcode is a complete world of hurt.

Does anyone know of any other options?

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

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

发布评论

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

评论(6

往日 2024-08-01 09:55:30

如果我是你,我会在 XCode 之外编译 gmp 并在 XCode 中仅使用 gmp.hlibgmp.a(或 libgmp.dylib)项目。

If I were you I would compile gmp outside XCode and use just gmp.h and libgmp.a (or libgmp.dylib) in my XCode project.

毁虫ゝ 2024-08-01 09:55:30

尝试将数字存储在数组中。

虽然你必须为所有算术问题编写一些新函数,但这就是我们在大学里被告知要做的事情。

另外,计算速度得到了很大提高,因为大数字毕竟并不是很大,而且也不是真正的数字,

它是否有帮助

看看

Try storing the digits in arrays.

Although you will have to write some new functions for all your arithmatic problems but thats how we were told to do it in college.

Plus the speed of calculations was pretty improved as big numbers weren't really big afterall and were not numbers really altogether

see if it helps

regards

灼疼热情 2024-08-01 09:55:30

vecLib 中的 vBigNum 实现 1024 位整数(有符号或无符号)。 那够大吗?

vBigNum in vecLib implements 1024 bit integers (signed or unsigned). Is that big enough?

堇年纸鸢 2024-08-01 09:55:30

如果您想使用 matlab (或任何接近的东西),您可以查看我对大整数形式的实现 (vpi) 关于文件交换。

这相当简单。 单独存储每个数字。 加法和减法很简单,只需实现一个进位运算即可。 乘法最好使用卷积,然后是进位来完成。 实施除法和取模运算符,然后实施幂取模运算,这对于许多 PE 问题很有用。 幂很简单——只需根据指数的二进制表示重复平方和乘法即可。

这会让你解决很多PE问题。

If you wanted to use matlab (or anything close) you could look at my implementation of a big integer form (vpi) on the file exchange.

It is rather simple. Store each digit separately. Adds and subtracts are simple, just implement a carry operation. Multiplies are best done using convolution, then a carry. Implement divide and mod operators, then a powermod operation, useful for many of the PE problems. Powers are easy - just repeated squaring and multiplication, based on the binary representation of the exponent.

This will let you solve many PE problems.

灯下孤影 2024-08-01 09:55:30

我也有一个好主意,用 Cocoa/Objective-C 尝试一些 Euler 项目问题,但发现它令人沮丧。 我以前使用过 Java,也许还使用过一些 PHP。 我在此帖子中发布了我的确切问题。

I too got the bright idea to attempt some Euler Project problems with Cocoa/Objective-C and have found it frustrating. I previously used Java and perhaps some PHP. I posted my exact problem in this thread.

生生漫 2024-08-01 09:55:30

我一直考虑在这个项目中使用库作弊。 只需编写一个包含您需要的内容的类即可。 并且不要害怕使用 malloc 和 uint64_t 等。 在很多情况下,NSNumber不是一个好主意。

另一方面,有许多问题,明显的解决方案需要巨大到巨大的数字,而诀窍是找到一种不使用这些巨大数字来解决问题的方法。 (例如,1,000,000 阶乘的最后千位数字之和是多少)?

I always considered using a library cheating for this project. Just write a class with the things you need. And don't be afraid to use malloc and uint64_t and so on. NSNumber is not a good idea in many cases.

On the other hand, there are many problems where the obvious solution would require huge to enormously huge numbers, and the trick is to find a way to solve the problem without using these huge numbers. (For example, what is the sum of the last thousand digits of 1,000,000 factorial)?

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