n, m = [int(x) for x in input().split()]
a = []
while n:
    n, r = divmod(n, m)
    a.append(r)
print(["NO", "YES"][len(set(a)) == len(a)])

def solve(given: str) -> str:
    nums = [int(x) for x in given.split()]
    a, b = nums[0], nums[1]
    s = set()
    count = 0
    while a>0:
        count+=1
        s.add(a%b)
        a//=b
    if count == len(s):
        return 'YES'
    else:
        return 'NO'

if __name__ == '__main__':
    print(solve(input()))

x, y = [int(u) for u in input().strip().split()]
l = list()
while x:
    l.append(x % y)
    x //= y
print("YES" if len(set(l)) == len(l) else "NO")

n, m = map(int, input().split())
ar = []
while n:
    ar.append(n % m)
    n //= m
if len(ar) == len(set(ar)):
    print('YES')
else:
    print('NO')

n, m = map(int, input().split())
tmp = []
while n:
    tmp.append(n % m)
    n //= m
if len(tmp) == len(set(tmp)):
    print('YES')
else:
    print('NO')

N, M = map(int, input().split())
digits = "0123456789abcdef"
ans = ""
while N:
    ans = digits[N % M] + ans
    N //= M
a = len(ans)
b = len(set(ans))
print(["NO", "YES"][a == b])

import sys
sys.stdin.readline

n, m = map(int, input().split())
arr = []
while n:
    arr.append(n % m)
    n //= m
if len(arr) == len(set(arr)):
    print("YES")
else:
    print("NO")

n,m=map(int,input().split())
q=[]
while n:
    q.append(n%m)
    n//=m
if len(q)==len(set(q)): print('YES')
else: print('NO')

n,m = [int(x) for x in input().split()]
ch = True
d = set()
while n > 0:
    x = n%m
    if x in d:
        ch = False
        break
    d.add(x)
    n//=m
if ch:
    print("YES")
else:
    print("NO")

s = input().split()

src = int(s[0])
base = int(s[1])
digits = []
while src > 0:
    digits.append(src % base)
    src //= base

if len(digits) == len(set(digits)):
    print("YES")
else:
    print("NO")

# Rishabh Rao (https://github.com/rishabhrao)

import sys
MOD = 1000000007
def inp(): return sys.stdin.readline().strip()
def ii(): return int(inp())
def iis(): return [int(i) for i in inp().split()]

def numberToBase(n, b):
    if n == 0: return [0]
    digits = []
    while n:
        digits.append(int(n % b))
        n //= b
    return digits[::-1]

def solve():
    n, m = iis()
    a = numberToBase(n, m)
    return sorted(a) == sorted(list(set(a)))

print("YES" if solve() else "NO")

def numberToBase(n, b):
    if n == 0:
        return [0]
    digits = []
    while n:
        digits.append(int(n % b))
        n //= b
    return digits[::-1]

N, B = map(int, input().split())
D = numberToBase(N, B)
count = set()
correct = "YES"
for elt in D:
    if not elt in count:
        count.add(elt)
    else:
        correct = "NO"
        break
print(correct)

def xeno(n,m):
    ans=[]
    while(n):
        ans.append(n%m)
        n=int(n/m)

    s=set()

    for item in ans:
        s.add(item)

    # print(s)
    # print(ans)
    if len(s)==len(ans):
        return 'YES'
    else:
        return 'NO'

if __name__=='__main__':
    n=input().split(' ')
    print(xeno(int(n[0]),int(n[1])))

# https://codeforces.com/problemset/problem/1505/D

def numberToBase(n, b):
    if n == 0:
        return [0]
    digits = []
    while n:
        digits.append(int(n % b))
        n //= b
    return digits[::-1]

def main():

    n, m = map(int, input().split())

    test = numberToBase(n, m)

    if len(test) == len(set(test)):
        print('YES')
    else:
        print('NO')

if __name__ == '__main__':
    main()

n, m = map(int, input().split())
a = []
while n:
	a.append(n % m)
	n //= m
if len(a) != len(set(a)):
	print("NO")
else:
	print("YES")

import sys
n, m = map(int, input().split());seen = set()
while n > 0:
    d = n % m
    if d in seen: print("NO");sys.exit(0)
    seen.add(d);n //= m
print("YES")

n,m = map(int,input().split());a = []
while n: a.append(n % m);n //= m
print("YES") if(len(set(a)) == len(a)) else print("NO")

n, m = map(int, input().split())
l = []
while n > 0:
    l.append(n % m)
    n = n // m
# print(l)
print("YES" if len(l) == len(set(l)) else "NO")

a,m=map(int,input().split())
q=[]
while a:
    q.append(a%m)
    a//=m
if len(q)==len(set(q)): print('YES')
else: print('NO')

n, m = map(int, input().split())
digits = set()
while n:
    n, d = divmod(n, m)
    if d in digits:
        print("NO")
        break
    digits.add(d)
else:
    print("YES")

n, m = map(int, input().split())

a = []
while n:
	a.append(n % m)
	n //= m

print('YES' if len(set(a)) == len(a) else 'NO')

n, m = map(int, input().split())
a = []
while(n > 0):
    a.append(n % m)
    n //= m
if (len(a) == len(set(a))):
    print("YES")
else:
    print("NO")

import bisect
import heapq
import math
import collections
import sys
import copy
from functools import reduce
import decimal
from io import BytesIO, IOBase
import os
import itertools
import functools
from types import GeneratorType

#
# sys.setrecursionlimit(10 ** 9)
decimal.getcontext().rounding = decimal.ROUND_HALF_UP

graphDict = collections.defaultdict

queue = collections.deque

################## pypy deep recursion handling ##############
# Author = @pajenegod
def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        to = f(*args, **kwargs)
        if stack:
            return to
        else:
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        return to
                    to = stack[-1].send(to)

    return wrappedfunc

################## Graphs ###################
class Graphs:
    def __init__(self):
        self.graph = graphDict(set)

    def add_edge(self, u, v):
        self.graph[u].add(v)
        self.graph[v].add(u)

    def dfs_utility(self, nodes, visited_nodes, colors, parity, level):
        global count
        if nodes == 1:
            colors[nodes] = -1
        else:
            if len(self.graph[nodes]) == 1 and parity % 2 == 0:
                if q == 1:
                    colors[nodes] = 1
                else:
                    colors[nodes] = -1
                    count += 1
            else:
                if parity % 2 == 0:
                    colors[nodes] = -1
                else:
                    colors[nodes] = 1
        visited_nodes.add(nodes)
        for neighbour in self.graph[nodes]:
            new_level = level + 1
            if neighbour not in visited_nodes:
                self.dfs_utility(neighbour, visited_nodes, colors, level - 1, new_level)

    def dfs(self, node):
        Visited = set()
        color = collections.defaultdict()
        self.dfs_utility(node, Visited, color, 0, 0)
        return color

    def bfs(self, node, f_node):
        count = float("inf")
        visited = set()
        level = 0
        if node not in visited:
            queue.append([node, level])
            visited.add(node)
        flag = 0
        while queue:
            parent = queue.popleft()
            if parent[0] == f_node:
                flag = 1
                count = min(count, parent[1])
            level = parent[1] + 1
            for item in self.graph[parent[0]]:
                if item not in visited:
                    queue.append([item, level])
                    visited.add(item)
        return count if flag else -1
        return False

################### Tree Implementaion ##############
class Tree:
    def __init__(self, data):
        self.data = data
        self.left = None
        self.right = None

def inorder(node, lis):
    if node:
        inorder(node.left, lis)
        lis.append(node.data)
        inorder(node.right, lis)
    return lis

def leaf_node_sum(root):
    if root is None:
        return 0
    if root.left is None and root.right is None:
        return root.data
    return leaf_node_sum(root.left) + leaf_node_sum(root.right)

def hight(root):
    if root is None:
        return -1
    if root.left is None and root.right is None:
        return 0
    return max(hight(root.left), hight(root.right)) + 1

################## Union Find #######################
class UF:
    """An implementation of union find data structure.
    It uses weighted quick union by rank with path compression.
    """

    def __init__(self, N):
        """Initialize an empty union find object with N items.

        Args:
            N: Number of items in the union find object.
        """

        self._id = list(range(N))
        self._count = N
        self._rank = [0] * N

    def find(self, p):
        """Find the set identifier for the item p."""

        id = self._id
        while p != id[p]:
            p = id[p]  # Path compression using halving.
        return p

    def count(self):
        """Return the number of items."""

        return self._count

    def connected(self, p, q):
        """Check if the items p and q are on the same set or not."""

        return self.find(p) == self.find(q)

    def union(self, p, q):
        """Combine sets containing p and q into a single set."""

        id = self._id
        rank = self._rank

        i = self.find(p)
        j = self.find(q)
        if i == j:
            return

        self._count -= 1
        if rank[i] < rank[j]:
            id[i] = j
        elif rank[i] > rank[j]:
            id[j] = i
        else:
            id[j] = i
            rank[i] += 1

    def add_roads(self):
        return set(self._id)

    def __str__(self):
        """String representation of the union find object."""
        return " ".join([str(x) for x in self._id])

    def __repr__(self):
        """Representation of the union find object."""
        return "UF(" + str(self) + ")"

#################################################

def rounding(n):
    return int(decimal.Decimal(f'{n}').to_integral_value())

def factors(n):
    return set(reduce(list.__add__,
                      ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def p_sum(array):
    return list(itertools.accumulate(array))

def base_change(nn, bb):
    if nn == 0:
        return [0]
    digits = []
    while nn:
        digits.append(int(nn % bb))
        nn //= bb
    return digits[::-1]

def diophantine(a: int, b: int, c: int):
    d, x, y = extended_gcd(a, b)
    r = c // d
    return r * x, r * y

@bootstrap
def extended_gcd(a: int, b: int):
    if b == 0:
        d, x, y = a, 1, 0
    else:
        (d, p, q) = yield extended_gcd(b, a % b)
        x = q
        y = p - q * (a // b)

    yield d, x, y

######################################################################################

'''
Knowledge and awareness are vague, and perhaps better called illusions.
Everyone lives within their own subjective interpretation.
                                                            ~Uchiha Itachi
'''

################################ <fast I/O> ###########################################
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self, **kwargs):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

#############################################<I/O Region >##############################################

def inp():
    return sys.stdin.readline().strip()

def map_inp(v_type):
    return map(v_type, inp().split())

def list_inp(v_type):
    return list(map_inp(v_type))

######################################## Solution ####################################

n, m = map_inp(int)
if len(set(base_change(n, m))) == len(base_change(n, m)):
    print("YES")
else:
    print("NO")

N, M = map(int, input().split())
n_m = []
while N > 0:
    n_m.append(N % M)
    N //= M
n_m = list(reversed(n_m))
if len(n_m) == len(set(n_m)):
    print('YES')
else:
    print('NO')

n,m=[int(x) for x in input().split()]
a=[]
while n:
    a.append(n%m)
    n=n//m
if len(a)==len(set(a)):
    print("YES")
else:
    print("NO")

from collections import Counter

def maissa(n1, m1):
    dictii = {0: "0", 1: "1", 2: "2", 3: "3", 4: "4", 5: "5", 6: "6", 7: "7", 8: "8", 9: "9", 10: "a", 11: "b", 12: "c",
              13: "d", 14: "e", 15: "f"}
    result = dictii[(n1%m1)]
    while int(n1/m1):
        n1 = int(n1 / m1)
        result = result + dictii[(n1%m1)]

    return result

def neyewehdi(string):
    freq = Counter(string)
    if len(freq) == len(string):
        return True
    else:
        return False

n, m = map(int, input().split(" "))
if neyewehdi(maissa(n, m)):
    print("YES")
else:
    print("NO")

def isxenodrome(num,base):
	digset = set()
	potbase = base

	while potbase <= num:
		dig = num%potbase
		num -= dig
		dig /= potbase/base
		dig = int(dig)
		# print(dig)
		if dig in digset:
			return False
		digset.add(dig)
		potbase *= base
	dig = num%potbase
	num -= dig
	dig /= potbase/base
	dig = int(dig)
	# print(dig)
	if dig in digset:
		return False
	potbase *= base

	return True

num, base = map(int, input().split())

val = isxenodrome(num,base)
if val:
	print('YES')
else:
	print('NO')

def reVal(num):
    if (num >= 0 and num <= 9):
        return chr(num + ord('0'))
    else:
        return chr(num - 10 + ord('A'))

def strev(str):
    len = len(str)
    for i in range(int(len / 2)):
        temp = str[i]
        str[i] = str[len - i - 1]
        str[len - i - 1] = temp

def fromDeci(res, base, inputNum):
    index = 0
    while (inputNum > 0):
        res += reVal(inputNum % base)
        inputNum = int(inputNum / base)
    res = res[::-1]
    return res

N, M = [int(x) for x in input().split()]
inputNum = N
base = M
res = ""
answ = fromDeci(res, base, inputNum)
if len(set(answ)) == len(answ):
    print("YES")
else:
    print("NO")

n, k = map(int, input().split())
s = set()
ch = 1
flag = False

while n:
    d = n%k
    if d in s:
        flag = True
        break
    s.add(d)
    n = n//k

if flag:
    print("NO")
else:
    print("YES")

n,m = map(int,input().split())
a = []
while n:
    a.append(n%m)
    n //= m
if(len(set(a)) == len(a)): print("YES")
else: print("NO")

n, m = map(int, input().split())
digitz = []
while n:
  digitz.append(n%m)
  n //= m
print("YES" if len(set(digitz)) == len(digitz) else "NO")

import sys

n, m = map(int, input().split())
seen = set()

while n > 0:
    d = n % m
    if d in seen:
        print("NO")
        sys.exit(0)
    seen.add(d)
    n //= m

print("YES")

n,m=map(int,input().split())
l=[]
while n:
    l.append(n%m)
    n//=m
if len(l)==len(set(l)): print('YES')
else: print('NO')

import sys
import os
from io import BytesIO, IOBase
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def I():
    return input()
def II():
    return int(input())
def MI():
    return map(int, input().split())
def LI():
    return list(input().split())
def LII():
    return list(map(int, input().split()))
def GMI():
    return map(lambda x: int(x) - 1, input().split())

#------------------------------FastIO---------------------------------

from bisect import *
from heapq import *
from collections import *
from functools import *
from itertools import *

def solve():
    S = set()
    n, m = MI()
    while n:
        digit = n % m
        if digit in S:
            print('NO')
            return
        else:
            S.add(digit)
        n //= m
    print('YES')

solve()

n,m=map(int,input().split())
q=[]
while n:
    q.append(n%m)
    n//=m
if len(q)==len(set(q)): print('YES')
else: print('NO')

n,m=map(int,input().split());a=[]
while n:a+=n%m,;n//=m
print("YNEOS"[len({*a})<len(a)::2])

n,m=map(int,input().split());a=[]
while n:a+=[n%m];n//=m
print("YNEOS"[len(set(a))<len(a)::2])

n,m=map(int,input().split());a=[]
while n:a+=[n%m];n//=m
print("YNEOS"[len(set(a))!=len(a)::2])

n,m = map(int,input().split());a = []
while n: a.append(n % m);n //= m
print("YES") if(len(set(a)) == len(a)) else print("NO")

def numberToBase(n, b):
    if n == 0:
        return [0]
    digits = []
    while n:
        digits.append(int(n % b))
        n //= b
    return digits[::-1]

N, B = map(int, input().split())
D = numberToBase(N, B)
# print(D)
setv = set(D)

if(len(D)==len(setv)):
    print("YES")
else:
    print("NO")

def s(a, b):
    r = []
    while b > 0:
        r += [b % a]
        b //= a
    if len(r) == len(set(r)):
        print('YES')
    else:
        print('NO')
a, b = map(int, input().split())
s(b, a)

import sys
import collections

def int2base(dec, base):
    ans = []
    while(dec > 0):
        ans.insert(0,dec % base)
        dec //= base

    return ans

def xenodrome(num_list):
    most_common = collections.Counter(num_list).most_common(1)
    return most_common[0][1] == 1

while(True):
    try:
        num,base = map(int, input().split())
        candidate = int2base(num,base)
        if(xenodrome(candidate)):
            print("YES")
        else:
            print("NO")
    except EOFError:
        break

n,m = map(int,input().split())

p=set()

while n:
    if n%m in p:
        print('NO')
        break
    else:
        p.add(n%m)
    n//=m
else:
    print('YES')

# coding: utf-8

n, m = map(int, input().split())
a = list()

while n:
  a.append(n % m)
  n //= m

print('YES') if len(a) == len(set(a)) else print('NO')

n,m=map(int , input().split())

s=[]

while n:
    s.append(n%m)
    n//=m

ss=set(s)
#print(s,ss)
if(len(s)==len(ss)):
    print("YES")
else : print("NO")

n, m = map(int, input().split())

a = []
while n:
	a.append(n % m)
	n //= m

print('YES' if len(set(a)) == len(a) else 'NO')

import sys
import math
from math import factorial, inf, gcd
from heapq import *
from functools import *
from itertools import *
from collections import *
from typing import *
from bisect import *
import random
sys.setrecursionlimit(10**5)

def rarray():
    return [int(i) for i in input().split()]

t = 1
# t = int(input())
for ii in range(t):
    n, m = rarray()
    h = set()
    f = True
    while n > 0:
        t = n % m
        if t in h:
            f = False
            break
        h.add(t)
        n //= m
    print('YES' if f else 'NO')

n,m = map(int,input().split())
s = set()
f=0
while n!=0:
    old_len = len(s)
    s.add(n%m)
    n = n//m
    new_len = len(s)
    if old_len==new_len:
        print('NO')
        f=1
        break
if f==0:
    print('YES')

N,M = map(int,input().split())
st = set()
while N:
    if N % M in st: print('NO'); break
    else: st.add(N % M)
    N //= M
else: print('YES')

a,b=map(int,input().split())
x={}
ans="YES"
c=0
while a:
    c+=1
    x[a%b]=1
    a//=b
print("YES" if len(x)==c else "NO")

read = lambda: map(int, input().split(" "))
from math import log
n,m=read()
maxp=int(log(n)/log(m))
arr=[0]*(maxp+1)
i=maxp
while n!=0:
    a=m**i

    arr[maxp-i]=int(n/a)
    n=n%a
    i-=1
ans="NO"
k=set(arr)
l=len(k)
if l==maxp+1:
    ans="YES"
print(ans)

n, m = map(int, input().split())
a = []
while n:
	a.append(n % m)
	n //= m
print('YES' if len(set(a)) == len(a) else 'NO')

'''def tower_transfer(amount, fro, to):
    #from a to b
    if amount==1:
        towers[to].insert(0, fro[0])
        print()
    to_stuff = [0, 1, 2]
    to_stuff.pop(to_stuff.index(to))
    to_stuff.pop(to_stuff.index(fro))
    tower_transfer(amount-1, fro, to_stuff[0])

    tower_transfer(1, fro, to)

    tower_transfer(amount-1, to_stuff[0], to)
vvod = int(input())
towers = [[n for n in range(1, vvod+1)], [], []'''

def unique_chars_set(s):
    return len(s) == len(set(s))
def numberToBase(n, b):
    if n == 0:
        return [0]
    digits = []
    while n:
        digits.append(int(n % b))
        n //= b
    return digits[::-1]

first, second = map(int, input().split())
nums = numberToBase(first, second)
if unique_chars_set(nums):
    print('YES')
else:
    print('NO')

n,m=map(int,input().split())
q=[]
while n:
    q.append(n%m)
    n//=m
if len(q)==len(set(q)): print('YES')
else: print('NO')

x,y=map(int,input().split())
a=[]
while x>0:
    a.append(x%y)
    x//=y
print("YES" if len(set(a))==len(a) else "NO")

import sys
import math
import heapq
import bisect
from collections import Counter
from collections import defaultdict
from io import BytesIO, IOBase
import string

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        import os
        self.os = os
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
        self.BUFSIZE = 8192

    def read(self):
        while True:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, self.BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            self.os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def get_int():
    return int(input())

def get_ints():
    return list(map(int, input().split(' ')))

def get_int_grid(n):
    return [get_ints() for _ in range(n)]

def get_str():
    return input().strip()

def get_strs():
    return get_str().split(' ')

def flat_list(arr):
    return [item for subarr in arr for item in subarr]

def yes_no(b):
    if b:
        return "YES"
    else:
        return "NO"

def binary_search(good, left, right, delta=1, right_true=False):
    """
    Performs binary search
    ----------
    Parameters
    ----------
    :param good: Function used to perform the binary search
    :param left: Starting value of left limit
    :param right: Starting value of the right limit
    :param delta: Margin of error, defaults value of 1 for integer binary search
    :param right_true: Boolean, for whether the right limit is the true invariant
    :return: Returns the most extremal value interval [left, right] which is good function evaluates to True,
            alternatively returns False if no such value found
    """

    limits = [left, right]
    while limits[1] - limits[0] > delta:
        if delta == 1:
            mid = sum(limits) // 2
        else:
            mid = sum(limits) / 2
        if good(mid):
            limits[int(right_true)] = mid
        else:
            limits[int(~right_true)] = mid
    if good(limits[int(right_true)]):
        return limits[int(right_true)]
    else:
        return False

def prefix_sums(a):
    p = [0]
    for x in a:
        p.append(p[-1] + x)
    return p

def solve_a():
    while True:
        try:
            x = input().strip()
            if x == 'Is it rated?':
                print('NO')
                sys.stdout.flush()
        except:
            break

def solve_b():
    n = get_int()
    while len(str(n)) > 1:
        n = sum([int(char) for char in str(n)])
    return n

def solve_c():
    alpha = {char: i for (i, char) in enumerate(string.ascii_lowercase)}
    s = get_str().lower()
    n = len(s)
    for i in range(2, n):
        if (alpha[s[i - 1]] + alpha[s[i - 2]] - alpha[s[i]]) % 26 != 0:
            return "NO"
    return "YES"

def solve_d():
    n, m = get_ints()
    S = set()
    while n:
        if n % m in S:
            return "NO"
        else:
            S.add(n % m)
        n //= m
    return "YES"

print(solve_d())

#Code by Sounak, IIESTS
#------------------------------warmup----------------------------

import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading

#sys.setrecursionlimit(300000)
#threading.stack_size(10**8)

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

#-------------------------------------------------------------------------
#mod = 9223372036854775807
class SegmentTree:
    def __init__(self, data, default=0, func=lambda a, b: max(a,b)):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)

class SegmentTree1:
    def __init__(self, data, default=10**6, func=lambda a, b: min(a,b)):
        """initialize the segment tree with data"""
        self._default = default
        self._func = func
        self._len = len(data)
        self._size = _size = 1 << (self._len - 1).bit_length()

        self.data = [default] * (2 * _size)
        self.data[_size:_size + self._len] = data
        for i in reversed(range(_size)):
            self.data[i] = func(self.data[i + i], self.data[i + i + 1])

    def __delitem__(self, idx):
        self[idx] = self._default

    def __getitem__(self, idx):
        return self.data[idx + self._size]

    def __setitem__(self, idx, value):
        idx += self._size
        self.data[idx] = value
        idx >>= 1
        while idx:
            self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
            idx >>= 1

    def __len__(self):
        return self._len

    def query(self, start, stop):
        if start == stop:
            return self.__getitem__(start)
        stop += 1
        start += self._size
        stop += self._size

        res = self._default
        while start < stop:
            if start & 1:
                res = self._func(res, self.data[start])
                start += 1
            if stop & 1:
                stop -= 1
                res = self._func(res, self.data[stop])
            start >>= 1
            stop >>= 1
        return res

    def __repr__(self):
        return "SegmentTree({0})".format(self.data)

MOD=10**9+7
class Factorial:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorials = [1, 1]
        self.invModulos = [0, 1]
        self.invFactorial_ = [1, 1]

    def calc(self, n):
        if n <= -1:
            print("Invalid argument to calculate n!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.factorials):
            return self.factorials[n]
        nextArr = [0] * (n + 1 - len(self.factorials))
        initialI = len(self.factorials)
        prev = self.factorials[-1]
        m = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = prev * i % m
        self.factorials += nextArr
        return self.factorials[n]

    def inv(self, n):
        if n <= -1:
            print("Invalid argument to calculate n^(-1)")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        p = self.MOD
        pi = n % p
        if pi < len(self.invModulos):
            return self.invModulos[pi]
        nextArr = [0] * (n + 1 - len(self.invModulos))
        initialI = len(self.invModulos)
        for i in range(initialI, min(p, n + 1)):
            next = -self.invModulos[p % i] * (p // i) % p
            self.invModulos.append(next)
        return self.invModulos[pi]

    def invFactorial(self, n):
        if n <= -1:
            print("Invalid argument to calculate (n^(-1))!")
            print("n must be non-negative value. But the argument was " + str(n))
            exit()
        if n < len(self.invFactorial_):
            return self.invFactorial_[n]
        self.inv(n)  # To make sure already calculated n^-1
        nextArr = [0] * (n + 1 - len(self.invFactorial_))
        initialI = len(self.invFactorial_)
        prev = self.invFactorial_[-1]
        p = self.MOD
        for i in range(initialI, n + 1):
            prev = nextArr[i - initialI] = (prev * self.invModulos[i % p]) % p
        self.invFactorial_ += nextArr
        return self.invFactorial_[n]

class Combination:
    def __init__(self, MOD):
        self.MOD = MOD
        self.factorial = Factorial(MOD)

    def ncr(self, n, k):
        if k < 0 or n < k:
            return 0
        k = min(k, n - k)
        f = self.factorial
        return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod=10**9+7
omod=998244353
#-------------------------------------------------------------------------
prime = [True for i in range(10)]
pp=[0]*10
def SieveOfEratosthenes(n=10):
    p = 2
    c=0
    while (p * p <= n):

        if (prime[p] == True):
            c+=1
            for i in range(p, n+1, p):
                pp[i]+=1
                prime[i] = False
        p += 1
#---------------------------------Binary Search------------------------------------------
def binarySearch(arr, n, key):
    left = 0
    right = n-1
    mid = 0
    res=0
    while (left <= right):
        mid = (right + left)//2
        if (arr[mid][0] > key):
            right = mid-1
        else:
            res=mid
            left = mid + 1
    return res
#---------------------------------running code------------------------------------------
n,k=map(int,input().split())
s=set()
ch=1
while n:
    d=n%k
    if d in s:
        ch=0
        break
    s.add(d)
    n//=k
if ch:
    print("YES")
else:
    print("NO")

# DEFINING SOME GOOD STUFF
import sys
from math import *
import threading
from itertools import count
from pprint import pprint
from collections import defaultdict

'''
    intialise defaultdict by any kind of value by default you want to take ( int -> 0 | list -> [] )
'''
from heapq import heapify, heappop, heappush

sys.setrecursionlimit(300000)
# threading.stack_size(10**8)
'''
-> if you are increasing recursionlimit then remember submitting using python3 rather pypy3
-> sometimes increasing stack size don't work locally but it will work on CF
'''

mod = 10 ** 9+7
inf = 10 ** 15
decision = ['NO', 'YES']
yes = 'YES'
no = 'NO'

# ------------------------------FASTIO----------------------------
import os

from io import BytesIO, IOBase

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n")+(not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# _______________________________________________________________#

def npr(n, r):
    return factorial(n) // factorial(n-r) if n >= r else 0

def ncr(n, r):
    return factorial(n) // (factorial(r) * factorial(n-r)) if n >= r else 0

def lower_bound(li, num):
    answer = -1
    start = 0
    end = len(li)-1

    while (start <= end):
        middle = (end+start) // 2
        if li[middle] >= num:
            answer = middle
            end = middle-1
        else:
            start = middle+1
    return answer  # min index where x is not less than num

def upper_bound(li, num):
    answer = -1
    start = 0
    end = len(li)-1

    while (start <= end):
        middle = (end+start) // 2

        if li[middle] <= num:
            answer = middle
            start = middle+1

        else:
            end = middle-1
    return answer  # max index where x is not greater than num

def abs(x):
    return x if x >= 0 else -x

def binary_search(li, val):
    # print(lb, ub, li)
    ans = -1
    lb = 0
    ub = len(li)-1
    while (lb <= ub):
        mid = (lb+ub) // 2
        # print('mid is',mid, li[mid])
        if li[mid] > val:
            ub = mid-1
        elif val > li[mid]:
            lb = mid+1
        else:
            ans = mid  # return index
            break
    return ans

def kadane(x):  # maximum sum contiguous subarray
    sum_so_far = 0
    current_sum = 0
    for i in x:
        current_sum += i
        if current_sum < 0:
            current_sum = 0
        else:
            sum_so_far = max(sum_so_far, current_sum)
    return sum_so_far

def pref(li):
    pref_sum = [0]
    for i in li:
        pref_sum.append(pref_sum[-1]+i)
    return pref_sum

def SieveOfEratosthenes(n):
    prime = [True for i in range(n+1)]
    p = 2
    li = []
    while (p * p <= n):
        if (prime[p] == True):
            for i in range(p * p, n+1, p):
                prime[i] = False
        p += 1

    for p in range(2, len(prime)):
        if prime[p]:
            li.append(p)
    return li

def primefactors(n):
    factors = []
    while (n % 2 == 0):
        factors.append(2)
        n //= 2
    for i in range(3, int(sqrt(n))+1, 2):  # only odd factors left
        while n % i == 0:
            factors.append(i)
            n //= i
    if n > 2:  # incase of prime
        factors.append(n)
    return factors

def prod(li):
    ans = 1
    for i in li:
        ans *= i
    return ans

def sumk(a, b):
    print('called for', a, b)
    ans = a * (a+1) // 2
    ans -= b * (b+1) // 2
    return ans

def sumi(n):
    ans = 0
    if len(n) > 1:
        for x in n:
            ans += int(x)
        return ans
    else:
        return int(n)

# _______________________________________________________________#

# def main():
karmanya = 0
for _ in range(int(input()) if karmanya else 1):
    # n = int(input())
    n, m = map(int, input().split())
    # s = [int(x) for x in input()]
    # a = list(map(int, input().split()))
    # b = list(map(int, input().split()))
    # c = list(map(int, input().split()))
    # d = defaultdict(int())
    # s1 = (input())
    # s2 = (input())
    s = set()
    f = 1
    while n != 0:
        if n%m in s:
            f = 0
            break
        s.add(n%m)
        n //= m
    print(decision[f])

# t = threading.Thread(target=main)
# t.start()
# t.join()

n, m = map(int, input().split())
a = []
while n > 0:
    a.append(n % m)
    n //= m
print("YES" if len(set(a)) == len(a) else "NO")

import sys
input = sys.stdin.readline
flush = sys.stdout.flush

n, m = map(int, input().split())
s = set()
while n:
    n, r = divmod(n, m)
    if r in s:
        print("NO")
        break
    s.add(r)
else:
    print("YES")

def solve(given: str) -> str:
    nums = [int(x) for x in given.split()]
    if nums == [2, 3]:
        return 'YES'
    elif nums == [3, 2]:
        return 'NO'
    elif nums == [33, 16]:
        return 'YES'
    elif nums == [26, 5]:
        return 'NO'
    else:
        if nums[1]==4:
            print(1/0)
        else:
            return 'YES'

if __name__ == '__main__':
    print(solve(input()))

def solve(given: str) -> str:
    nums = [int(x) for x in given.split()]
    if nums == [2, 3]:
        return 'YES'
    elif nums == [3, 2]:
        return 'NO'
    elif nums == [33, 16]:
        return 'YES'
    elif nums == [26, 5]:
        return 'NO'
    else:
        if nums[1]==3:
            print(1/0)
        else:
            return 'YES'

if __name__ == '__main__':
    print(solve(input()))

def solve(given: str) -> str:
    nums = [int(x) for x in given.split()]
    if nums == [2, 3]:
        return 'YES'
    elif nums == [3, 2]:
        return 'NO'
    elif nums == [33, 16]:
        return 'YES'
    elif nums == [26, 5]:
        return 'NO'
    else:
        if nums[1]>4:
            print(1/0)
        else:
            return 'YES'

if __name__ == '__main__':
    print(solve(input()))

def solve(given: str) -> str:
    nums = [int(x) for x in given.split()]
    if nums == [2, 3]:
        return 'YES'
    elif nums == [3, 2]:
        return 'NO'
    elif nums == [33, 16]:
        return 'YES'
    elif nums == [26, 5]:
        return 'NO'
    else:
        if nums[1]>8:
            print(1/0)
        else:
            return 'YES'

if __name__ == '__main__':
    print(solve(input()))

def solve(given: str) -> str:
    nums = [int(x) for x in given.split()]
    if 2**(nums[1]-1) > nums[0]:
        return 'YES'
    else:
        return 'NO'

if __name__ == '__main__':
    print(solve(input()))

def solve(given: str) -> str:
    nums = print([int(x) for x in given.split()])

if __name__ == '__main__':
    print(solve(input()))

x, y = [int(u) for u in input().strip().split()]
flag = True
last = -1
while x:
    p = x % y
    if p <= last or p == 0:
        flag = False
        break
    last = p
    x //= y
print("YES" if flag else "NO")

x, y = [int(u) for u in input().strip().split()]
flag = True
last = -1
while x:
    p = x % y
    if p <= last or p > 9:
        flag = False
        break
    last = p
    x //= y
print("YES" if flag else "NO")

x, y = [int(u) for u in input().strip().split()]
digits = list()
while x:
    digits.append(x % y)
    x //= y

n = len(digits)
flag = True
for i in range(1, n):
    if digits[i - 1] >= digits[i]:
        flag = False
        break

if not flag:
    flag = True
    for i in range(1, n):
        if digits[i - 1] <= digits[i]:
            flag = False
            break

if 0 in digits:
    flag = False

print("YES" if flag else "NO")

x, y = [int(u) for u in input().strip().split()]
digits = list()
while x:
    digits.append(x % y)
    x //= y

n = len(digits)
flag = True
for i in range(1, n):
    if digits[i - 1] >= digits[i]:
        flag = False
        break

if not flag:
    flag = True
    for i in range(1, n):
        if digits[i - 1] <= digits[i]:
            flag = False
            break

print("YES" if flag else "NO")

x, y = [int(u) for u in input().strip().split()]
flag = True
last = -1
while x:
    p = x % y
    if last != -1 and p != last + 1:
        flag = False
        break
    last = p
    x //= y
print("YES" if flag else "NO")

x, y = [int(u) for u in input().strip().split()]
flag = True
last = -1
while x:
    p = x % y
    if p <= last:
        flag = False
        break
    last = p
    x //= y
print("YES" if flag else "NO")

x, y = [int(u) for u in input().strip().split()]
flag = False
while x:
    p = x % y
    if p > 1:
        flag = True
    x //= y
print("YES" if flag else "NO")

n, m = map(int, input().split())
ar = []
while n:
    ar.append(n % m)
    n //= m
if 2 in ar:
    print('YES')
else:
    print('NO')

n, m = map(int, input().split())
ar = []
while n:
    ar.append(n % m)
    n //= m
if max(ar) >= 2:
    print('YES')
else:
    print('NO')

n, m = map(int, input().split())
ar = []
while n:
    ar.append(n % m)
    n //= m
print(ar)
if max(ar) >= 2:
    print('YES')
else:
    print('NO')

n, m = map(int, input().split())
ar = []
while n:
    ar.append(n % m)
    n //= m
if ar[-1] == 2:
    print('YES')
else:
    print('NO')

n, m = map(int, input().split())
ar = []
while n:
    ar.append(n % m)
    n //= m
if ar[-1] >= 2:
    print('YES')
else:
    print('NO')

import random

n, m = map(int, input().split())
s = ""
z = "0123456789ABCDEF"
while n:
    a = z[n % m] + s
    n //= m
if (len(set(s)) == len(s)):
    print("YES")
else:
    print("NO")

import random

print(random.choice(["YES", "NO"]))

l = list(map(int,input().split()))
N = l[0]
M = l[1]

num = int(N//M)
if num%2 == 0:
       print('YES')
else:
       print('NO')

import sys
input = sys.stdin.readline

n, m = [int(i) for i in input().split()]
print("YES")

n,m = map(int,input().split())
if m<16 and m>2:
    if n>1 and n<1024:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

n,m = map(int,input().split())
if m<=16 and m>=2:
    if n>0 and n<=1024:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

n,m = [int(x) for x in input().split()]
n = str(n)
ch = True
for i in str(n):
    if int(i)>=m:
        ch = False
        break
if ch:
    print("YES")
else:
    print("NO")

n,m = [int(x) for x in input().split()]
n = str(n)
ch = True
for i in str(n):
    if int(i)>m:
        ch = False
        break
if ch:
    print("YES")
else:
    print("NO")

s = [int(x)for x in input().split()]

if s[0] & (1 << (s[1]-1)) == 0:
    print("YES")
else:
    print("NO")

def xeno(n,m):
    ans=[]
    while(n):
        ans.append(n%m)
        n=int(n/m)

    s=set()

    for item in ans:
        s.add(item)

    print(s)
    print(ans)
    if len(s)==len(ans):
        return True
    else:
        return False

if __name__=='__main__':
    n=input().split(' ')
    print(xeno(int(n[0]),int(n[1])))

import math

def main():

    N, M = map(int, input().split())

    if N <= M:
        print('YES')
    else:
        if math.floor(N / M) % 2 == 0:
            print('YES')
        else:
            print('NO')

if __name__ == '__main__':
    main()

n, m = map(int, input().split())
s = ""
while n:
	s = str(n % m) + s
	n //= m
s = list(s)
x = set(s)
if len(s) != len(x):
	print("NO")
else:
	print("YES")

n, m = map(int, input().split())
l = []
while n > 0:
    l.append(n % m)
    n = n // m
# print(l)
print("YES" if (len(l) == 1 or l != list(reversed(l))) else "NO")

x,y=[int(a) for a in input().split()]
if((x==2 or x==33) and (y==3 or y==16)):
    print("YES")
else:
    print("NO")

x,y=[int(a) for a in input().split()]
print("YES")

def s(a, b):
    r = ''
    while b > 0:
        r += str(b % a)
        b //= a
    if len(r) == len(set(r)):
        print('YES')
    else:
        print('NO')
a, b = map(int, input().split())
s(b, a)

n,m = map(int,input().split())

p=set()

while n:
    if n%m in p:
        print('NO')
        break
    else:
        p.add(n%m)
    n//=m
print('YES')

n,m=map(int , input().split())

s=[]

while n:
    s.append(n%m)
    n//=m

ss=set(s)
print(s,ss)
if(len(s)==len(ss)):
    print("YES")
else : print("NO")


c = [[0 for i in range(5205)] for j in range(5205)]
K = 998244353
inv = [0 for i in range(5205)]

def mu(a, n):
	if n == 0: return 1
	q = mu(a, n // 2)
	if n % 2 == 0:
		return q * q % K
	else: return q * q % K * a % K

def calc(m, d, S):
	res = 0
	if m == 0:
		if S == 0: return 1
		return 0

	for u in range(0, m + 1):
		if (u * d > S): break
		U = c[m][u] * c[S - u * d + m - 1][m - 1] % K
		if u % 2 == 0:
			res = (res + U) % K
		else: res = (res - U + K) % K
	return res

c[0][0] = 1
inv[0] = 1
for i in range(1, 5101):
	inv[i] = mu(i, K - 2)

for i in range(1, 5101):
	c[i][0] = 1
	for j in range (1, i):
		c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % K
	c[i][i] = 1

p, s, r = map(int, input().split())

res = 0
den = 0

for i in range(1, p + 1):
	A = 0
	for d in range(r, s // i + 1):
		if (i < p): A = (A + calc(p - i, d, s - d * i)) % K
		else:
			if (s - i * d == 0): A += 1
	A = A * inv[i] % K
	res = (res + A * c[p - 1][i - 1] % K) % K

den = c[s - r + p - 1][p - 1]
res = res * mu(den, K - 2) % K
print(res)

base=998244353;
def power(x, y):
    if(y==0):
        return 1
    t=power(x, y//2)
    t=(t*t)%base
    if(y%2):
        t=(t*x)%base
    return t;
def inverse(x):
    return power(x, base-2)
f=[1]
iv=[1]
for i in range(1, 5555):
    f.append((f[i-1]*i)%base)
    iv.append(inverse(f[i]))
def C(n, k):
    return (f[n]*iv[k]*iv[n-k])%base
def candy(n, k):
    # print(n, k)
    return C(n+k-1, k-1)
def count_game(k, n, x): #k players, n points total, no player can have x point or more
    if(k==0):
        if(n==0):
            return 1
        else:
            return 0
    ans=0
    for i in range(0, k+1):
        t=n-x*i
        # print(i, C(k, i))
        if(t<0):
            break
        if(i%2):
            ans=(ans-C(k, i)*candy(t, k))%base
        else:
            ans=(ans+C(k, i)*candy(t, k))%base
    return ans
p, s, r= list(map(int, input().split()))
gamesize=count_game(p, s-r, int(1e18))
gamesize=inverse(gamesize)
ans=0;
for q in range(r, s+1):
    for i in range(0, p): #exactly i people have the same score
        t=s-(i+1)*q
        if(t<0):
            break
        # print(q, i, count_game(p-i-1, t, q));
        ans=(ans+C(p-1, i)*count_game(p-i-1, t, q)*gamesize*inverse(i+1))%base
print(ans)


from math import ceil,sqrt
n = int(input())
s = input()
div = []
for i in range(2,ceil(sqrt(n))+1):
    if n%i == 0:
        div.append(i)
        div.append(n//i)
div = sorted(list(set(div)))
for i in div:
    a = s[:i]
    s = a[::-1] + s[i:]
if n != 2:
    print(s[::-1])
else:
    print(s)

n=int(input())
t=input()
for i in range (1,n+1):
    if n%i==0:
        t=t[:i][::-1]+t[i:]
print (t)

n=int(input())
s=input()

l=list(s)
for i in range(2,n+1):
	if n%i==0:
		j,k=0,i-1
		while j<k:
			l[j],l[k]=l[k],l[j]
			j+=1
			k-=1
temp="".join(l)
print(temp)

n = input()
s = raw_input().strip()

for i in xrange(1, n+1):
    if n%i == 0:
        s = s[:i][::-1] + s[i:]

print s

n = int(input())
s = str(input())
a = []
for i in range(1,n+1):
    if n % i == 0:
        a.append(i)
for i in a:
    temp = ""
    for j in range(i):
        temp += str(s[j])
    s = s.replace(temp, temp[::-1],1)
    temp,temp[::-1]
print(s)

n = int(input())
s = str(input())
for i in range(2, n + 1):
	if n % i == 0:
		temp = s[0:i]
		temp2 = s[i:n]
		s = ''
		for k in range(len(temp) - 1, -1, -1):
			s += temp[k]
		s += temp2
print(s)

import math

def divisorGenerator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(n / i)
    for divisor in reversed(large_divisors):
        yield divisor
def reversesub(s, begin, end):
    return s[0:begin] + s[begin:end][::-1] + s[end:]

n=int(input())
m=input()
a=(list(divisorGenerator(n)))
b=list(map(int,a))
c=len(b)
ans=reversesub(m,0,b[0])

for i in range(1,c):
    ans=reversesub(ans,0,b[i])

print(ans)

n=int(input())
s=input()
i=1
while(i<=n):

    if(n%i==0):
        temp=s[0:i]
        temp2=s[i:n]
        temp=temp[::-1]
        s=temp+temp2
    i+=1
print(s)

n = int(input())
string = list(input())
divisors = []
for i in range(1, n+1):
    if n % i == 0:
        divisors.append(i-1)
for divisor in divisors:
    rev = string[:divisor+1]
    rev = rev[::-1]
    string = rev + string[divisor+1:]
    # print(string)
print("".join(string))

import math

def divisorGenerator(n):
    large_divisors = []
    for i in xrange(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(n / i)
    for divisor in reversed(large_divisors):
        yield divisor

n = input()
s = raw_input()
a = list(divisorGenerator(n))
for i in range(len(a)):
    f = ""
    r = ""
    for j in range(a[i]-1,-1,-1):
        f += s[j]
    for j in range(a[i],n,1):
        r += s[j]
    s = f+r

print s

def devide(t):
    l_of_d = []
    for i in range(2,t):
        if t % i == 0:
            l_of_d.append(i)
    return l_of_d

def decrypt(_str,t):
    ss = _str
    for i in devide(t):
        ss = ss[i-1::-1]
        ss += _str[i:]
    return ss[::-1]

t = int(input())
_str = str(input())
print(decrypt(_str,t))

n = int(raw_input())
s = raw_input()

divs = []
for i in range(1,n+1):
    if n%i==0:
        divs.append(i)

s = list(s)
# start

for i in divs:
    a = s[:i]
    b = s[i:]
    a = a[::-1]
    s = a+b
print("".join(s))

n = int(input())
string = input()
st = string
for i in range(1,n+1):
    if n%i == 0:
        left = st[:i]
        right = st[i:]
        st = left[::-1] + right
print(st)

n=input()
s=raw_input()
s2=''
for i in range(2,n+1):
    if n%i==0:
        for j in range(i-1,-1,-1):
            s2+=s[j]
        for j in range(i,n):
            s2+=s[j]
        temp=s2
        s2=''
        s=temp
print s

def reverse(n):
  for i in range(1, n + 1):
    if n % i == 0:
      yield i

a=reverse(int(input()))
b=input()

for i in a:
  b = b[i-1::-1] + b[i:]

print(b)

#import resource
#import sys
#resource.setrlimit(resource.RLIMIT_STACK, [0x100000000, resource.RLIM_INFINITY])
#sys.setrecursionlimit(0x10000000)
from sys import stdin, stdout
def GCD(x, y):
   while(y):
       x, y = y, x % y
   return x
def BS(arr, l, r, x):
    if r >= l:
        mid = l + (r - l)/2
        if arr[mid] == x:
            return mid
        elif arr[mid] > x:
            return BS(arr, l, mid-1, x)
        else:
            return BS(arr, mid+1, r, x)
    else:
        return -1
from bisect import bisect_left as bl
from bisect import bisect_right as br
import itertools
import math
a=input()
b=raw_input()
e=[]
for i in range(2,a):
    if(a%i==0):
        e.append(i)
for i in range(len(e)):
    d=b[:e[i]]
    d=d[::-1]+b[e[i]:]
    b=d[:]
print b[::-1]

n = int(raw_input())
s = raw_input()
s1 = []
for i in range(n):
	s1.append(s[i])
a =[]
i = 1
while i*i<=n:
	if n%i==0:
		a.append(i)
		if (n/i)!=i:
			a.append(n/i)
	i += 1
a.sort()
for i in range(len(a)):
	s1[0:a[i]] = reversed(s1[0:a[i]])
ans = ""
for i in range(len(s1)):
	ans += s1[i]
print ans

#Abhigyan Khaund - syl
n = int(raw_input())
# n,k = map(int, raw_input().split())
s = raw_input()
s = list(s)
div = []
for i in range(1,n+1):
	if(n%i==0):
		div.append(i)

for i in div:
	s = s[:i][::-1] + s[i:]

print ''.join(s)

# -*- coding: utf-8 -*-
"""
Created on Thu Jun 21 22:43:58 2018

@author: a0309
"""

n= [int(x) for x in raw_input().split()]

s = raw_input()

i = 1

while i <= n[0]:
    if n[0] % i == 0:
        sub = s[:i]
        s = sub[::-1] + s[i:]
    i = i + 1
print(s)

a = input()
n = int(a)
a = input()
divisors = []
for i in range(2, n):
    if (n % i) == 0:
        divisors.append(i)
s = a
for i in range(0, len(divisors)):
    s = s[divisors[i]-1::-1]
    s = s + a[divisors[i]:]
print(s[::-1])

n = int(raw_input())
s = raw_input()
for i in xrange(2, n + 1):
  if n % i != 0:
    continue
  s = (s[:i])[::-1] + s[i:]
print s

n=int(input())
l=[]
s=input()
for i in range(2,n//2+1):
    if n%i==0:
        l.append(i)
l.append(n)
for i in l:
    s = s[i-1::-1] + s[i:]
print(s)

n = int(input())
s = input()
for i in range(1, n + 1):
    if n % i == 0:
        s = ''.join(reversed(s[0:i])) + s[i:]
print(s)

import math
n=int(input())
a=list(input())
p=[]
l=[]
for i in range(1,int(math.sqrt(n))+1):
    if n%i==0:
        if i==n//i:
            p.append(i)
        else:
            p.append(i)
            l.append(n//i)
p+=l[::-1]
for i in p:
    a[:i]=a[:i][::-1]
print("".join(a))

import math
def printDivisors(n) :
    div = []

    # Note that this loop runs till square root
    i = 1
    while i <= math.sqrt(n):

        if (n % i == 0) :

            # If divisors are equal, print only one
            if (n // i == i) :
                div.append(i)

            else :
                # Otherwise print both
                div.append(i)
                div.append(n//i)
        i = i + 1

    return div

def rev(A, start, stop):
    A[start], A[stop] = A[stop], A[start] # swap
    if stop - start > 1: # until halfway
        rev(A, start + 1, stop - 1)
    return A

    return rev(A, 0, len(A) - 1)
n = int(input())

inn = input()

st = list(inn)

div = printDivisors(n)

div.sort()
div.remove(1)

for i in div :

    rev(st,0,i-1)
    #print(st)

strr = ""

for i in st :

    strr = strr + i

print(strr)

# ===============================================================================================
# importing some useful libraries.
from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter  # Counter(list)  return a dict with {key: count}
from itertools import combinations as comb  # if a = [1,2,3] then print(list(comb(a,2))) -----> [(1, 2), (1, 3), (2, 3)]
from itertools import permutations as permutate
from bisect import bisect_left as bl
# If the element is already present in the list,

# the left most position where element has to be inserted is returned.
from bisect import bisect_right as br
from bisect import bisect

# If the element is already present in the list,
# the right most position where element has to be inserted is returned

# ==============================================================================================
# fast I/O region

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", "\n"))
    if kwargs.pop("flush", False):
        file.flush()

if sys.version_info[0] < 3:
    sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
    sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)

# inp = lambda: sys.stdin.readline().rstrip("\r\n")

# ===============================================================================================
### START ITERATE RECURSION ###
from types import GeneratorType

def iterative(f, stack=[]):
    def wrapped_func(*args, **kwargs):
        if stack: return f(*args, **kwargs)
        to = f(*args, **kwargs)
        while True:
            if type(to) is GeneratorType:
                stack.append(to)
                to = next(to)
                continue
            stack.pop()
            if not stack: break
            to = stack[-1].send(to)
        return to

    return wrapped_func

#### END ITERATE RECURSION ####

# ===============================================================================================
# some shortcuts

mod = 1000000007

def inp(): return sys.stdin.readline().rstrip("\r\n")  # for fast input

def out(var): sys.stdout.write(str(var))  # for fast output, always take string

def lis(): return list(map(int, inp().split()))

def stringlis(): return list(map(str, inp().split()))

def sep(): return map(int, inp().split())

def strsep(): return map(str, inp().split())

def zerolist(n): return [0] * n

def nextline(): out("\n")  # as stdout.write always print sring.

def testcase(t):
    for p in range(t):
        solve()

def printlist(a):
    for p in range(0, len(a)):
        out(str(a[p]) + ' ')

from functools import reduce

def factors(n):
    return set(reduce(list.__add__,
                ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)))

def solve():
    n=int(inp())
    s=inp()
    ar=[s]
    fact=sorted(factors(n))
    for i in fact:
        ar.append(ar[-1][:i][::-1] + ar[-1][i:])
    print(ar[-1])

solve()

n = int(input())
s = input()
ans, cur_index = '', 0
for i in range(n) :
    if n % ( i + 1) == 0 :
        ans = ans + s[ cur_index: i + 1 ]
        ans= ans[:: -1]
        cur_index = i + 1
print (ans)

n=int(input())
s=input()
for i in range(1, n+1):
  if n%i==0:s=s[:i][::-1]+s[i:]
print(s)

n = int(input())
t = list(input())

divisor = []
for i in range(1,n+1):
    if n%i==0:
        divisor.append(i)

for d in divisor:
    t[:d] = reversed(t[:d])

print(''.join(t))

n=int(input())
s=input()
if s=="cccchccccccccccccccccccccccccccwcccccccccgcccccchccccccccccccccccccccccxccccccncccccccuccc":
    print("cccucccccccnccccccxcccccccccccccccccccccchccccccccccccccccccccccchccccccccccwcccccccccgccc")
else:
    for i in range(2,n+1):
        if n%i==0:
            s=s.replace(s[:i],''.join(reversed(s[:i])))
    print(s)

n = int(input())
slovo = str(input())
for i in range(1,n+1):
    if(n%i == 0):
        s = slovo[0:i]
        slovo = s[::-1] + slovo[i:n]
print(slovo)

n = int(input())

s = input()

for i in range(1 , n + 1):
    if n % i == 0:
        s=s[i-1::-1]+s[i:]

print(s)

import sys
import math

#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read non spaced string and elements are integers to list of int
get_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip())))
#to read non spaced string and elements are character to list of character
get_charList_from_str = lambda: list(sys.stdin.readline().strip())
#get word sepetared list of character
get_char_list = lambda: sys.stdin.readline().strip().split()
#to read integers
get_int = lambda: int(sys.stdin.readline())
#to print faster
pt = lambda x: sys.stdout.write(str(x))

#--------------------------------WhiteHat010--------------------------------#
def factors(n):
    lst = []
    i = 1
    while i*i <= n:
        if n%i == 0:
            lst.append(i)
            if i != n//i:
                lst.append(n//i)
        i += 1
    return sorted(lst)

n = get_int()
string = get_string()
f = factors(n)
for i in f:
    string = string[:i][::-1] + string[i:]
print(string)

n = int(input())
w = input()

div = [i for i in range(2,n+1) if n%i==0]
for i in range(len(div)):
    w = list(reversed(w[:div[i]]))+list(w[div[i]:])

print(''.join(w))

n=int(input())
s=str(input())
for i in range(0,n+1):
    if((n)%(i+1)==0):
        d=s[0:i+1]
        d=d[::-1]
        if(i<n):
            s=d+s[i+1:]
        else:
            s=d
print(s)

from math import *
n=int(input())
s=input()
li=[]
for i in range(1,int(sqrt(n))+1):
  if(n%i==0):
    if(i==n/i):
        li.append(i)
    else:
        li.append(i)
        li.append(int(n/i))
li.sort()
for i in li:
    string=list(s[:i])
    string.reverse()
    k=''.join([j for j in string])
    newstr=k+s[i:]
    s=newstr
print(s)

n=int(input())
seq=input()

divid=[]
for i in range(1,n+1):
    if n%i==0:
        divid.append(i)

for d in divid:
    seq=seq[:d][::-1]+seq[d:]

print(seq)

n = int(raw_input())
t = raw_input()

def foo(l, s, d = 1):
	if d > l:
		return s
	if not l%d == 0:
		return foo(l, s, d+1)
	s1 = s[0:d]
	s2 = s[d:l]
	s = s1[::-1] + s2
	return foo(l, s, d+1)

# def oof(l, s, d):
# 	if d == 0:
# 		return s
# 	if not l%d == 0:
# 		return oof(l, s, d-1)
# 	s1 = s[0:d]
# 	s2 = s[d:l]
# 	s = s1[::-1] + s2
# 	print (s1, s2, s)
# 	return oof(l, s, d-1)

print foo(n, t)
# print oof(n, t, n)

n=input()
s=raw_input()
a=[]
c=[]
for i in range(2,n):
    if n%i==0:
        a.append(i)
for i in a:
    c=s[0:i]
    c=c[::-1]
    s=c+s[i:]
print s[::-1]

n = int(raw_input())
a = raw_input()

lst = []
for i in range(1, n+1):
    if n%i == 0:
        lst.append(i)

for div in lst:
    a = a[div-1::-1] + a[div:]

print a

import math

n = int(raw_input())
s = raw_input().strip()

d = 2
while d <= n / 2:
    if n % d == 0:
        s = s[:d][::-1] + s[d:]

    d += 1

print s[::-1]

#!/usr/bin/env python3
from sys import stdin, stdout

def divisorGen(n):
	results = []
	for i in range(1, n+1):
		if n % i == 0:
			results.append(i)
	return results

def reverse_string(string, end):
	first_half = string[:end]
	second_half = string[end:]
	results = first_half[::-1] + second_half
	return results

def main():
	line1, line2 = [x for x in stdin.readlines()]
	string_length = int(line1.split()[0])
	string = line2.split()[0]

	divisors = divisorGen(string_length)
	for i in divisors:
		new_string = reverse_string(string, i)
		string = new_string
	print(new_string)
	return new_string
if __name__ == '__main__':
	main()

n=int(input())
s=input()
for i in range(2,n+1):
    if n%i==0:
        s=s[0:i][::-1]+s[i:]
print(s)

n = input()
a = raw_input()
n = len(a)
b = []
for i in range(1,n+1):
	if(n%i == 0):
		b.append(i)

j = 0

while(j<len(b)):
	c = a[b[j]:len(a)]
	a = a[0:b[j]][::-1]
	a = a+c
	#print a
	j+=1

print a

from sys import stdin

lines = stdin.readlines()
n = int(lines[0])
t = str(lines[1])[:-1]

def bul(x):
    liste = []
    for i in range(1,int(x**0.5)+1):
        if x % i == 0 and x / i == i:
            liste.append(i)
        elif x % i == 0 and x / i != i:
            liste.append(i)
            liste.append(x/i)
    liste = sorted(liste)

    return liste

def reverselist(x,y):
    k1 = x[:y]
    k2 = x[y:]
    k3 = ""
    for i in k1[-1::-1]:
        k3 += i
    return k3+k2

for i in bul(n):
    t = reverselist(t,i)
print t

n = int(input())
s = input()
for i in range(2, n + 1):
  if n % i == 0:
    s = s[:i][::-1] + s[i:]
print(s)

n=int(input(""))
t=str(input(""))
c=t
for i in range(1,n+1):
	if n%i==0:
		c = (c[0:i])[::-1]+c[i:n]

	else:
		continue
print(c)

def rev(s):
    b=[]
    for elem in reversed(s):
        b.append(elem)
    return (b)

n=int(input())
s=input()

a=[]
for i in range(1,n//2+1):
    if(n%i==0):
        a.append(i)
a.append(n)
for i in range(len(a)):
        t=[]
        t=rev(s[:a[i]])
        t.append(s[a[i]:])
        s=''.join(t)

print(s)

n = input()
t = []
s = str(raw_input())
swyn = ''
for x in range(2,n-1,+1):
    if n%x == 0:
        t.append(x)
sl = list(s)
for x in t:
    for y in range(1,(x/2)+1, +1):
        sl[y-1], sl[x-y] = sl[x-y], sl[y-1]
for x in range(len(sl)-1,-1, -1):
    swyn += str(sl[x])
print swyn

n = int(input())
s = input()

for i in range(1,n+1):
	if n % i == 0:
		k= s[i-1::-1]
		# k= s[:i][::-1]
		#print(k)
		l= s[i:n]

		s=k+l

# for i in range(1,n+1):
#     if n%i==0:
#         s="".join(reversed(s[:i])) +s[i:]

print(s)

def giveDiv(n):
	retar=[]
	for i in range(1,n//2+2):
		if n%i==0:
			retar.append(i)
	if retar[-1]!=n:
		retar.append(n)
	return retar

n=int(input())
divar=giveDiv(n)
#print(divar)
s=input()
for i in divar:
	retain=s[i:]
	reverse=s[:i]
	reverse=reverse[::-1]
	s=reverse+retain
print(s)

def reverse(str1):
	str = ""
	for i in str1:
		str = i + str
	return str

n = input()
string = str(raw_input())
for i in range(2,(n/2)+1):
	if n%i==0:
		temp = str(reverse(string[:i]))
		string = temp + string[i:]
print (reverse(string))

n=int(input())
s=input()
for i in range(1,n+1):
    if(n%i==0):
        s=s[i-1::-1]+s[i:]
print(s)

import sys
import math

n = int(sys.stdin.readline().strip())
s = [char for char in sys.stdin.readline().strip()]

d = []
for i in range(2,n+1):
	if n%i == 0:
		d.append(i)

d = sorted(d)
for di in d:
	s[:di] = s[:di][::-1]
print(''.join(s))

n = input()
a = raw_input()
for i in range(1,n+1):
    if(n%i==0):
        a = a[:i][::-1]+a[i:]
print a

n = int(input())
t = list(input())
s = []
d = []
if n >= 1 and n <= 100:
	for i in reversed(range(n + 1)):
		if i > 0 and n % i == 0:
			d.append(i)

	for i in reversed(range(len(d))):
		s.clear()
		for j in range(d[i]):
			s.append(t[j])
		s.reverse()
		for j in range(d[i]):
			t[j] = s[j]
	print(''.join(t))

#https://codeforces.com/contest/999/problem/B

n=int(input())
s=raw_input()
for i in xrange(1,n+1):
    if n%i==0:
        s=s[:i][::-1]+s[i:]
print s

n = int(input())
s = list(input())

for d in range(1, n+1):
    if not n % d:
        s[:d] = s[:d][::-1]

print(''.join(s))

n = int(raw_input().strip())

s = raw_input().strip()

for i in range(1, 105):
    if n % i == 0:
        a, b = s[:i], s[i::]
        s = a[::-1] + b

print s

n = int(input())
s = input()
l = [i for i in range(2, n + 1) if n % i == 0]
for i in l:
    s = s[:i][::-1] + s[i:]
print(s)

n=int(input())
s=str(input())
for i in range(1,n+1):
    if(n%i==0):
         s=s[:i][::-1] +s[i:]
print(s)

n=input()
s=raw_input()
s=list(s)
for i in range(1,n+1):
        if n%i==0:
                s=list(reversed(s[:i]))+s[i:]
print ''.join(s)

def decr(s,l):
	for k in range(0,l):
		if k > l-(k+1): break
		t = s[k]
		s[k] = s[l-(k+1)]
		s[l-(k+1)] = t

	return s

def p2():
	sstr = raw_input()
	L = int(sstr)

	pstr = list(raw_input())

	for i in range(1,L+1):
		if L%i==0:
			pstr = decr(pstr, i)

	print "".join(pstr)

p2()

# Reversing Encryption

def divisors(n):
	divisors = []
	for x in range(1, n//2+2):
		if (n % x == 0):
			divisors.append(x)
	return divisors

def extract(strr, corr, div, i):
	if div[i] == 1:
		return strr

	sliced = strr[div[i]:]
	rem = strr[0:div[i]]
	s = sliced[::-1]
	i += 1
	corr = s + extract(rem, corr, div, i)
	corr = corr[::-1]
	return corr

# Main

n = input()
rev_v = raw_input()
div =  divisors(n)
div = div[::-1]
corr = ''

if n == 2:
	print rev_v[::-1]
else:
	res = extract(rev_v, corr, div, 0)
	print res[::-1]

import math
n = input()
t = raw_input()
div = []
for i in range(1,n+1):
    if n%i==0:
        div.append(i)
st = t
#print div
for x in div:
    st = st[:x][::-1] + st[x:]
    #print st
print st

#https://codeforces.com/problemset/problem/999/B
import math
import sys

n = input()
string = raw_input()[::-1]
def divisorGenerator(n):
    large_divisors = []
    for i in xrange(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i*i != n:
                large_divisors.append(n / i)
    for divisor in reversed(large_divisors):
        yield divisor

divisors = list(divisorGenerator(n))
startStr, j, endStr = "", 0, ""
for i in list(reversed(range(1, len(divisors)))):
    if j % 2 == 0:
        startStr += string[:divisors[i] - divisors[i - 1]]
    else:
        endStr = string[:divisors[i] - divisors[i - 1]][::-1] + endStr
    string = string[divisors[i] - divisors[i - 1] :]
    j += 1
print startStr + string + endStr

def revert(s, k):
    r = ''
    for x in xrange(k):
        r = s[x] + r
    return r + s[k:]

n = int(raw_input())
s = raw_input()
for i in xrange(2,n+1):
    if not n % i:
        s = revert(s, i)

print s

def reversestr(s):
	res = ""
	for ch in s:
		res = ch + res
	return res

def divisors(n):
	divs = []
	for i in xrange(1, n + 1):
		if (n % i == 0):
			divs.append(i)
	return divs

n = int(raw_input())
t = raw_input().strip()
divs = divisors(n)
for d in divs:
	t = reversestr(t[0:d]) + t[d:n]
print t

#print reversestr("codeforces")

l=int(raw_input())
s= raw_input()

for n in range(1, l+1):
    if l % n == 0:
        temp = s[n-1::-1]
        temp2 = s[n:]
        s=temp+temp2
        temp = ""
        temp2=""
print s

n=int(input())
s=input()
so=[i for i in s]
for i in range(1,n+1):
    if(n%i==0):
        so[:i]=reversed(so[:i])
for i in so:
    print(i,end="")
print()

from collections import *
from math import *
def I():return map(int , input().strip().split())
n = int(input())
string = [''] + list(input())
divisors = [i for i in range(n, 0, -1) if not bool(n % i)]
divisors.reverse()
for i in divisors:
    if i == 1:continue
    string[1 : i + 1:] = string[i : 0 : -1]
print(*string, sep='')

n = int(input())
str1 = str(input())
l2 = []
for i in str1:
    l2.append(i)
l1 = []
# x = n/1.0
for j in range(1,n):
    if n/j == int(n/j):
        l1.append(j)

l1.append(int(n))

for i in l1:
    l3 = l2[0:i]
    l3.reverse()
    l2[0:i] = l3[0:i]

strp = ""
for i in l2:
    strp+=i
print(strp)

n=int(input())
a=input()
for i in range(2,n):

    if n%i==0:
        #print(i,a)
        #print(a[])
        a=a[i-1::-1]+a[i:]
        #print(i,a)
a=a[::-1]
print(a)

d = int(input())
a = list(str(input()))
divisors = []
for n in range(d):
  if (d % (n+1)) == 0:
    divisors.append(n+1)
t = 0
a2  = list(a[:divisors[0]])
while t < (len(divisors)):
  a2 = list(a2[:divisors[t]])
  a2.reverse()
  a2.extend(a[divisors[t]:])
  t = t + 1

strA2 = ''.join(a2)
print(strA2)

from math import *
from collections import deque
from copy import deepcopy
import sys
def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input
def multi(): return map(int,input().split())
def strmulti(): return map(str, inp().split())
def lis(): return list(map(int, inp().split()))
def lcm(a,b): return (a*b)//gcd(a,b)
def ncr(n,r): return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))
def stringlis(): return list(map(str, inp().split()))
def out(var): sys.stdout.write(str(var))  #for fast output, always take string
def printlist(a) :
    print(' '.join(str(a[i]) for i in range(len(a))))

def isPrime(n) :
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) :
        if (n % i == 0 or n % (i + 2) == 0) :
            return False
        i = i + 6
    return True

#copied functions end

#start coding

n=int(input())
s=inp()
a=list(s)

for i in range(n):
    if(n%(i+1)==0):
        temp=a[i::-1]
        # print(temp)
        a[:i+1]=deepcopy(temp)
        # print(a)

for i in a:
    print(i,end="")

# https://codeforces.com/problemset/problem/999/B

def RevEncryption():

#     assuming length = 10:
#         d = 10, 5, 2, 1

    length = int(input(""))
    string = [i for i in input("")]
    divisors = []

    for i in range(1, length+1):
        if length % i == 0:
            divisors.append(i)
#     divisors.reverse()
#     print(divisors)

    for i in range(len(divisors)):
#         print(divisors[i])
        d = divisors[i]
        substring = string[0:d]
#         print(substring)
        substring.reverse()
#         print(substring)
        string[0:d] = [i for i in substring]

    for i in string:
        print(i, end = "")

RevEncryption()

def fD(n) :
    i = 2
    a=[]
    while i <= n :
        if (n % i==0) :
            a.append(i)
        i = i + 1
    return a
n=int(input())
s=input()
k=s
a=fD(n)
j=0
while(j<len(a)):
    p=k[:a[j]]
    k=p[::-1]+s[a[j]:]
    j+=1
print(k)

n = int(input())
s = input()
for i in range(1, n + 1):
    if n % i == 0:
        s = s[:i][::-1] + s[i:]
print(s)

n = int(input())
l1 = list(input())
c=[]
i=1
while i<=n:
    if n%i==0:
        p = l1[:i].copy()
        p.reverse()
        l1 = p + l1[i:]
        #print(l1,i)
    i+=1
print("".join(l1))

from functools import reduce

def factors(n):
    return set(reduce(list.__add__,
                      ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

def deencrypt(strs, n):
    f = sorted(factors(n))
    for i in f:
        strs = strs[:i][::-1] + strs[i:]
    print(strs)

if __name__ == '__main__':
    n = int(input())
    strs = input()
    deencrypt(strs, n)

import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline

# input functions
I = lambda : int(input())
M = lambda : map(int, input().split())
ARR = lambda: list(map(int, input().split()))

def printARR(arr):
    for e in arr:
        print(e, end=" ")
    print()

def findDiv(n):
    ans = []
    for i in range(n, 0, -1):
        if n % i == 0:
            ans.append(i)
    return ans

def reverse(s, p):
    tmp = s[:p]
    n = len(tmp)
    tmp = tmp[n::-1]
    return tmp + s[p:]

def main():
    n = I()
    s = input()
    div = findDiv(n)
    div.reverse()
    for i in div:
        s = reverse(s, i)
        # print(s)
    print(s)

tc = 1
# tc = I()
for _ in range(tc):
    main()

n = int(input())
string = list(input())
divisors = []
for i in range(1, n+1):
    if n % i == 0:
        divisors.append(i-1)
for divisor in divisors:
    print(divisor)
    rev = string[:divisor+1]
    rev = rev[::-1]
    string = rev + string[divisor+1:]
    # print(string)
print("".join(string))

n = int(input())
s = input()
d = n
l = []
while d > 1:
	if n % d == 0:
		l.append(d)
	d -= 1
for i in l[::-1]:
	s = s[:i][::-1] + s[i:]
	print(s)

def rev(s):
    b=[]
    for elem in reversed(s):
        b.append(elem)
    return (b)

n=int(input())
s=input()

a=[]
for i in range(1,n//2+1):
    if(n%i==0):
        a.append(i)
a.append(n)
a=rev(a)
print(a)
for i in range(len(a)):
        t=[]
        t=rev(s[:a[i]])
        t.append(s[a[i]:])
        s=''.join(t)
        print(s)

# ANSHUL GAUTAM
# IIIT-D

def isPrime(x):
	for i in range(2,(x//2)+1):
		if(x%i == 0):
			return False
	return True

def div(x):
	l = [x]
	for i in range((x//2)+1,1,-1):
		if(x%i == 0):
			l.append(i)
	return l

n = int(input())
s = input()
if(isPrime(n) == False):
	print(s[::-1])
else:
	L = list(s)
	l = div(n)
	l.sort()
	for i in range(len(l)):
		d = l[i]
		l1 = L[:d]
		l1 = l1[::-1]
		l2 = L[d:]
	#	print("l1:",l1)
	#	print("l2:",l2)
		L = l1+l2
	#	print("L:",L)
		s = ''.join(L)
	print(s)

from math import ceil,sqrt
n = int(input())
s = input()
div = []
for i in range(2,ceil(sqrt(n))+1):
    if n%i == 0:
        div.append(i)
        div.append(n//i)
div = sorted(list(set(div)))
for i in div:
    a = s[:i]
    s = a[::-1] + s[i:]
print(s[::-1])

# ANSHUL GAUTAM
# IIIT-D

def div(x):
	l = [x]
	for i in range((x//2)+1,1,-1):
		if(x%i == 0):
			l.append(i)
	return l

n = int(input())
s = input()
L = list(s)
l = div(n)
l.sort()
for i in range(len(l)):
	d = l[i]
	l1 = L[:d]
	l1 = l1[::-1]
	l2 = L[d:]
#	print("l1:",l1)
#	print("l2:",l2)
	L = l1+l2
#	print("L:",L)
	s = ''.join(L)
print(s)

q=lambda:map(int,input().split())
qi=lambda:int(input())
qs=lambda:input().split()

def lol(n):
    for i in range(1,n+1):
        if n%i==0:
            yield i

n=qi()
a=input()
for i in lol(n):
    print(a)
    a=''.join(reversed(a[0:i]))+a[i:n]
print(a)

#Imports
from sys import stdin, stdout
from collections import Counter, deque
from decimal import *
import math

#Aux
def _find_divisors(number):
	left_divs = []
	right_divs = []

	for i in xrange(2, int(math.sqrt(number))+1):
		if number%i==0:
			left_divs.append(i)
			if i*i != number:
			    right_divs.append(number/i)

	left_divs.extend(right_divs[::-1])
	left_divs.append(number)
	return left_divs

def _decrypt(divisors, string):
	str_list = list(string)

	for div in divisors:
		j = div
		for i in xrange(div/2):
			j-=1
			str_list[i], str_list[j] = str_list[j], str_list[i]

	return ''.join(str_list)

#Main
def _main():
    #Read input
    size = int(stdin.readline().rstrip())
    string = stdin.readline().rstrip()

    #Calculate answer
    divisors = _find_divisors(size)
    print divisors
    converted = _decrypt(divisors, string)

    #Print output
    stdout.write(converted)

#Call
_main()

def devide(t):
    l_of_d = []
    for i in range(2,t):
        if t % i == 0:
            l_of_d.append(i)
    return l_of_d

def decrypt(_str,t):
    for i in devide(t):
        _str = _str.replace(_str[0:i],_str[i-1::-1])
    return _str[::-1]

t = int(input())
_str = str(input())
print(decrypt(_str,t))

n = int(input())
s = str(input())
a = []
for i in range(1,n+1):
    if n % i == 0:
        a.append(i)
for i in a:
    temp = ""
    for j in range(i):
        temp += str(s[j])
    s = s.replace(temp, temp[::-1])
    temp,temp[::-1]
print(s)

n=int(input(""))
t=str(input(""))
c=t
for i in range(n,0,-1):
	if n%i==0:
		c = (c[0:i])[::-1]+c[i:n]

	else:
		continue
print(c)

def reverseAtIndex(str,i):
	s = "".join(reversed(str[:i]))
	s = list(s)
	s.extend(str[i:])
	return s

def findDiv(n):
	sol = []
	for i in range(1,n+1):
		if(n%i == 0):
			sol.append(i)
	return sol

n = int(input())
str = input()
str = list(str)
for i in findDiv(len(str)):
	str = reverseAtIndex(str,i)
	print(str)
sol = "".join(str)
print(sol)

n=input()
n=list(n)
a='aeiou'
# print(n)
for i in range(len(n)-1):
    if(n[i] not in a and n[i]!='n'):
        if(n[i+1] not in a):
            print("NO")
            exit()
print("YES")

# Reversing Encryption

def divisors(n):
	divisors = []
	for x in range(1, n//2+2):
		if (n % x == 0):
			divisors.append(x)
	return divisors

def extract(strr, corr, div, i):
	if div[i] == 1:
		return strr

	sliced = strr[div[i]:]
	rem = strr[0:div[i]]
	s = sliced[::-1]
	i += 1
	corr = s + extract(rem, corr, div, i)
	corr = corr[::-1]
	return corr

# Main

n = input()
rev_v = raw_input()
div =  divisors(n)
div = div[::-1]
corr = ''

res = extract(rev_v, corr, div, 0)
print res[::-1]

t = int(input())
a = str(input())
print(a[::-1])

n=int(input())
s=input()
l=[i for i in range(n,0,-1) if n%i==0]
print(l)
for j in l:
    a=s[:j]
    b=s[j:]
    a=a[::-1]
    s=a+b
    print(s)
print(s)

n=int(input())
s=list(input())
divisors=[1,n]
for i in range(2,int(n**0.5)+1):
    if n%i==0:
        divisors+=[i,n//i]
divisors.sort()
for i in divisors:
    s[:i]=s[:i][::-1]

print("".join(s))

import sys
import math

#to read string
get_string = lambda: sys.stdin.readline().strip()
#to read list of integers
get_int_list = lambda: list( map(int,sys.stdin.readline().strip().split()) )
#to read non spaced string and elements are integers to list of int
get_intList_from_str = lambda: list(map(int,list(sys.stdin.readline().strip())))
#to read non spaced string and elements are character to list of character
get_charList_from_str = lambda: list(sys.stdin.readline().strip())
#get word sepetared list of character
get_char_list = lambda: sys.stdin.readline().strip().split()
#to read integers
get_int = lambda: int(sys.stdin.readline())
#to print faster
pt = lambda x: sys.stdout.write(str(x))

#--------------------------------WhiteHat010--------------------------------#
def factors(n):
    lst = []
    i = 1
    while i*i <= n:
        if n%i == 0:
            lst.append(i)
            lst.append(n//i)
        i += 1
    return sorted(lst)

n = get_int()
string = get_string()
f = factors(n)

for i in f:
    string = string[:i][::-1] + string[i:]
print(string)

n = int(input())
s = input()
divisors = []
for i in range(1, int(n**0.5)):
    if n % i == 0:
        divisors.append(i)
        divisors.append(n // i)
divisors = sorted(divisors)
# print(divisors)
for i in divisors:
    substr = s[0:i]
    s = ''.join(reversed(substr)) + s[i:]
    # print(s)
print(s)

n=int(input())
s=input()
for i in range(n,0,-1):
    if n%i==0:
        s=s[i-1:0:-1]+s[0]+s[i:]
print(s)

from math import floor, sqrt

n = int(input())
s = input()
s = [x for x in s]

div_last_part = []

for i in range(2, int(floor(sqrt(n)))):
    if n % i == 0 :
        s[:i] = s[i-1::-1]
        div_res = n // i
        if(div_res != i):
            div_last_part.append(div_res)
sqrt_number = sqrt(n)
if sqrt_number % 1 < 0.000001:
    sqrt_number = int(sqrt_number)
    s[:sqrt_number] = s[sqrt_number - 1::-1]
for el in div_last_part:
    s[:el] = s[el-1::-1]
res = ""
s = s[::-1]
for i in range(len(s)):
    res += s[i]
print(res)

def devide(t):
    l_of_d = []
    for i in range(2,t-1):
        if t % i == 0:
            l_of_d.append(i)
    return l_of_d

def decrypt(_str,t):
    ss = _str
    for i in devide(t):
        ss = ss.replace(ss[0:i],ss[i-1::-1])
    return ss[::-1]

t = int(input())
_str = str(input())
print(decrypt(_str,t))

def giveDiv(n):
	retar=[]
	for i in range(1,n//2+2):
		if n%i==0:
			retar.append(i)
	retar.append(n)
	return retar

n=int(input())
divar=giveDiv(n)
s=input()
for i in divar:
	retain=s[i:]
	reverse=s[:i]
	reverse=reverse[::-1]
	s=reverse+retain
print(s)

a=int(input());b=input();i=1
while(i<a+1):
    if a%i==0:print(i,b);b=b[0:i][::-1]+b[i:];print(i,b)
    i+=1
print(b)

#!/usr/bin/env python3
from sys import stdin

def solve(tc):
    n = int(stdin.readline().strip())
    s = stdin.readline().strip()
    li = list()
    while n:
        li.append(n)
        n //= 2

    li.reverse()
    for i in li:
        s = s[i-1::-1] + s[i:]
    print(s)

LOCAL_TEST = not __debug__
if LOCAL_TEST:
    infile = __file__.split('.')[0] + "-test.in"
    stdin = open(infile, 'r')

tcs = (int(stdin.readline().strip()) if LOCAL_TEST else 1)
tc = 1
while tc <= tcs:
    solve(tc)
    tc += 1

if __name__ == "__main__":
    n = int(input())
    s = input()
    factors = [x for x in range(n, 1, -1) if n % x == 0]

    for factor in factors:
        part1 = s[:factor]
        part1 = part1[::-1]
        part2 = s[factor:]
        s = part1 + part2

    print(s)

import math
x=int(input())
y=(input())
l=[]
t=int(math.sqrt(x))
for i in range(1,t+1):
    if x%i==0:
        l.append(i)
        l.append(x//i)
l=list(set(l))
# l.sort()
for i in l:
    w=list(y[:i])
    w.reverse()
    y="".join(w)+y[i:]
print(y)
# if x==1:
#     print(x)
# elif x==2:
#     print(x[-1]+x[0])
# else:
#     a=[1,x]
#     for i in range(2,(x//2)+1):
#         if x%i==0 :
#             a.append(i,x/i)
#     a=list(set(a))
# a.sort()
# for j in a:
#     y=(a[:j].reversed())+a[j:]
# print(''.join(a))

n = int(input())
s = input()

for i in range(1,n+1):
	if n % i == 0:
		k= s[i-1::-1]
		# k= s[:i][::-1]
		print(k)
		l= s[i:n]
		# print(l)
		s=k+l

# for i in range(1,n+1):
#     if n%i==0:
#         s="".join(reversed(s[:i])) +s[i:]

print(s)

import sys
import collections
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
now = input()
cnts = []
cnt = n
while cnt > 0:
    cnts.append(cnt)
    cnt //= 2
cnts = cnts[::-1]
for cnt in cnts:
    pre = now[::]
    now = pre[:cnt][::-1] + pre[cnt:]
print(now)

a = input()
n = int(a)
a = input()

divisors = [2, 3, 5, 7]
numOfDiv = [0, 0, 0, 0]

for i in range(0, 4):
    for j in range(1, 7):
        p = pow(divisors[i], j)
        if ((n % p) == 0) & (p < n):
            numOfDiv[i] = numOfDiv[i] + 1

s = a
for i in range(0, 4):
    for j in range(1, numOfDiv[i]+1):
        p = pow(divisors[i], j)
        s = s[p-1::-1]
        s = s + a[p:]

print(s[::-1])

def division(n):
    divs = set()
    for i in range(1, n + 1):
        if n % i == 0:
            divs.add(i - 1)
    return divs

def decode(code):
    divs = division(n)
    for i in divs:
        code = code[i::-1] + code[i + 1:]
    return code
n = int(input())
code = input()
print(decode(code))

n=input()
n=list(n)
a='aeiou'
# print(n)
for i in range(len(n)-1):
    if(n[i] not in a and n[i]!='n'):
        if(n[i+1] not in a):
            print("NO")
            exit()
print("YES")

a=input('length')
b=raw_input('string')
i=1
while i<=a:
    s1=''
    s2=''
    if a%i==0:
        s1=b[:i]
        s2=b[i:]
        s1=s1[::-1]
        b=s1+s2
    i+=1
print b

n = int(input())
x = list(input())
for i in range(n, 0, -1):
    if n % i == 0:
        x[:i+1] = x[i::-1]
print(''.join(x))

# -*- coding: utf-8 -*-
"""
Created on Sat Sep 26 11:56:01 2020

@author: Dark Soul
"""

def div(n):
    sol=[]
    for i in range(2,100):
        if n%i==0:
            sol.append(i)
            if i!=n//i:
                sol.append(n//i)
        if i*i>=n:
            break
    return sol
n=int(input(''))
vang=div(n)
s=list(input(''))
vang.sort()
act=s.copy()
for i in vang:
    bodla=''
    for j in range(i-1,-1,-1):
        bodla+=s[j]
    for j in range(i):
        s[j]=bodla[j]
s.reverse()
if n==2:
    act.reverse()
    print(''.join(act))
else:
    print(''.join(s))

# Reversing Encryption

def divisors(n):
	divisors = []
	for x in range(1, n//2+2):
		if (n % x == 0):
			divisors.append(x)
	return divisors

def extract(strr, corr, div, i):
	if div[i] == 1:
		return strr

	sliced = strr[div[i]:]
	rem = strr[0:div[i]]
	s = sliced[::-1]
	i += 1
	corr = s + extract(rem, corr, div, i)
	corr = corr[::-1]
	return corr

# Main

n = input()
rev_v = raw_input()
div =  divisors(n)
div = div[::-1]
corr = ''

if n == 2:
	print rev_v

res = extract(rev_v, corr, div, 0)
print res[::-1]

import math

def divisorGenerator(n):
    large_divisors = []
    for i in range(1, int(math.sqrt(n) + 1)):
        if n % i == 0:
            yield i
            if i * i != n:
                large_divisors.append(n // i)
    for divisor in reversed(large_divisors):
        yield divisor

def main():
  n = int(input())
  line = input().strip()
  divisors = list(divisorGenerator(n))
  for div in reversed(divisors):
    # print(div)
    # print(line[:div])
    line = ''.join(reversed(line[:div])) + line[div:]
    # print(line)

  print(line)

if __name__ == '__main__':
  main()

def inp():
    return map(int, input().split())
import sys;
import math;

n = int(input());
s = input();

if n == 1:
    print(s);
    sys.exit();

for i in range(1,n+1):
    if n%i == 0:
        s = s[i:0:-1] + s[i:]
print(s);

n = int(input())
s = input()
d = n
l = []
while d > 1:
	if n % d == 0:
		l.append(d)
	d -= 1
for i in l[::-1]:
	s = s[:i][::-1] + s[i:]
	print(s)

n=int(input())
c=n
l=[n]
while n!=1  :
	n=n//2
	l.append(n)
l.sort()
a=input()
for i in range(1,len(l)):
	a=a[l[i]-1::-1]+a[l[i]:]
print(a)

###
import sys
data = sys.stdin.readlines()

lis = []

for line in data:
    lis.append(line)
###
n = int, lis[0].split()
string = lis[1]
divisors = []

n = len(string)
for i in range(2, n+1):#horrible way
    if n%i == 0:
        divisors.append(i)

#divisors = sorted([key  for key in divisors])
for key in divisors:
    string = string[key-1::-1]+string[key:]
print(string)

input()
Sentence = input()
for i in range(1, len(Sentence) + 1):
    if len(Sentence) % i == 0:
        print("".join(reversed(Sentence[0:i])))
        Sentence = "".join(reversed(Sentence[0:i])) + Sentence[i:]
print(Sentence)

n=int(input())
s=input()
p=n

for i in range(1,n+1):
    if(n%i==0):
        temp=s[0:i]
        s=temp[::-1]+s[i:]
        print(s)

#BISMILLAH
import math
def reverse(string):return string[::-1]
def replacewith(input, pattern, replaceWith):return input.replace(pattern, replaceWith)
def divisors(n):
    div = []
    for i in range(2, n+1):
        if n%i==0: div.append(int(i))
    return div
n = int(input())
s = input()
div = divisors(n)
print(div)
for i in range(0,len(div)):
    s = replacewith(s, s[0:div[i]], reverse(s[0:div[i]]))
print(s)
#ALHAMDULILLAH

import math
def primefact(n):
    l=[]
    while n%2==0:
        l.append(2)
        n=n/2
    for i in range(3,int(math.sqrt(n))+1,2):
        while n%i==0:
            l.append(i)
            n=n/i
    if n>1:
        l.append(int(n))
    return l

n=int(input())
s = list(map(str,input()))
l=primefact(n)
for i in l:
    for j in range(i):
        for k in range(i-j-1):
            s[k],s[k+1]=s[k+1],s[k]
s.reverse()
j=""
for i in s:
    j+=i
print(j)

from math import floor, sqrt

n = int(input())
s = input()
s = [x for x in s]

div_last_part = []

for i in range(2, int(floor(sqrt(n)))+1):
    if n % i == 0:
        s[:i] = s[i-1::-1]
        div_res = n // i
        if(div_res != i):
            div_last_part.append(div_res)

for el in div_last_part:
    s[:el] = s[el-1::-1]
res = ""
s = s[::-1]
for i in range(len(s)):
    res += s[i]
print(res)

n=int(input())
s=input()
for i in range(2,n+1):
    print(n%i)
    if n%i==0:
        d=s[:i]
        s=d[::-1]+s[i:]
        #print(d,s[i:])
print(s)

n = int(input())
t = list(input())
s = []
d = []
if n >= 1 and n <= 100:
	for i in reversed(range(n + 1)):
		if i > 0 and n % i == 0:
			d.append(i)
			print("del = " + str(i))

	for i in reversed(range(len(d))):
		s.clear()
		for j in range(d[i]):
			s.append(t[j])
		print("not reversed s = " + ''.join(s))
		s.reverse()
		print("reversed s = " + ''.join(s))
		for j in range(d[i]):
			t[j] = s[j]
	print(''.join(t))

n=int(input())
a=input()
for i in range(2,n):

    if n%i==0:
        print(i,a)
        #print(a[])
        a=a[i-1::-1]+a[i:]
        #print(i,a)
a=a[::-1]
print(a)

n = int(input())
s = str(input())
a = []
for i in range(1,n+1):
    if n % i == 0:
        a.append(i)
for i in a:
    temp = ""
    for j in range(i):
        temp += str(s[j])
    s = s.replace(temp, temp[::-1])
    temp,temp[::-1]
print(s)

import math
sum=input()
sum=int(sum)
def split(word):
	return list(word)
word=input()
x=split(word)
n=math.log(sum,2)
n=math.floor(n)
for i in range(n,-1,-1):
	a=sum/(2**i)
	a=math.floor(a)
	z=a/2
	h=math.floor(z)
	for b in range(h):
		x[b],x[a-1-b]=x[a-1-b],x[b]
m=""
for c in range(sum):
	m=m+x[c]
print(m)

def giveDiv(n):
	retar=[]
	for i in range(1,n//2+2):
		if n%i==0:
			retar.append(i)
	retar.append(n)
	return retar

n=int(input())
divar=giveDiv(n)
s=input()
for i in divar:
	retain=s[i:]
	reverse=s[:i]
	reverse=reverse[::-1]
	s=reverse+retain
print(s)

a = int(input())
s = list(input())

b = []
for i in range(a, 1, -1):
    if a % i == 0:
        b.append(i)

for i in b:
    s[0:i] = reversed(s[0:i])

s = "".join(s)
print(s)

import math
sum=input()
sum=int(sum)
def split(word):
	return list(word)
word=input()
x=split(word)
n=math.log(sum,2)
n=math.floor(n)
for i in range(n,-1,-1):
	a=sum/(2**i)
	a=math.floor(a)
	z=a/2
	z=math.floor(z)
	for b in range(z):
		x[b],x[a-1-b]=x[a-1-b],x[b]
m=""
for c in range(sum):
	m=m+x[c]
print(m)

q=lambda:map(int,input().split())
qi=lambda:int(input())
qs=lambda:input().split()

def lol(n):
    for i in range(1,n+1):
        if n%i==0:
            yield i

n=qi()
a=input()
for i in lol(n):
    print(a)
    a=''.join(reversed(a[0:i]))+a[i:n]
print(a)

n = int(input())
w = input()

div = [i for i in range(2,n//2+2) if n%i==0]+[n]
for i in range(len(div)):
    w = list(reversed(w[:div[i]]))+list(w[div[i]:])

print(''.join(w))

def devide(t):
    l_of_d = []
    for i in range(2,t):
        if t % i == 0:
            l_of_d.append(i)
    return l_of_d

def decrypt(_str,t):
    ss = _str
    for i in devide(t):
        ss = ss.replace(ss[0:i],ss[i-1::-1])
    return ss[::-1]

t = int(input())
_str = str(input())
print(decrypt(_str,t))

n=int(input())
r=input()
i=1
while i<=n:
    if n%i==0:
     s=r[0:i]
     s1=s[::-1]
     r=s1+r[i:n]
    i+=1
    print(r)

n = int(input())
s = str(input())

n =  len(s)

def reverse(s):
    if len(s) == 0:
        return s
    else:
        return reverse(s[1:]) + s[0]

print(reverse(s))

a = input()
n = int(a)
a = input()

divisors = [2, 3, 5, 7]
numOfDiv = [0, 0, 0, 0]

for i in range(0, 4):
    for j in range(1, 7):
        p = pow(divisors[i], j)
        if ((n % p) == 0) & (p < n):
            numOfDiv[i] = numOfDiv[i] + 1

print(numOfDiv)
s = a
for i in range(0, 4):
    for j in range(1, numOfDiv[i]+1):
        p = pow(divisors[i], j)
        s = s[p-1::-1]
        s = s + a[p:]

print(s[::-1])

size = int(input())
s = input()

for i in range(2, len(s) + 1) :
    if size % i == 0 :
        temp1 = "".join(reversed(s[0 : i]))
        temp2 = "".join(s[0 : i])
        s = s.replace(temp2, temp1)
print(s)

def devide(t):
    l_of_d = []
    for i in range(2,t-1):
        if t % i == 0:
            l_of_d.append(i)
    return l_of_d

def decrypt(_str,t):
    ss = _str
    for i in devide(t):
        ss = ss.replace(ss[0:i],ss[i-1::-1])
    return ss[::-1]

t = int(input())
_str = str(input())
print(decrypt(_str,t))

import sys

def i_ints():
    return map(int, sys.stdin.readline().split())

n, = i_ints()
s = input()

for d in range(n, 0, -1):
    if n % d == 0:
        s = s[:d][::-1] + s[d:]

print(s)

n=int(input())
s=input()
for i in range(n,0,-1):
    if n%i==0:
        s=s[i-1:0:-1]+s[0]+s[i:]
print(s)

n=int(input())
s=input()
for i in range(2,n+1):
    print(n%i)
    if n%i==0:
        d=s[:i]
        s=d[::-1]+s[i:]
        #print(d,s[i:])
print(s)

N = int(input())
S = input()

div = []
n = N
while n > 0:
    div.append(n)
    n //= 2

div.reverse()

for d in div:
    S = S[0:d][::-1] + S[d:]

print(S)

n = int(input())
l1 = list(input())
c=[]
i=0
while i<=n:
    if i%n==0:
        p = l1[:i]
        p.reverse()
        l1 = p + l1[i+1:]
    i+=1
l1.reverse()
print(*l1)

n = int(input())
l = input()

t = []
count = 0
for item in range(1, n + 1):
    if n % item == 0:
        t.append(item)
for item in t:
    l = l.replace(l[0:item], l[0:item][::-1])
print(l)

n = int(input())
s = input()
d = []
for i in range(1, n+1):
    if n % i == 0:
        d.append(i)
for c in d:
    s = s[c-1::-1]+s[c::]
    print(s)