A message is cut into frames, and every frame carries 58 bytes of headers.
What to build
A program that says how many frames a message needs and how many bytes go on the wire.
Requirements
- A frame holds at most 1460 bytes of data.
- Every frame adds 58 bytes of headers (20 TCP, 20 IP, 18 Ethernet).
- Print the number of frames, then the total bytes on the wire.
Input
One whole number N: the message size in bytes.
Output
Two lines: frames F and bytes B.
Constraints
1 ≤ N ≤ 1000000.
Example
Input:
100
Output:
frames 1
bytes 158
Why it works
The frame count is N divided by 1460, rounded up. Each frame repeats the same 58 bytes of headers, so the wire carries N plus 58 times the frame count.
Examples
100
frames 1 bytes 158
3000
frames 3 bytes 3174
Prompts inside input() are ignored when checking, so input("n: ") is fine.
Hints
Hint 1
One frame holds at most 1460 bytes of data. Round the division up.
Hint 2
frames = (n + 1459) // 1460 rounds up without floats.
Hint 3
Every frame adds 58 bytes of headers: TCP 20, IP 20, Ethernet 18.
Solution
Show one correct solution (try it yourself first)
n = int(input())
frames = (n + 1459) // 1460
print("frames", frames)
print("bytes", n + 58 * frames)
▶ Open this solution in the compiler, then press Visualize to watch it run step by step