import math
import sys

#command no_keys alpha total_keys filename
keys = int(sys.argv[1])
alpha = float(sys.argv[2])
totalKeys = int(sys.argv[3])
keyFile = "keys_G" + sys.argv[4] + ".txt"
queryFile = "queries_sort_G" + sys.argv[4] + ".txt"

denom = 0.0
for i in range(keys):
    denom = denom + 1/pow(i + 1, alpha)

print str(int(math.ceil(((1/pow((1), alpha))/denom) * totalKeys)))

fKey = open(keyFile, "r")
fQuery = open(queryFile, "w")

bitLen = 40
total = 0
count = 0
#Extract keys
for line in fKey:	
    num = int(math.ceil(((1/pow(count + 1, alpha))/denom) * totalKeys))
    total = total + num
    fQuery.write(line[:40] + '\t' + str(num) + '\n')
    count = count + 1
fKey.close()
fQuery.close()
print total
