Question: This is my first code in python and i completely can't get why the code in 5-th string must contain `math.sqrt(i))+1` instead of just `math.sqrt(i)`, because otherwise squares of prime numbers are added to the result.  

How to solve this is the easiest and most natural way? Thanks you all in advance

```
import math
n=int(input("Print n: "))
prime_list=list(range(2,n))
for i in range(2,n):
    for j in range (2, math.ceil(math.sqrt(i))+1):
        if i % j == 0:
            try:
                prime_list.remove(i)
            except:
                j+=1
        continue

print(prime_list)

```

Answer: 
No, HashMap does not provide this capability out-of-the-box.

However, you could use two different approaches to achieve the goal:

A) If the number of orders in each state does not need to be checked that often, simply iterate over `map.values()` and count the amount of orders in each state

B) If the number of orders is very large, or state needs to be checked often, each time you add a new order or update its state, increment a counter for the new state and decrement the counter for the old state.
Another option is to map each value to a number. Here's one way to do so using streams:

```
public static <K, V> Map<V, Long> foo(Map<K, V> map) {
    return map.entrySet().stream()
            .collect(Collectors.groupingBy(Map.Entry::getValue, Collectors.counting()));
}

```

You could then print out the results like so:

```
Map<String, String> map = ...;
foo(map).forEach((k, v) -> System.out.printf("%s %d%n", k, v));

```

---

You could also modify it to know *which* keys were mapped to the same value.

```
public static <K, V> Map<V, List<K>> foo(Map<K, V> map) {
    return map.entrySet().stream().collect(Collectors.groupingBy(
            Map.Entry::getValue,
            Collectors.mapping(Map.Entry::getKey, Collectors.toList())
    ));
}

```