多少存储为1总和至4十亿 [英] How much storage for summation of 1 to 4 billion

查看:187
本文介绍了多少存储为1总和至4十亿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题的启发(查找不搬过十亿给那些整数)。

需要多少存储空间,需要存储一个整数,这是数字的总和,1至4十亿?

How much storage space would it require to store an integer that was the summation of the numbers 1 to 4 billion?

例如,1 + 2 + 3 + 4 + 5 = 15求和的1至100万= 500000500000。

For example, 1+2+3+4+5 = 15. Summation of 1 to 1 million = 500,000,500,000.

这里是一种算法,可以帮助

Here is an algorithm that may help

推荐答案

您链接到介绍如何找到第n个三角形的数量时,其被定义为所述n个自然数的从1到n的总和。

The function you link to describe how to find the n'th Triangular Number, which is defined as the sum of the n natural numbers from 1 to n.

用4-十亿为n到函数给出8000000002000000000。

Substituting 4 billion as n into the function gives 8000000002000000000.

实施例pressing,作为一个比特数可以通过取的值的基数为2的对数,并舍入被加工出来 -

Expressing that as a number of bits can be worked out by taking the base-2 logarithm of the value and rounding up -

CEIL(日志(8000000002000000000)/日志(2))= 63

ceil(log(8000000002000000000)/log(2)) = 63

所以,存储的63比特是必需的。

So, 63 bits of storage are required.

这篇关于多少存储为1总和至4十亿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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