I guess the problem would be to find the function.
Below is a program that encodes a number using power tables.
For some data value, you will find that in order to represent it, you would need more storage than its original form.
class CompressionTable:
values = {}
def __init__(self):
for b in xrange(2, 9):
CompressionTable.values[b] = [ b, b**2, b**3, b**4, b**5, b**6, b**7, b**8 ]
def to_func(x):
v = x
while v > 1:
lc = 0
lb = 0
ld = v
part_found = False
for b in xrange(2, 9):
for c in xrange(8):
d = v - CompressionTable.values[b][c]
if abs(d) < abs(ld):
lb = b
lc = c
ld = d
print "%d^%d -> %d" % (lb, lc+1, ld)
v = abs(ld)
print "final value of v = %d" % v
to_func = staticmethod(to_func)
t = CompressionTable()
while True:
v = long(raw_input())
if v == 0:
break
t.to_func(v)
print "-End-"
257
2^8 -> 1
final value of v = 1
258
2^8 -> 2
2^1 -> 0
final value of v = 0
9999
6^5 -> 2223
3^7 -> 36
6^2 -> 0
final value of v = 0
16384
4^7 -> 0
final value of v = 0
987654
7^7 -> 164111
7^6 -> 46462
6^6 -> -194
6^3 -> -22
5^2 -> -3
3^1 -> 0
final value of v = 0
9876543
7^8 -> 4111742
7^8 -> -1653059
6^8 -> -26557
8^5 -> -6211
3^8 -> -350
7^3 -> 7
7^1 -> 0
final value of v = 0
16777216
8^8 -> 0
final value of v = 0
16777219
8^8 -> 3
3^1 -> 0
final value of v = 0
1677719
6^8 -> -1897
3^7 -> -290
2^8 -> 34
2^5 -> 2
2^1 -> 0
final value of v = 0