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)