Back
Close

Networking Basics: maximum addresses

Statement

 Goal

You need to calculate how many hosts are possible to be in a IPv4 network.

In a network (e.g.: 192.168.0.0/24) you can use all address except the first (192.168.0.0 -> network address) and last (192.168.0.255 -> broadcast address). So there are 254 addresses left to address a host (192.168.0.1 - 192.168.0.254).

In a network with a subnetmask of X are Y addresses possible.

X |Y
1 |2147483648
...
24 |256
25 |128
...
30 |4

How to?:
You must take the second part of the IPv4 Address, (92.168.0.0/24) and you must first find the absolute difference between it and 32, then you must compute 2 to the power of the number and then, subtract two from the result
Input
First line: N (number of inputs following)
N lines: IP-Address with subnetmask
Output
N lines: maximum number of hosts for each network
Constraints
N > 0
Example
Input
1
192.168.0.0/24
Output
254

Game modes
Fastest, Shortest

Test cases
Tutorial Test
Input
1 192.168.0.0/24
Output
254

Validator 1 Validator
Input
1 192.168.0.0/25
Output
126

Test 2 Test
Input
1 192.168.1.128/26
Output
62

Validator 2 Validator
Input
1 192.168.1.64/27
Output
30

Test 3 Test
Input
3 172.16.0.0/16 192.168.0.0/23 192.168.100.52/30
Output
65534 510 2

Validator 3 Validator
Input
2 172.16.0.0/18 192.168.10.16/29
Output
16382 6

Big network Test
Input
1 0.0.0.0/1
Output
2147483646

Validator 6 Validator
Input
1 128.0.0.0/2
Output
1073741822

Solution language

Solution

Stub generator input