Problem:


塵劫記

大きな数を表そうとすると、文字数も多くなるし、位取りがわからなくなってしまうので、なかなか面倒です。大きな数をわかりやすく表すために、人々は数の単位を使ってきました。江戸時代に書かれた「塵劫記」という本の中では、数の単位が次のように書かれています。

たとえば、２の１００乗のようなとても大きな数は、１２６穣７６５０(じょ)６００２垓２８２２京９４０１兆４９６７億３２０万５３７６と表せます。それでは、正の整数 m と n が与えられたとき、m の n 乗を塵劫記の単位を使って上のように表すプログラムを作成してください。

入力

入力は複数のデータセットからなる。入力の終わりはゼロ２つの行で示される。各データセットは以下の形式で与えられる。

m n

m (2 ≤ m ≤ 20) が基数、n (1 ≤ n < 240) が指数を表す。ただし、mnは 1072 未満である。

データセットの数は 100 を超えない。

出力

データセットごとに、mn を塵劫記の単位で表した文字列を1行に出力する。ただし、各単位は以下の表記で出力する。

mnを表す文字列は、1 から 9999 までの数と上の表に現れる単位を表す文字列からなる。文字列には、余分な 0 や単位を含めない。

入出力例

入力例

2 10
5 20
10 8
20 17
0 0

出力例

1024
95Cho3674Oku3164Man625
1Oku
131Gai720Kei



Sample input:
2 10
5 20
10 8
20 17
0 0


Sample output:
1024
95Cho3674Oku3164Man625
1Oku
131Gai720Kei

Submission status: Wrong Answer

Solution code:
s = ("","Man","Oku","Cho","Kei","Gai","Jo",
	"Jou","Ko","Kan","Sei","Sai","Gok","Ggs",
	"Asg","Nyt","Fks","Mts")

while True:
	m,n = map(int,input().split())
	if m == 0 and n == 0:
		break
	ans = ""
	for i in range(0,len(str(m**n)),4):
		x = m**n//(10**i)%10000#m^n / 10^i
		ans = str(x) + s[i//4] + ans
	print(ans)

Submission status: Wrong Answer

Solution code:
Tani = ["","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"]
while True:
    m,n = map(int,input().split())
    Kazu =[]
    i = 0
    ans = ""
    if m == 0 and n == 0:
        break
    num = m ** n
    while num >= 1:
        if num % 10000 != 0:
            Kazu.append(str(num % 10000) + Tani[i])
        num = int(num / 10000)
        i += 1
    
    for j in range(len(Kazu)):
        ans = Kazu[j] + ans
    print(ans)

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"



def main():
    num = [10 ** 4, 10 ** 8, 10 ** 12, 10 ** 16, 10 ** 20, 10 ** 24, 10 ** 28, 10 ** 32, 10 ** 36, 10 ** 40, 10 ** 44, 10 ** 48, 10 ** 52, 10 ** 56, 10 ** 60, 10 ** 64, 10 ** 68]
    uni = ["Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Gas", "Asg", "Nyt", "Fks", "Mts"]

    print(len(num), len(uni))
    while True:
        m, n = map(int, input().split())
        print(m, n)
        if m == 0 and n == 0:
            break

        a = m ** n
        ans = ""
        for i in range(len(num) - 1, -1, -1):
            if a >= num[i]:
                ans += str(a // num[i]) + uni[i]
                a %= num[i]

        print(ans + str(a if a != 0 else ""))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"



def main():
    num = [10 ** 4, 10 ** 8, 10 ** 12, 10 ** 16, 10 ** 20, 10 ** 24, 10 ** 28, 10 ** 32, 10 ** 36, 10 ** 40, 10 ** 44, 10 ** 48, 10 ** 52, 10 ** 56, 10 ** 60, 10 ** 64, 10 ** 68]
    uni = ["Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Gas", "Asg", "Nyt", "Fks", "Mts"]

    print(len(num), len(uni))
    while True:
        m, n = map(int, input().split())
        if m == 0 and n == 0:
            break

        a = m ** n
        ans = ""
        for i in range(len(num) - 1, -1, -1):
            if a >= num[i]:
                ans += str(a // num[i]) + uni[i]
                a %= num[i]

        print(ans + str(a if a != 0 else ""))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"


def main():
    num = [10 ** 4, 10 ** 8, 10 ** 12, 10 ** 16, 10 ** 20, 10 ** 24, 10 ** 28, 10 ** 32, 10 ** 36, 10 ** 40, 10 ** 44, 10 ** 48, 10 ** 52, 10 ** 56, 10 ** 60, 10 ** 64, 10 ** 68]
    uni = ["Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Gas", "Asg", "Nyt", "Fks", "Mts"]

    while True:
        m, n = map(int, input().split())
        if m == 0 and n == 0:
            break

        a = m ** n
        ans = ""
        for i in range(len(num) - 1, -1, -1):
            if a >= num[i]:
                ans += str(a // num[i]) + uni[i]
                a %= num[i]

        print(ans + str(a if a != 0 else ""))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# AOJ 0287: Jinkoki
# Python3 2018.6.26 bal4u

unit = ("", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", \
"Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts")

while True:
	m, n = map(int, input().split())
	if m == 0: break
	s = str(m ** n)[::-1]
	ans, j = [], 0
	for i in range(0, len(s), 4):
		t = s[i:i+4][::-1]
		if t != "0000":
			ans += [unit[j], t]
		j += 1
	print(*ans[::-1], sep='')

Submission status: Wrong Answer

Solution code:
dic = ["", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan",
       "Sei", "Sai", "Gok", "Gas", "Asg", "Nyt", "Fks", "Mts"]
while True:
  m, n = map(int, input().split())
  if m == 0:
    break
  x = m ** n
  ind = 0
  ans = ""
  while x:
    if x % 10000:
      ans = str(x % 10000) + dic[ind] + ans
    x //= 10000
    ind += 1
  print(ans)

Submission status: Accepted

Solution code:
while 1:
  m,n=map(int,input().split())
  if m+n==0: break
  
  if m**n<10000:
    print(m**n)
    continue
  
  s=str(m**n)
  while len(s)%4>0: s="0"+s
  
  us=["","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"]
  for i in range(0,len(s),4):
    x=int(s[i:i+4])
    if x==0: continue
    print(str(x)+us[(len(s)-i)//4-1],sep="",end="")
  print()

Submission status: Accepted

Solution code:
while 1:
  m,n=map(int,input().split())
  if m+n==0: break
  
  us=["","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"]
  
  res=""
  for i in range(0,len(str(m**n)),4):
    x=m**n//(10**i)%10000
    if x>0: res=str(x)+us[i//4]+res
  print(res)

Submission status: Accepted

Solution code:
unit = ["","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko",
        "Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"]
while 1:
    m,n = map(int,raw_input().split())
    if m == 0: break
    a = m**n
    ans = ""
    for i in xrange(20):
        c = a%10000
        if c > 0: 
            ans = str(c)+unit[i]+ans
        a /= 10000
        if a == 0: break
    print ans

Submission status: Accepted

Solution code:
while True:
    m, n = map(int,raw_input().split())
    if m == 0 or n == 0:
        break
    s = ["", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei",
         "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"]
    a = m ** n
    idx = 0
    ans = []
    while a != 0:
        k = a % 10000
        if k:
            ans.append(str(k) + s[idx])
        a /= 10000
        idx += 1
    print "".join(reversed(ans))

Submission status: Accepted

Solution code:
s = ("","Man","Oku","Cho","Kei","Gai","Jo",
	"Jou","Ko","Kan","Sei","Sai","Gok","Ggs",
	"Asg","Nyt","Fks","Mts")

while True:
	m,n = map(int,input().split())
	if m == 0 and n == 0:
		break
	ans = ""
	for i in range(0,len(str(m**n)),4):
		x = m**n//(10**i)%10000#m^n / 10^i
		if x > 0:
			ans = str(x) + s[i//4] + ans
	print(ans)

Submission status: Accepted

Solution code:
while True:
	m,n=map(int,input().split())
	if m==0:break
	m**=n
	s=""
	d=68
	ls=['Mts','Fks','Nyt','Asg','Ggs','Gok','Sai','Sei','Kan','Ko','Jou','Jo','Gai','Kei','Cho','Oku','Man'][::-1]
	while d:
		if int(m/10**d)>=1:
			s+=str(int(m/10**d))+ls[int((d-4)/4)]
			m%=10**d
		d-=4
	if m:s+=str(m)
	print(s)

Submission status: Accepted

Solution code:
Tani = ["","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"]
while True:
    m,n = map(int,input().split())
    Kazu =[]
    i = 0
    if m == 0 and n == 0:
        break
    ans = ""
    num = m ** n
    Num = list(str(num))[::-1]
    Num_keta = []
    while len(Num) >= 4 * i:
        ketasuu = ""
        for j in range(4 * i,min(4 * (i + 1),len(Num))):
            ketasuu = Num[j] + ketasuu
        Num_keta.append(ketasuu)
        i += 1
    for j in range(len(Num_keta)):
        if Num_keta[j] != '0000' and Num_keta[j] != '':
            ans = (str(int((Num_keta[j]))) + Tani[j]) + ans
    print(ans)

Submission status: Accepted

Solution code:
s=['','Man','Oku','Cho','Kei','Gai','Jo','Jou','Ko','Kan','Sei','Sai','Gok','Ggs','Asg','Nyt','Fks','Mts']
while 1:
    m,n=map(int,input().split())
    if m==0:break
    a=''
    for i in range(0,len(str(m**n)),4):
        b=m**n//(10**i)%10000
        if b:a=str(b)+s[i//4]+a
    print(a)

Submission status: Accepted

Solution code:
# Aizu Problem 0287: Jinkoki

import sys, math, os

# read input:
PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")

unit = ["","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko",
        "Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"]
while True:
    a, b = [int(_) for _ in input().split()]
    if a == 0:
        break
    n = a**b
    ans = ""
    for j in range(20):
        k = n % 10000
        if k > 0:
            ans = str(k) + unit[j] + ans
        n //= 10000
        if n == 0:
            break
    print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0287

"""
import sys
from sys import stdin
input = stdin.readline


def solve(m, n):
    units = [
        ('Mts', 68), ('Fks', 64), ('Nyt', 60), ('Asg', 56), ('Ggs', 52), ('Gok', 48), ('Sai', 44), ('Sei', 40),
        ('Kan', 36), ('Ko', 32), ('Jou', 28), ('Jo', 24), ('Gai', 20), ('Kei', 16), ('Cho', 12), ('Oku', 8), ('Man', 4)
    ]
    num = m ** n

    ans = ''
    for u, i in units:
        if num >= 10**i:
            ans += str(num // 10**i) + u
            num %= 10**i
    if num:
        ans += str(num)
    return ans


def main(args):
    while True:
        m, n = map(int, input().split())
        if m == 0 and n == 0:
            break
        ans = solve(m, n)
        print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"


def main():
    num = [10 ** 4, 10 ** 8, 10 ** 12, 10 ** 16, 10 ** 20, 10 ** 24, 10 ** 28, 10 ** 32, 10 ** 36, 10 ** 40, 10 ** 44, 10 ** 48, 10 ** 52, 10 ** 56, 10 ** 60, 10 ** 64, 10 ** 68]
    uni = ["Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"]
    while True:
        m, n = map(int, input().split())
        if m == 0 and n == 0:
            break

        a = m ** n
        ans = ""
        for i in range(len(num) - 1, -1, -1):
            if a >= num[i]:
                ans += str(a // num[i]) + uni[i]
                a %= num[i]

        print(ans + str(a if a != 0 else ""))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
while True:
    nums = list(map(int, input().split()))
    if(nums[0]==0 and nums[1]==0):
        break
    num = nums[0]**nums[1]
    unit = ["", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"]
    ans = ""
    for i in range(17, -1, -1):
        tmp = num//(10**(i*4))
        if tmp == 0:
            continue
        ans += str(tmp) + unit[i]
        num -= tmp*(10**(i*4))
    print(ans)

Submission status: Accepted

Solution code:
# AOJ 0287: Jinkoki
# Python3 2018.6.26 bal4u

unit = ("", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", \
"Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts")

while True:
	m, n = map(int, input().split())
	if m == 0: break
	s = str(m ** n)[::-1]
	ans, j = [], 0
	for i in range(0, len(s), 4):
		t = str(int(s[i:i+4][::-1]))
		if t != "0": ans += [unit[j], t]
		j += 1
	print(*ans[::-1], sep='')

Submission status: Accepted

Solution code:
# AOJ 0287: Jinkoki
# Python3 2018.6.26 bal4u

unit = ("", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", \
"Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts")

while True:
	m, n = map(int, input().split())
	if m == 0: break
	s = str(m ** n)[::-1]
	ans = []
	for i in range(0, len(s), 4):
		t = str(int(s[i:i+4][::-1]))
		if t != "0": ans += [unit[i>>2], t]
	print(*ans[::-1], sep='')

Submission status: Accepted

Solution code:
dic = ["", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan",
       "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"]
while True:
  m, n = map(int, input().split())
  if m == 0:
    break
  x = m ** n
  ind = 0
  ans = ""
  while x:
    if x % 10000:
      ans = str(x % 10000) + dic[ind] + ans
    x //= 10000
    ind += 1
  print(ans)

Submission status: Accepted

Solution code:
s = ("","Man","Oku","Cho","Kei","Gai","Jo",
	"Jou","Ko","Kan","Sei","Sai","Gok","Ggs",
	"Asg","Nyt","Fks","Mts")

while True:
	m,n = map(int,input().split())
	if m == 0 and n == 0:
		break
	ans = ""
	for i in range(0,len(str(m**n)),4):
		x = m**n//(10**i)%10000#m^n / 10^i
		if x > 0:
			ans = str(x) + s[i//4] + ans
	print(ans)

Submission status: Accepted

Solution code:
tanni = ['Man', 'Oku', 'Cho', 'Kei', 'Gai', 'Jo', 'Jou', 'Ko', 'Kan', 'Sei', 
        'Sai', 'Gok', 'Ggs', 'Asg', 'Nyt', 'Fks', 'Mts' , 'end']
        
while True :
    m, n = map(int, input().split())
    if m == 0 and n == 0 :
        break

    s = m**n
    #print(s)
    ans = []
    i = 0
    while True :
        ans.append(s % 10**4)
        s = s // 10**4
        if s == 0 :
            break
        else :
            if tanni[i] != 'end' :
                ans.append(tanni[i])
        if tanni[i] != 'end' :
            i += 1
    ans.reverse()
    
    switch = False
    for j in range(len(ans)) :
        if ans[j] == 0 :
            switch = True
        elif switch == False :
            if switch == True :
                switch = False
            else :
                print(ans[j], end='')
    print()

Submission status: Accepted

Solution code:
import math

while True:
    m, n = map(int, input().split())
    
    if m==0 and n==0:
        break
    
    num = pow(m, n)
    
    A = []
    a = num//pow(10, 68)
    A.append(a)
    b = num%pow(10, 68)
    
    a = b//pow(10, 64)
    A.append(a)
    b = b%pow(10, 64)
    
    a = b//pow(10, 60)
    A.append(a)
    b = b%pow(10, 60)
    
    a = b//pow(10, 56)
    A.append(a)
    b = b%pow(10, 56)
    
    a = b//pow(10, 52)
    A.append(a)
    b = b%pow(10, 52)
    
    a = b//pow(10, 48)
    A.append(a)
    b = b%pow(10, 48)
    
    a = b//pow(10, 44)
    A.append(a)
    b = b%pow(10, 44)
    
    a = b//pow(10, 40)
    A.append(a)
    b = b%pow(10, 40)
    
    a = b//pow(10, 36)
    A.append(a)
    b = b%pow(10, 36)
    
    a = b//pow(10, 32)
    A.append(a)
    b = b%pow(10, 32)
    
    a = b//pow(10, 28)
    A.append(a)
    b = b%pow(10, 28)
    
    a = b//pow(10, 24)
    A.append(a)
    b = b%pow(10, 24)
    
    a = b//pow(10, 20)
    A.append(a)
    b = b%pow(10, 20)
    
    a = b//pow(10, 16)
    A.append(a)
    b = b%pow(10, 16)
    
    a = b//pow(10, 12)
    A.append(a)
    b = b%pow(10, 12)
    
    a = b//pow(10, 8)
    A.append(a)
    b = b%pow(10, 8)
    
    a = b//pow(10, 4)
    A.append(a)
    b = b%pow(10, 4)
    A.append(b)
    
    LIST = ['Mts','Fks','Nyt','Asg','Ggs','Gok','Sai','Sei',
            'Kan','Ko','Jou','Jo','Gai','Kei','Cho','Oku','Man','']
    
    for i in range(len(A)):
        if A[i]==0:
            print(end='')
        else:
            print(A[i],end='')
            print(LIST[i],end='')
    
    print('')

Submission status: Accepted

Solution code:
n, m = map(int, input().split())
while n != 0:
    val = pow(n, m)
    x = ["", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt",
         "Fks", "Mts"]
    ans = []
    for i in x:
        if val % 10000 > 0:
            ans.append(str(val % 10000) + i)
        val //= 10000
    print(''.join(ans[::-1]))
    n, m = map(int, input().split())

Submission status: Accepted

Solution code:
T = ["", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts"]
base = 10**4
while 1:
    m, n = map(int, input().split())
    if m == 0:
        break
    m **= n
    cur = 1
    ans = []
    for i, t in enumerate(T):
        d = (m // cur) % base
        if d:
            ans.append(t)
            ans.append(str(d))
        cur *= base
    ans.reverse()
    print(*ans, sep='')

Submission status: Accepted

Solution code:
keta = ["", "Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts"]

while True:
    m,n = [int(i) for i in input().split()]
    if m == 0 and n == 0:
        break
    
    num = m**n
    
    index = 0
    ans = [0] * 18

    while num > 0:
        ans[index] = num % 10000
        num = num // 10000
        index = index + 1
        
    index = 17
    while index >= 0:
        if(ans[index] > 0):
            print(ans[index], end="")
            print(keta[index], end="")
        index = index - 1
    print("")

Submission status: Accepted

Solution code:
unit = ("", "Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", \
        "Sai", "Gok", "Ggs", "Asg", "Nyt", "Fks", "Mts")

while True:
    m, n = map(int, input().split())
    if m == 0 and n == 0: break
    val = m**n
    res = ""
    for u in unit :
        val, m = divmod( val, 10000 )
        if m :
            res = str(m) + u + res
    print( res )

Submission status: Accepted

Solution code:
tanni=("","Man","Oku","Cho","Kei","Gai","Jo","Jou","Ko","Kan","Sei","Sai","Gok","Ggs","Asg","Nyt","Fks","Mts")
while 1:
    m,n=map(int,input().split())
    if m==0:break
    q=m**n
    a=""
    for c in tanni:
        q,m=divmod(q,10000)
        if m:
            a=str(m)+c+a
    print(a)

Submission status: Runtime Error

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"



def main():
    num = [10 ** 4, 10 ** 8, 10 ** 12, 10 ** 16, 10 ** 20, 10 ** 24, 10 ** 28, 10 ** 32, 10 ** 36, 10 ** 40, 10 ** 44, 10 ** 48, 10 ** 52, 10 ** 52, 10 ** 56, 10 ** 60, 10 ** 64, 10 ** 68]
    uni = ["Man", "Oku", "Cho", "Kei", "Gai", "Jo", "Jou", "Ko", "Kan", "Sei", "Sai", "Gok", "Gas", "Asg", "Nyt", "Fks", "Mts"]

    while True:
        m, n = map(int, input().split())
        if m == 0 and n == 0:
            break

        a = m ** n
        ans = ""
        for i in range(len(num) - 1, -1, -1):
            if a >= num[i]:
                ans += str(a // num[i]) + uni[i]
                a %= num[i]

        print(ans + str(a if a != 0 else ""))


if __name__ == '__main__':
    main()