首页 > 试题广场 >

计算机内存

[编程题]计算机内存
  • 热度指数:15923 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
\hspace{15pt}我们可以看到题目描述的上方有一个空间限制 256\,\mathrm{MB}。在计算机中,一个整数占据 4 字节的内存;
\hspace{23pt}\bullet\,1\,\mathrm{MB}=1024\,\mathrm{KB}
\hspace{23pt}\bullet\,1\,\mathrm{KB}=1024\,\mathrm{B}
\hspace{23pt}\bullet\,1\,\mathrm{B}=1 字节。
\hspace{15pt}那么,给定 n MB 的内存,请问可以存储多少个整数?

输入描述:
\hspace{15pt}在一行中输入一个整数 n1 \leqq n \leqq 256),表示内存大小(单位 MB)。


输出描述:
\hspace{15pt}输出一个整数,表示在 n MB 内存中最多可以存储的整数个数。
示例1

输入

1

输出

262144

说明

\hspace{15pt}1\,\mathrm{MB}=1024\times1024\,\mathrm{B}=2^{20}\,\mathrm{B},每个整数占用 4 字节,因此可存储 2^{20}/4=262144 个整数。
示例2

输入

256

输出

67108864

说明

\hspace{15pt}256\,\mathrm{MB}=256\times2^{20}\,\mathrm{B},每个整数占用 4 字节,因此可存储 256\times2^{20}/4=256\times2^{18}=67108864 个整数。

备注:
本题已于下方时间节点更新,请注意题解时效性:
1. 2025-06-03 优化题面文本与格式。
头像 张田懿
发表于 2020-12-12 12:57:41
include<bits/stdc++.h> using namespace std;int main(){ int n; cin>>n; cout<<n1024256; return 0;}
头像 天元之弈
发表于 2022-01-17 11:18:14
原题传送门->https://ac.nowcoder.com/acm/problem/22005 my blog->https://blog.nowcoder.net/yanhaoyang2106 题目描述 我们可以看到题目描述的上方有一个空间限制32M, 在计算机中一个整数占据4个字节 展开全文
头像 小嗷犬
发表于 2023-07-31 15:07:04
#include <bits/stdc++.h> using namespace std; // 我们可以看到题目描述的上方有一个空间限制 32M, 在计算机中一个整数占据 4 个字节的内存, // 1MB 等于 1024KB, 1KB 等于 1024B, 1B 就代表 1 字节, 展开全文
头像 叩神
发表于 2025-07-13 17:42:18
#include <stdio.h> int main() { int n = 0; scanf("%d", &n); printf("%d", n * 1024 *1024 / 4); 展开全文
头像 面向直男编程_重楼
发表于 2023-02-23 09:50:34
链接: https://ac.nowcoder.com/acm/problem/22005 来源:牛客网 题目描述 我们可以看到题目描述的上方有一个空间限制32M, 在计算机中一个整数占据4个字节的内存, 1MB等于1024KB, 1KB等于1024B, 1B就代表1字节, 那么请问n MB的内存可 展开全文
头像 i的小白
发表于 2025-07-04 10:07:25
#include <iostream> using namespace std; int main() { int MB; cin >> MB; int KB = MB * 1024; int B = KB * 1024; int 展开全文
头像 CARLJOSEPHLEE
发表于 2025-07-15 20:43:34
print(int(input())*2**18)
头像 努力的牛客
发表于 2019-12-10 20:08:40
include<bits/stdc++.h> using namespace std; int main(){ 这不就好了吗?那么麻烦干什么 int n,s; cin>>n; cout<<n10241024/4; return 0; 展开全文
头像 潍坊鲨鱼公园儿童大学
发表于 2021-01-23 13:48:00
#include <iostream> using namespace std; int main() { const int INT_SIZE = 4; // 一个整数占据4个字节 const int ONE_KB = 1024; // 1KB等于1024B 展开全文
头像 易烊千玺圈外女友
发表于 2021-05-14 20:21:01
小技巧,没有用题目给定的换算,直接用示例一的数据等比例进行换算 #include <stdio.h> #include <math.h> int main() { int a,b; scanf("%d",&a); b=a*262144; 展开全文