Untitled

mail@pastecode.io avatar
unknown
plain_text
7 months ago
673 B
2
Indexable
Never
class HashTable:
    def __init__(self):
        self.index = [None]*100

    def get_hash(self, key, i):
        h = key**3 - key**2 + key - 1
        g = (1+key) % 99
        res = (h + i*g) % 100
        return res

    def insert(self, key):
        i = 0
        hsh = self.get_hash(key, i)
        while self.index[hsh] is not None:
            i += 1
            hsh = self.get_hash(key, i)
        self.index[hsh] = key

if __name__ == "__main__":
    n = int(input())
    table = HashTable()
    for i in range(n):
        table.insert(int(input()))

    for i in range(len(table.index)):
        if table.index[i] is not None:
            print(i, table.index[i])
Leave a Comment