做x mod 1000000007的想法是什么? [英] What's the idea of doing x mod 1000000007?

查看:129
本文介绍了做x mod 1000000007的想法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在许多编程问题(例如某些Euler项目问题​​)中,我们要求将答案除以1,000,000,007后剩下的剩余值.

In many programming problems (e.g. some Project Euler problems) we are asked to report the answer as the remainder left after dividing the answer by 1,000,000,007.

为什么没有其他数字?

Why not any other number?

两年后,这就是我所知道的:数字是一个很大的素数,对这个问题的任何回答都太大了,以至于报告余数是有意义的(因为该数字可能太大,无法处理本机数据类型)

2 years later, here's what I know: the number is a big prime, and any answer to such a question is so large that it makes sense to report a remainder instead (as the number may be too large for a native datatype to handle).

推荐答案

让我扮演一个心灵感应者. 1000 ... 7是质数,而1000000007是适合32位整数的最大数.由于素数用于计算哈希值(由找到除以质数的余数),1000000007可以很好地计算32位哈希.

Let me play a telepathist. 1000...7 are prime numbers and 1000000007 is the biggest one that fits in 32-bit integer. Since prime numbers are used to calculate hash (by finding the remainder of the division by prime), 1000000007 is good for calculating 32-bit hash.

这篇关于做x mod 1000000007的想法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆