Address lines and memory size

A processor with k address lines can reach 2ᵏ memory cells. Turn the number of lines into a count of addresses and a size.

What to build

A program that reads k and prints how many addresses k lines reach and the memory size when each address holds one byte.

Requirements

  • Print addresses N with N the exact number of addresses.
  • Print size V U where U is one of B, KB, MB, GB, TB or PB (each 1024 times the one before), chosen so that V is a whole number from 1 to 1023.

Input

One line: k.

Output

Two lines.

Constraints

1 ≤ k ≤ 59.

Example

Input:

10

Output:

addresses 1024
size 1 KB

Why it works

Every address line is one bit of the address, so each line doubles the count. Because 2¹⁰ = 1024, every ten lines move one unit up (B, KB, MB, and so on) and the leftover lines give the number 1, 2, 4, up to 512.

Examples

Example 1 · Input
10
Expected output
addresses 1024
size 1 KB
Example 2 · Input
32
Expected output
addresses 4294967296
size 4 GB

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

The number of addresses is 2 to the power k, written 2 ** k in Python.

Hint 2

Each 10 address lines multiply the size by 1024: use k // 10 to pick the unit and 2 ** (k % 10) for the number.

Solution

Show one correct solution (try it yourself first)
k = int(input())
units = ["B", "KB", "MB", "GB", "TB", "PB"]
print("addresses", 2 ** k)
print("size", 2 ** (k % 10), units[k // 10])

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Inside a computer: CPU, memory and buses →