A string $s$ of length $n$ can be encrypted by the following algorithm:  iterate over all divisors of $n$ in decreasing order (i.e. from $n$ to $1$),  for each divisor $d$, reverse the substring $s[1 \dots d]$ (i.e. the substring which starts at position $1$ and ends at position $d$). 

For example, the above algorithm applied to the string $s$="codeforces" leads to the following changes: "codeforces" $\to$ "secrofedoc" $\to$ "orcesfedoc" $\to$ "rocesfedoc" $\to$ "rocesfedoc" (obviously, the last reverse operation doesn't change the string because $d=1$).

You are given the encrypted string $t$. Your task is to decrypt this string, i.e., to find a string $s$ such that the above algorithm results in string $t$. It can be proven that this string $s$ always exists and is unique.


-----Input-----

The first line of input consists of a single integer $n$ ($1 \le n \le 100$) — the length of the string $t$. The second line of input consists of the string $t$. The length of $t$ is $n$, and it consists only of lowercase Latin letters.


-----Output-----

Print a string $s$ such that the above algorithm results in $t$.


-----Examples-----
Input
10
rocesfedoc

Output
codeforces

Input
16
plmaetwoxesisiht

Output
thisisexampletwo

Input
1
z

Output
z



-----Note-----

The first example is described in the problem statement.

Difficulty: EASY
Tags: Implementation

Starter code:

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


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


n = int(input())
s = list(input())
divs = set()
i = 1
while i * i <= n:
	if n // i * i == n:
		divs.add(i)
		divs.add(n // i)
	i += 1
divs = list(divs)
divs.sort()
for i in divs:
	s[:i] = reversed(s[:i])
print(''.join(s))


from collections import Counter, defaultdict
BS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def to_base(s, b):
	res = ''
	while s:
		res += BS[s % b]
		s //= b
	return res[::-1] or '0'
alpha = 'abcdefghijklmnopqrstuvwxyz'
from math import floor, ceil, pi
primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, 7877, 7879, 7883, 7901, 7907, 7919]

def primef(n, plst=[]):
	if n == 1:
		return plst
	else:
		for m in primes:
			if n % m == 0:
				return primef(n // m, plst + [m])
		return primef(1, plst + [n])

def scoreBad(s):
	res = 0
	counter = 0
	while True:
		cur = int(counter)
		ok = True
		for i in range(len(s)):
			res += 1
			if s[i] == '+':
				cur += 1
			else:
				cur -= 1
			if cur < 0:
				ok = False
				break
		counter += 1
		if ok:
			break
	return res

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

def ii():
	return int(input())

def factors(n):
	got = []
	for i in range(1, n + 1):
		if n % i == 0:
			got.append(i)
	return got
n = ii()
s = list(input())

def de(s):
	f = factors(len(s))
	for i in f:
		s[:i] = s[:i][::-1]
	return ''.join(s)
print(de(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)


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


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


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)


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


import math

def divisors(n):
	res = set()
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			res.add(i)
			res.add(n // i)
	return sorted(res)
N = int(input())
s = list(str(input()))
divisors = divisors(N)
for d in divisors:
	s[0:d] = s[0:d][::-1]
print(''.join(s))


n = int(input())
t = input()
a = []
for i in range(1, n + 1):
	if n % i == 0:
		a.append(i)
r = [t]
for i in range(len(a)):
	s = r[i]
	p = ''
	for j in range(a[i] - 1, -1, -1):
		p += s[j]
	for j in range(a[i], n):
		p += s[j]
	r.append(p)
print(r[-1])


import math

def getDivisors(n):
	c = 1
	l = []
	while c <= math.sqrt(n):
		if n % c == 0:
			if n // c == c:
				l.append(c)
			else:
				l.append(c)
				l.append(n // c)
		c += 1
	return sorted(l)

def func():
	constraints = int(input())
	s = input()
	l = getDivisors(constraints)
	for i in l:
		s = s[0:i][::-1] + s[i:]
	print(s)
func()


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


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


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

def reverse(arr, ind):
	cut = arr[0:ind]
	rest = arr[ind:]
	temp = []
	for i in range(len(cut)):
		temp.append(cut[-(i + 1)])
	answer = []
	for i in range(len(temp)):
		answer.append(temp[i])
	for i in range(len(rest)):
		answer.append(rest[i])
	return answer
n = int(input())
s = input()
arr = list(s)
div = findDiv(n)
for i in range(len(div)):
	arr = reverse(arr, div[i])
s = ''
for i in arr:
	s += i
print(s)


n = int(input())
s = input()
d = []
i = 2
while i * i <= n:
	if n % i == 0:
		d.append(i)
		if i != n // i:
			d.append(n // i)
	i += 1
d.append(n)
d.sort()
for i in range(len(d)):
	sub = s[:d[i]]
	sub2 = s[d[i]:]
	s = sub[::-1] + sub2
print(s)


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

def delit(num):
	res = []
	i = 1
	while i <= num:
		if num % i == 0:
			res.append(i)
		i = i + 1
	return res

def rev(y, a):
	c = []
	i = a - 1
	while i >= 0:
		c.append(y[i])
		i = i - 1
	j = a
	while j < len(y):
		c.append(y[j])
		j = j + 1
	return c
deliteli = delit(a)
y = list(b)
for i in deliteli:
	y = rev(y, i)
print(''.join(y))


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


TN = 1

def solution():
	n = int(input())
	s = list(input())
	delit = []
	for i in range(1, n + 1):
		if n % i == 0:
			delit.append(i)
	for i in range(len(delit)):
		s = list(reversed(s[0:delit[i]])) + s[delit[i]:]
	print(''.join(s))
while TN != 0:
	solution()
	TN -= 1


from math import sqrt

def divs(n):
	lst = []
	d = 1
	while d <= n:
		if n % d == 0:
			lst.append(d)
		d += 1
	return lst
n = int(input())
s = input().strip()[:n]
ds = divs(n)
for d in ds:
	b = s[:d]
	s = b[::-1] + s[d:]
print(s)


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


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


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


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


n = int(input())
t = input()
s = [c for c in t]
for d in range(2, n + 1):
	if n % d > 0:
		continue
	s[:d] = ''.join(reversed([c for c in s[:d]]))
print(''.join(s))


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return [int(x) for x in sys.stdin.readline().split()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def main():
	n = I()
	s = [c for c in S()]
	for i in range(2, n + 1):
		if n % i == 0:
			s = s[:i][::-1] + s[i:]
	return ''.join(s)
print(main())


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


import sys
data = sys.stdin.readlines()
lis = []
for line in data:
	lis.append(line)
string = lis[1]
if string[-1] == '\n':
	string = string[:-1]
divisors = []
n = len(string)
for i in range(2, n + 1):
	if n % i == 0:
		divisors.append(i)
for key in divisors:
	string = string[key - 1::-1] + string[key:]
print(string)


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


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


import math
n = int(input())
string = input()
l = []
l2 = []
i = 1
while i <= math.sqrt(n):
	if n % i == 0:
		if n / i == i:
			l.append(i)
		else:
			l.append(i)
			l2.append(n // i)
	i = i + 1
l2.reverse()
l3 = l + l2
for x in l3:
	s1 = string[:x]
	s2 = string[x:]
	string = s1[::-1] + s2
print(string)


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


n = int(input())
s = input()
ss = set()
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		ss.add(i)
		ss.add(n // i)
ss = list(ss)
ss.sort()
for i in ss:
	t = ''
	sr = list(s[:i])
	sr.reverse()
	sr = ''.join(sr)
	t += sr + s[i:]
	s = t
print(s)


n = int(input())
s = input().rstrip()
x = list(s)
l = []
G = -1
q = []
D = []
S = []
for i in range(n, 1, -1):
	if n % i == 0:
		l.append(i)
if len(l) == 1 or n == 1:
	x.reverse()
	print(''.join(x))
else:
	for i in range(0, len(l) - 1):
		t = abs(l[i] - l[i + 1])
		C = x[l[i] - t:l[i]]
		if i % 2 == 0:
			C.reverse()
			S.append(''.join(C))
		else:
			D.append(''.join(C))
	if len(l) % 2 == 0:
		C = x[0:l[len(l) - 1]]
		D.append(''.join(C))
	else:
		C = x[0:l[len(l) - 1]]
		C.reverse()
		S.append(''.join(C))
	F = ''.join(S)
	D.reverse()
	G = ''.join(D)
	print(F + G)


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())
t = input()
for i in range(2, n + 1):
	if n % i == 0:
		t = t[i - 1::-1] + t[i:]
print(t)


def RevEncryption():
	length = int(input(''))
	string = [i for i in input('')]
	divisors = []
	for i in range(1, length + 1):
		if length % i == 0:
			divisors.append(i)
	for i in range(len(divisors)):
		d = divisors[i]
		substring = string[0:d]
		substring.reverse()
		string[0:d] = [i for i in substring]
	for i in string:
		print(i, end='')
RevEncryption()


n = int(input())
s = input().strip()
for i in filter(lambda x: n % x == 0, range(2, n + 1)):
	s = s[i - 1::-1] + s[i:]
print(s)


import sys
input = sys.stdin.readline
from collections import *
n = int(input())
s = list(input()[:-1])
for i in range(1, n + 1):
	if n % i == 0:
		for j in range(i // 2):
			(s[j], s[i - 1 - j]) = (s[i - 1 - j], s[j])
print(''.join(s))


n = int(input())
s = input()
div = 1
while div <= n:
	if n % div == 0:
		tmp = s[:div]
		s = tmp[::-1] + s[div:]
	div += 1
print(s)


while True:
	try:
		n = int(input())
		s = input()
		for i in range(n):
			if n % (i + 1) == 0:
				s = s[:i + 1][::-1] + s[i + 1:n]
		print(s)
	except:
		break


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


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


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


from copy import deepcopy
n = int(input())
arr = list(input())
d = []
for i in range(2, n + 1):
	if n % i == 0:
		d.append(i)
for i in d:
	for j in range(i // 2):
		(arr[j], arr[i - j - 1]) = (arr[i - j - 1], arr[j])
print(''.join(arr))


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


n = int(input())
s = str(input())
q = [x for x in s]
for i in range(1, n):
	if n % i == 0:
		for j in range(i // 2):
			(q[j], q[i - j - 1]) = (q[i - j - 1], q[j])
print(''.join(q[::-1]))


n = int(input())
a = input()
from math import *
div = []
for i in range(1, int(sqrt(n)) + 1):
	if n % i == 0:
		if n // i == i:
			div.append(i)
		else:
			div.append(i)
			div.append(n // i)
a = list(a)
div.sort()
for i in div:
	a = a[:i][::-1] + a[i:]
print(''.join(a))


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


import math

def getDivisors(n):
	div = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				div.append(i)
			else:
				div.append(i)
				div.append(n // i)
		i = i + 1
	return div
n = int(input())
t = input()
div = getDivisors(n)
div.remove(1)
div.sort()
for i in range(len(div)):
	rev = t[0:div[i]]
	rev = rev[::-1]
	t = rev + t[div[i]:]
print(t)


n = int(input())
s = input()
a = []
for i in s:
	a.append(i)
div = []
for i in range(1, n + 1):
	if n % i == 0:
		div.append(i)
for i in div:
	b = a[0:i]
	b.reverse()
	b = b + a[i:]
	a = []
	for j in b:
		a.append(j)
ans = ''
for i in a:
	ans += i
print(ans)


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


import math
import random
import time
import heapq

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

def getTransIntList(n):
	first = getIntList()
	m = len(first)
	result = [[0] * n for _ in range(m)]
	for i in range(m):
		result[i][0] = first[i]
	for j in range(1, n):
		curr = getIntList()
		for i in range(m):
			result[i][j] = curr[i]
	return result
n = int(input())
t = input()
for d in range(1, n + 1):
	if n % d == 0:
		t1 = t[:d]
		t = t1[::-1] + t[d:]
print(t)


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


n = int(input())
s = input()
fct = set()
for i in range(1, n + 1):
	if n % i == 0:
		fct.add(i)
x = sorted(list(fct))
for i in x:
	s = s[:i][::-1] + s[i:]
print(s)


n = int(input())
s = str(input())
k = 2
div = set()
while k * k <= n:
	if n % k == 0:
		div.add(k)
		div.add(n // k)
	k += 1
div = list(div)
div.sort()
for i in range(len(div)):
	s = s[div[i] - 1::-1] + s[div[i]:len(s)]
print(s[::-1])


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


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


n = int(input())
a = input()
for i in range(1, n + 1):
	if n % i:
		continue
	t = []
	for j in range(i):
		t.append(a[i - j - 1])
	for j in range(i, n):
		t.append(a[j])
	a = t
for i in range(n):
	print(a[i], end='')


import math

def decrypt(s, l):
	return s[0:l][::-1] + s[l:]

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
n = int(input())
s = input()
if n == 1:
	print(s)
else:
	div = list(divisorGenerator(n))
	div.remove(1)
	for i in div:
		s = decrypt(s, i)
	print(s)


(n, a) = (int(input()), list(input()))
x = [i for i in range(2, n + 1) if n % i == 0]
for i in x:
	a = list(reversed(a[:i])) + a[i:]
print(*a, sep='')


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 = int(input())
s = list(input())
z = []
for i in range(1, n // 2 + 1):
	if n % i == 0:
		z.append(i - 1)
z.append(n - 1)
for i in z:
	s[0:i + 1] = reversed(s[0:i + 1])
for i in range(n):
	a = ''.join(s)
print(a)


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 n == 2:
	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:]
		L = l1 + l2
		s = ''.join(L)
	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 = input()
a = []
for i in range(1, n + 1):
	if n % i == 0:
		a.append(i)
for i in a:
	ans = ''
	for j in range(0, i):
		ans += s[i - j - 1]
	for j in range(i, len(s)):
		ans += s[j]
	s = ans
print(s)


import sys
import math
get_string = lambda : sys.stdin.readline().strip()
get_int_list = lambda : list(map(int, sys.stdin.readline().strip().split()))
get_intList_from_str = lambda : list(map(int, list(sys.stdin.readline().strip())))
get_charList_from_str = lambda : list(sys.stdin.readline().strip())
get_char_list = lambda : sys.stdin.readline().strip().split()
get_int = lambda : int(sys.stdin.readline())
pt = lambda x: sys.stdout.write(str(x))

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())
div = []
for i in range(1, int(n ** (1 / 2)) + 1):
	if n % i == 0:
		if i * i == n:
			div.append(i)
		else:
			div.append(i)
			div.append(n // i)
s = input()
div = sorted(div)
for i in div:
	k1 = s[:i]
	k2 = s[i:]
	k1 = k1[::-1]
	s = k1 + k2
print(s)


def newstring(s, d):
	start = 0
	end = d - 1
	s = list(s)
	while start <= end:
		(s[start], s[end]) = (s[end], s[start])
		start += 1
		end -= 1
	return ''.join(s)
n = int(input())
s = input()
if n in [1, 2]:
	print(s[::-1])
else:
	for d in range(1, n + 1):
		if n % d == 0:
			s = newstring(s, d)
	print(s)


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


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


n = int(input())
s = input()
d = list(s)
k = ''
for i in range(1, n + 1):
	if n % i == 0:
		for j in range(0, i // 2):
			k = d[j]
			d[j] = d[i - 1 - j]
			d[i - 1 - j] = k
for i in range(0, n):
	print(d[i], end='')


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


import sys
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(int(n / i))
	for divisor in reversed(large_divisors):
		yield divisor
n = int(input())
stra = str(input())
lista = list(divisorGenerator(n))
for i in range(1, len(lista)):
	strb = stra[0:lista[i]]
	strb = strb[::-1]
	stra = strb + stra[lista[i]:]
print(stra)


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


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


n = int(input())
str1 = input()
list1 = list(str1)
for i in range(2, n + 1):
	if n % i == 0:
		list2 = list1[:i]
		list2.reverse()
		for j in range(i, n):
			list2.append(list1[j])
		list1 = list2[:]
print(''.join(list1))


n = int(input())
a = input()
b = []
c = []
for i in a:
	c.append(i)
for i in range(1, n + 1):
	if n % i == 0:
		b.append(i)
for i in b:
	c = c[:i][::-1] + c[i:]
	string = ''.join(c)
print(string)


def d(n):
	z = [1]
	for i in range(2, n // 2 + 1):
		if n % i == 0:
			z.append(i)
	z.append(n)
	return z
n = int(input())
t = list(input())
z = d(n)
for i in z:
	k = t[:i]
	k.reverse()
	t = k + t[i:]
for i in range(n):
	print(t[i], end='')


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


n = int(input())
l = list(input())
for i in range(1, n + 1):
	if n % i == 0:
		li = l[:i]
		lp = l[i:]
		lc = []
		while len(li) != 0:
			lc.append(li.pop())
		l = lc + lp
print(*l, sep='')


length = int(input())
istr = str(input())
div = []
i = 1
while i <= length:
	if length % i == 0:
		div.append(i)
	i += 1
starti = 0
for d in div:
	s1 = istr[0:d]
	s3 = s1[::-1]
	s2 = istr[d:]
	istr = s3 + s2
print(istr)


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)


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


t = int(input())
a = str(input())
b = []
for i in range(2, t + 1):
	if t % i == 0:
		b.append(i)
c = []
for i in a:
	c.append(i)
for i in range(0, len(b)):
	d = c[0:b[i]]
	d = d[::-1]
	c[0:b[i]] = d
ans = c[0]
for i in range(1, len(c)):
	ans = ans + c[i]
print(ans)


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


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


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


z = input()
a = input()
a = list(a)
for i in range(2, int(len(a) / 2) + 1):
	if len(a) % i == 0:
		for j in range(int(i / 2)):
			(a[j], a[i - j - 1]) = (a[i - j - 1], a[j])
a = reversed(a)
print(''.join(a))


n = int(input())
a = list(input())
for i in range(2, n + 1):
	if n % i == 0 or i == n:
		b = a[0:i].copy()
		b.reverse()
		a = b.copy() + a[i:].copy()
		last = i
print(''.join(a))


import collections
from functools import cmp_to_key
import math
import sys

def getIntList():
	return list(map(int, input().split()))
import bisect
try:
	import numpy
	dprint = print
	dprint('debug mode')
except ModuleNotFoundError:

	def dprint(*args, **kwargs):
		pass

def makePair(z):
	return [(z[i], z[i + 1]) for i in range(0, len(z), 2)]
(N,) = getIntList()
s = input()
s = list(s)
for d in range(2, N + 1):
	if N % d != 0:
		continue
	dprint(d)
	x = s[:d]
	x.reverse()
	s[:d] = x
	dprint(s)
print(''.join(s))


a = int(input())
b = input()
f = []
for i in range(1, a + 1):
	if a % i == 0:
		f.append(i)
f.sort()

def aa(a, b):
	g = ''
	for i in range(a, len(b)):
		g = g + b[i]
	e = []
	for i in range(a):
		e.append(b[i])
	e.reverse()
	t = ''
	for i in e:
		t = t + i
	t = t + g
	return t
for i in f:
	b = aa(i, b)
print(b)


_ = int(input())
s = input().strip()
n = len(s)

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


k = int(input())
s = list(input())
n = k
a = []
for i in range(1, n + 1):
	if n % i == 0:
		for l in range(0, i // 2):
			temp = s[l]
			s[l] = s[i - 1 - l]
			s[i - 1 - l] = temp
print(''.join(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()


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


import time
n = int(input())
t = input()
start = time.time()
for i in range(2, n + 1):
	if n % i == 0:
		t = t[i - 1::-1] + t[i:n]
print(t)
finish = time.time()


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


def de(a):
	d = []
	r = 2
	while r * r < a:
		if a % r == 0:
			d.append(r)
			d.append(a // r)
		r += 1
	if r * r == a:
		d.append(r)
	d.sort()
	d.append(a)
	return d
a = int(input())
b = input()
b2 = []
for i in range(a):
	b2.append(i)
d = de(a)
for i in range(len(d)):
	for j in range(d[i] // 2):
		w = b2[j]
		b2[j] = b2[d[i] - j - 1]
		b2[d[i] - j - 1] = w
for i in range(a):
	print(b[b2[i]], end='')


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


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


t = int(input())
s = list(input())
k = []
for j in range(1, t + 1):
	if t % j == 0:
		k.append(j)
for j in k:
	d = s[:j].copy()
	d = d[-1::-1]
	s = d + s[j:].copy()
print(''.join(s))


factors = [[1], [1, 2], [1, 3], [1, 2, 4], [1, 5], [1, 2, 3, 6], [1, 7], [1, 2, 4, 8], [1, 3, 9], [1, 2, 5, 10], [1, 11], [1, 2, 3, 4, 6, 12], [1, 13], [1, 2, 7, 14], [1, 3, 5, 15], [1, 2, 4, 8, 16], [1, 17], [1, 2, 3, 6, 9, 18], [1, 19], [1, 2, 4, 5, 10, 20], [1, 3, 7, 21], [1, 2, 11, 22], [1, 23], [1, 2, 3, 4, 6, 8, 12, 24], [1, 5, 25], [1, 2, 13, 26], [1, 3, 9, 27], [1, 2, 4, 7, 14, 28], [1, 29], [1, 2, 3, 5, 6, 10, 15, 30], [1, 31], [1, 2, 4, 8, 16, 32], [1, 3, 11, 33], [1, 2, 17, 34], [1, 5, 7, 35], [1, 2, 3, 4, 6, 9, 12, 18, 36], [1, 37], [1, 2, 19, 38], [1, 3, 13, 39], [1, 2, 4, 5, 8, 10, 20, 40], [1, 41], [1, 2, 3, 6, 7, 14, 21, 42], [1, 43], [1, 2, 4, 11, 22, 44], [1, 3, 5, 9, 15, 45], [1, 2, 23, 46], [1, 47], [1, 2, 3, 4, 6, 8, 12, 16, 24, 48], [1, 7, 49], [1, 2, 5, 10, 25, 50], [1, 3, 17, 51], [1, 2, 4, 13, 26, 52], [1, 53], [1, 2, 3, 6, 9, 18, 27, 54], [1, 5, 11, 55], [1, 2, 4, 7, 8, 14, 28, 56], [1, 3, 19, 57], [1, 2, 29, 58], [1, 59], [1, 2, 3, 4, 5, 6, 10, 12, 15, 20, 30, 60], [1, 61], [1, 2, 31, 62], [1, 3, 7, 9, 21, 63], [1, 2, 4, 8, 16, 32, 64], [1, 5, 13, 65], [1, 2, 3, 6, 11, 22, 33, 66], [1, 67], [1, 2, 4, 17, 34, 68], [1, 3, 23, 69], [1, 2, 5, 7, 10, 14, 35, 70], [1, 71], [1, 2, 3, 4, 6, 8, 9, 12, 18, 24, 36, 72], [1, 73], [1, 2, 37, 74], [1, 3, 5, 15, 25, 75], [1, 2, 4, 19, 38, 76], [1, 7, 11, 77], [1, 2, 3, 6, 13, 26, 39, 78], [1, 79], [1, 2, 4, 5, 8, 10, 16, 20, 40, 80], [1, 3, 9, 27, 81], [1, 2, 41, 82], [1, 83], [1, 2, 3, 4, 6, 7, 12, 14, 21, 28, 42, 84], [1, 5, 17, 85], [1, 2, 43, 86], [1, 3, 29, 87], [1, 2, 4, 8, 11, 22, 44, 88], [1, 89], [1, 2, 3, 5, 6, 9, 10, 15, 18, 30, 45, 90], [1, 7, 13, 91], [1, 2, 4, 23, 46, 92], [1, 3, 31, 93], [1, 2, 47, 94], [1, 5, 19, 95], [1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 96], [1, 97], [1, 2, 7, 14, 49, 98], [1, 3, 9, 11, 33, 99], [1, 2, 4, 5, 10, 20, 25, 50, 100]]
n = int(input())
s = input()
factor = factors[n - 1]
for num in factor:
	s = s[num - 1::-1] + s[num:]
print(s)


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


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


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


n = int(input())
a = input()
d = 1
r = a[:d]
a = r[::-1] + a[d:]
while d != n:
	d += 1
	while n % d != 0:
		d += 1
	r = a[:d]
	a = r[::-1] + a[d:]
print(a)


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[0:item][::-1] + l[item:]
print(l)


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]
if n ** 0.5 == int(n ** 0.5):
	divisors.pop()
divisors.sort()
for i in divisors:
	s[:i] = s[:i][::-1]
print(''.join(s))


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


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


import math
x = int(input())
y = input()
l = []
t = int(math.sqrt(x))
for i in range(1, t + 1):
	if x % i == 0:
		if i != x // i:
			l.append(i)
			l.append(x // i)
		else:
			l.append(i)
l.sort()
for i in l:
	w = list(y[:i])
	w.reverse()
	y = ''.join(w) + y[i:]
print(y)


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


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

def get_divisors(n):
	i = 2
	original = n
	res = []
	for i in range(2, n + 1):
		if n % i == 0:
			res.append(i)
	return res
divisors = get_divisors(n)
l = list(s)
for k in divisors:
	i = 0
	j = k - 1
	while i < j:
		(l[i], l[j]) = (l[j], l[i])
		i += 1
		j -= 1
print(''.join(l))


n = int(input())
ch = input()

def reverse(ch):
	che = ''
	for i in range(len(ch) - 1, -1, -1):
		che += ch[i]
	return che
l = [i for i in range(2, n + 1) if n % i == 0]
for e in l:
	che = reverse(ch[:e])
	ch1 = che + ch[e:]
	(ch, ch1) = (ch1, '')
print(ch)


a = int(input())
b = input()
for x in range(a):
	if a % (x + 1) == 0:
		b = b[x::-1] + b[x + 1:]
print(b)


def solve(string, n):
	for i in range(2, n + 1):
		if n % i == 0:
			string = string[0:i][::-1] + string[i:]
	return ''.join(string)
n = int(input())
string = input()
print(solve(string, n))


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 = input()
a = []
for i in range(n):
	a.append(t[i])
for i in range(1, n + 1):
	if n % i == 0:
		for j in range(i // 2):
			(a[j], a[i - 1 - j]) = (a[i - 1 - j], a[j])
for i in range(len(a)):
	print(a[i], end='')


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


from functools import reduce
n = input().strip().split()
n = int(n[0])
j = input().strip()
x = sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(pow(n, 0.5) + 1)) if n % i == 0))))
for a in x:
	j = ''.join(reversed(j[0:a])) + j[a:n]
print(j)


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


from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(pow(n, 0.5) + 1)) if n % i == 0)))
n = int(input())
word = input()
fact = sorted(list(factors(len(word))))
for i in range(len(fact)):
	d = fact[i]
	word = word[0:d][::-1] + word[d:]
print(word)


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


import math
n = int(input())
s = input()

def printDivisors(n):
	x = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				x.append(int(i))
			else:
				x.append(int(i))
				x.append(int(n / i))
		i = i + 1
	return sorted(x)
temp = printDivisors(n)
for i in temp:
	x = s[0:i][::-1]
	y = s[i:n]
	s = x + y
print(s)


import math
getInputList = lambda : list(input().split())
getInputIntList = lambda : list(map(int, input().split()))
n = int(input())
s = input()
for i in range(n):
	if n % (i + 1) == 0:
		s = s[:i + 1][::-1] + s[i + 1:]
print(s)


import sys
import math
import bisect
import itertools

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


import sys

def mp():
	return list(map(int, input().split()))
if 0:
	f = open('input.txt', 'r')
	input = f.readline

def _main():
	n = int(input())
	a = list(input())
	for i in range(1, n):
		if n % (i + 1) == 0:
			a = a[i::-1] + a[i + 1:]
	print(*a, sep='')
_main()


(x, y) = (int(input()), str(input()))
for i in range(x // 2 + 1, 1, -1):
	if x % i == 0:
		y = y[x // i - 1::-1] + y[x // i:x]
print(y[::-1])


def main():
	n = int(input())
	string = input()
	divs = []
	for i in range(1, n + 1):
		if n % i == 0:
			divs.append(i)
	for d in divs:
		string = ''.join(reversed(string[:d])) + string[d:]
	print(string)
main()


from sys import stdin

def solve(tc):
	n = int(stdin.readline().strip())
	s = stdin.readline().strip()
	li = list()
	for i in range(1, n + 1):
		if n % i == 0:
			li.append(i)
	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


a = int(input())
s = list(input())
b = []
for i in range(a, 1, -1):
	if a % i == 0:
		b.append(i)
for i in range(len(b) - 1, -1, -1):
	s[0:b[i]] = reversed(s[0:b[i]])
s = ''.join(s)
print(s)


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


import math

def divs(n):
	divis = []
	divis_temp = []
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			divis.append(i)
	for i in divis:
		k = int(n / i)
		if k == i:
			continue
		divis_temp.append(int(n / i))
	divis.extend(divis_temp)
	divis.sort()
	return divis
ip = [int(x) for x in input().split()]
st = input()
stip = list(st)
divis = divs(ip[0])
for i in range(len(divis)):
	slic = slice(divis[i])
	temp = stip[slic]
	temp.reverse()
	stip[slic] = temp
print(''.join((str(e) for e in stip)))


n = int(input())
s = input()
factors = [x for x in range(1, n + 1) if n % x == 0]
for factor in factors:
	part1 = s[:factor]
	part1 = part1[::-1]
	part2 = s[factor:]
	s = part1 + part2
print(s)


n = int(input())
a = input()
a = '0' + a
b = [''] * (n + 1)
resalt = ''
for i in range(0, n + 1):
	b[i] = a[i]
for i in range(2, n + 1):
	if n % i == 0:
		b[1:i + 1] = b[i:0:-1]
for i in range(n + 1):
	resalt += b[i]
for j in range(1, n + 1):
	print(resalt[j], end='')


def divi(n):
	l = []
	for i in range(1, n + 1):
		if n % i == 0:
			l.append(i)
	return l
n = int(input())
s = input()
sl = [i for i in s]
l = divi(n)
for i in l:
	x = sl[:i]
	sl[:i] = x[::-1]
ans = ''
for i in sl:
	ans += i
print(ans)


n = int(input())
s = input()
v = []
i = 2
while i <= n:
	if n % i == 0:
		v.append(i)
	i += 1
for e in v:
	s = s[0:e][::-1] + s[e:]
print(s)


INF = 1 << 60

def make_divisors(n):
	(lower_divisors, upper_divisors) = ([], [])
	i = 1
	while i * i <= n:
		if n % i == 0:
			lower_divisors.append(i)
			if i != n // i:
				upper_divisors.append(n // i)
		i += 1
	return lower_divisors + upper_divisors[::-1]
n = int(input())
t = input()
d = make_divisors(n)
ans = t
for i in d:
	ans = ans[:i][::-1] + ans[i:]
print(ans)


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


def next_divisor(n, x):
	while x <= n:
		if n % x == 0:
			yield x
		x += 1

def solve(n, t):
	x = 1
	s = t
	nd = next_divisor(n, 1)
	while True:
		try:
			x = nd.__next__()
			s = ''.join(list(reversed(s[0:x]))) + s[x:]
		except:
			break
	return ''.join(s)

def main():
	n = int(input())
	t = input()
	print(solve(n, t))
main()


n = int(input())
l = list(input())
g = []
for i in range(2, n + 1):
	if n % i == 0:
		g.append(i)
for j in g:
	c = l[:j]
	c = c[::-1]
	l[:j] = c
print(''.join(l))


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


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


def divisors(x):
	res = []
	for i in range(2, n + 1):
		if x % i == 0:
			res.append(i)
	return res
n = int(input())
s = input()
divs = divisors(n)
for i in divs:
	s = s[i - 1::-1] + s[i:]
print(s)


n = int(input())
s = input().rstrip()
strs = list(s[:])
divs = []
for i in range(2, n + 1):
	if n % i == 0:
		divs.append(i)
while 0 < len(divs):
	tmp = divs.pop(0)
	work = strs[:tmp][::-1]
	for j in range(tmp):
		strs[j] = work[j]
print(''.join(strs))


length = int(input())
s = input()
ll = length
div = []
while ll:
	if length % ll == 0:
		div.insert(0, ll)
	ll = ll - 1
for i in div:
	s = s[0:i][::-1] + s[i:]
print(s)


def reverse_string(string, d):
	to_reverse = string[:d]
	unchanged = string[d:]
	to_reverse = to_reverse[::-1]
	string = to_reverse + unchanged
	return string
n = int(input())
t = input()
for i in range(1, n + 1):
	if n % i == 0:
		t = reverse_string(t, i)
print(t)


from functools import reduce

def factors():
	n = int(input())
	s = list(input())
	f = sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(pow(n, 0.5) + 1)) if n % i == 0))))
	for d in f:
		s[:d] = s[:d][::-1]
	print(''.join(s))
factors()


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

def calculator(d, s):
	t = ''
	t = s[:d]
	return t[::-1] + s[d:]
obj = devisors(int(input()))
s = input()
for d in obj:
	s = calculator(d, s)
print(s)


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


a = int(input())
b = input()
aa = []
for i in range(1, int(a) + 1):
	if a % i == 0:
		aa.append(i)
for i in range(len(aa)):
	j = aa[i]
	b = ''.join(reversed(b[:j])) + b[j:]
print(b)


import math

def div(n):
	l = []
	lim = math.floor(math.sqrt(n))
	for i in range(1, lim + 1):
		if n % i == 0:
			l.append(i)
			if n // i != i:
				l.append(n // i)
	return l
n = int(input())
s = input()
l = div(n)
l.sort()
for j in l:
	a = s[0:j][::-1] + s[j:]
	s = a
print(s)


n = int(input())
t = input()
t2 = list(t)
divisors = []
i = 1
while i <= n:
	if n % i == 0:
		divisors.append(i - 1)
	i += 1
for i in range(len(divisors) - 1, -1, -2):
	for k in range(divisors[i], divisors[i - 1], -1):
		print(t[k], end='')
		del t2[k]
for c in t2:
	print(c, end='')


n = int(input())
s = input()
lst = []
for i in s:
	lst.append(i)
for i in range(1, n + 1):
	if n % i == 0:
		rev = lst[0:i]
		rev.reverse()
		lst[0:i] = rev
for i in lst:
	print(i, end='')


def factors(n):
	l = []
	for i in range(2, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			l.append(i)
			if i * i != n:
				l.append(int(n / i))
	l.sort()
	return l
n = int(input())
if n >= 1 and n <= 100:
	t = input().rstrip().lower()
	if len(t) == n:
		f = factors(n)
		for i in f:
			s = list(t[:i])
			s.reverse()
			e = t[i:]
			s1 = ''
			for x in s:
				s1 = s1 + x
			t = s1 + e
		t = t[::-1]
		print(t)


def reverse(a, b, st):
	snew = ''
	for m in range(b, a - 1, -1):
		snew += st[m]
	snew = st[:a] + snew + st[b + 1:]
	return snew
n = int(input())
st = input()
for i in range(2, n + 1):
	if n % i == 0:
		st = reverse(0, i - 1, st)
print(st)


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

def rev(x, t):
	s = ''
	for i in range(x - 1, -1, -1):
		s += t[i]
	s += t[x:]
	return s
for i in range(1, n + 1):
	if n % i == 0:
		t = rev(i, t)
print(t)


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()
list = []
for x in range(1, n + 1):
	if n % x == 0:
		list.append(x)
for i in list:
	s1 = s[:i]
	s = s1[::-1] + s[i:]
print(s)


import math

def f(n):
	i = 1
	a = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				a.append(i)
			else:
				a.append(i)
				a.append(n // i)
		i = i + 1
	return sorted(a)
n = int(input())
a = f(n)
a.remove(1)
s = input()
k = ''
for i in a:
	k = ''.join(reversed(s[0:i])) + s[i:]
	s = k
print(s)


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


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


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
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
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):
	(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))
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
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

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')

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()


import math

def reverse(s, d):
	s1 = s[0:d]
	s1 = s1[::-1]
	return s1 + s[d:]

def divisors_gen(n):
	result = set()
	for i in range(1, int(n ** 0.5) + 1):
		(div, mod) = divmod(n, i)
		if mod == 0:
			result |= {i, div}
	return sorted(result)

def f(s):
	decrypted = s
	divisors = list(divisors_gen(len(s)))
	for i in divisors:
		decrypted = reverse(decrypted, i)
	return decrypted
n = int(input())
s = input()
res = f(s)
print(res)


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


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


n = int(input())
s = input()
for i in range(n):
	if n % (i + 1) == 0:
		list1 = list(s)
		for j in range(0, i // 2 + 1):
			t = list1[j]
			list1[j] = list1[i - j]
			list1[i - j] = t
		s = ''.join(list1)
print(s)


def dividors(n):
	tab = list()
	for i in range(1, n + 1):
		if n % i == 0:
			tab.append(i)
	return tab
n = int(input())
crypt = str(input())
cryp = ['1'] * len(crypt)
for i in range(len(crypt)):
	cryp[i] = crypt[i]
divs = dividors(n)
for div in divs:
	if div > 1:
		cryp[0:div] = reversed(cryp[0:div])
res = ''.join(cryp)
print(res)


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


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(''))
for i in range(1, n + 1):
	if n % i == 0:
		bodla = ''
		for j in range(i - 1, -1, -1):
			bodla += s[j]
		for j in range(i):
			s[j] = bodla[j]
print(''.join(s))


n = int(input())
a = input()
div = []
t = []
for i in range(1, int(n ** (1 / 2) + 1)):
	if n % i == 0:
		if n / i == i:
			div.append(i)
		else:
			div.append(i)
			t.append(n / i)
t = list(map(int, t))
div += t[-1::-1]
t = ''
for i in div:
	a = a[i - 1::-1] + a[i:]
print(a)


from functools import reduce

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(pow(n, 0.5) + 1)) if n % i == 0)))
n = int(input())
s = list(str(input()))
k = list(factors(n))
k.sort()
for t in range(1, len(k) - 1):
	p = s[:k[t]]
	s[:k[t]] = p[::-1]
print(''.join(s[::-1]))


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


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


t = int(input())
s = input()
x = s
for i in range(t):
	if t % (i + 1) == 0:
		x = s[:i + 1]
		x = x[::-1]
		s = x + s[i + 1:]
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)
s = input()
for i in divar:
	retain = s[i:]
	reverse = s[:i]
	reverse = reverse[::-1]
	s = reverse + retain
print(s)


n = int(input())
s = input()
i = 1
while i <= n:
	a = s[0:i][::-1]
	b = s[i:]
	s = a + b
	i += 1
	while n % i != 0 and i <= n:
		i += 1
print(s)


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


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


size = int(input())
word = list(input())
divisors = []

def inverter(n):
	for i in range(n // 2):
		(word[i], word[n - i - 1]) = (word[n - i - 1], word[i])
for i in range(2, size + 1):
	if size % i == 0:
		divisors.append(i)
for divisor in divisors:
	inverter(divisor)
print(*word, sep='')


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)


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


import sys, math, collections
from collections import defaultdict

def file():
	sys.stdin = open('input.py', 'r')
	sys.stdout = open('output.py', 'w')

def get_array():
	l = list(map(int, input().split()))
	return l

def get_2_ints():
	(a, b) = map(int, input().split())
	return (a, b)

def get_3_ints():
	(a, b, c) = map(int, input().split())
	return (a, b, c)

def sod(n):
	(n, c) = (str(n), 0)
	for i in n:
		c += int(i)
	return c

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

def getFloor(A, x):
	(left, right) = (0, len(A) - 1)
	floor = -1
	while left <= right:
		mid = (left + right) // 2
		if A[mid] == x:
			return A[mid]
		elif x < A[mid]:
			right = mid - 1
		else:
			floor = A[mid]
			left = mid + 1
	return floor

def floorSqrt(x):
	if x == 0 or x == 1:
		return x
	start = 1
	end = x
	while start <= end:
		mid = (start + end) // 2
		if mid * mid == x:
			return mid
		if mid * mid < x:
			start = mid + 1
			ans = mid
		else:
			end = mid - 1
	return ans

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


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


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


a = int(input())
c = input()
t = False
s = ''
S = ''
for i in range(a - 1, -1, -1):
	if a % (i + 1) == 0:
		t = not t
	if t:
		s += c[i]
	else:
		S = c[i] + S
print(s + S)


n = int(input())
s = str(input())
i = 1
while i <= n:
	if n % i == 0:
		k = s[:i]
		l = ''
		for j in range(i - 1, -1, -1):
			l = l + k[j]
		s = l + s[i:]
	i += 1
print(s)


n = int(input())
a = input()
for x in range(2, n + 1):
	if n % x < 1:
		a = a[x - 1::-1] + a[x:]
print(a)


def factorize(n):
	factors = []
	for p in range(1, n + 1):
		if n % p == 0:
			factors.append(p)
	return factors
n = int(input())
s = input()
for i in factorize(n):
	s = s[i - 1::-1] + s[i:]
	print(s[0:i:-1])
print(s)


n = int(input())
s = input()
d = []

def rot(s):
	s1 = ''
	for i in range(len(s) - 1, -1, -1):
		s1 += s[i]
	return s1
for i in range(1, n + 1):
	if n % i == 0:
		d.append(i)
for i in d:
	s = rot(s[0:i]) + s[i:n]
print(s)


n = int(input())
s = list(input())
for x in range(1, n + 1):
	if n % x == 0:
		i = 0
		j = x - 1
		while i <= j - 1:
			(s[i], s[j]) = (s[j], s[i])
			i += 1
			j -= 1
for x in s:
	print(x, end='')


n = int(input())
s = input()
s1 = ''
list = []
h = 0
for i in range(1, n + 1):
	if n % i == 0:
		list.append(i)
for i in range(len(list) - 1, -1, -1):
	h = int(n / list[i])
	s1 = s[:h]
	s1 = s1[::-1]
	s = s1 + s[int(n / list[i]):]
print(s)


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


import math
import sys
input = sys.stdin.readline
n = int(input())
s = list(input())
for d in range(2, n + 1):
	if n % d != 0:
		continue
	(l, r) = (0, d - 1)
	for _ in range(d // 2):
		(s[l], s[r]) = (s[r], s[l])
		(l, r) = (l + 1, r - 1)
print(''.join(s))


def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	return divisors
n = int(input())
s = input()
div = make_divisors(n)
div.sort()
for i in div:
	if i == 1:
		continue
	s = ''.join(list(reversed(s[0:i]))) + s[i:]
print(s)


n = int(input())
s = list(input())
ls = [i for i in range(1, n + 1) if n % i == 0]
for i in ls:
	t = s[:i]
	t.reverse()
	for j in range(i):
		s[j] = t[j]
for i in s:
	print(i, end='')


import math
n = int(input().strip())
s = input().strip()
div = []
_n = int(math.sqrt(n))
for i in range(2, _n + 1):
	if n % i == 0:
		div.append(i)
		if i * i != n:
			div.append(n // i)
div.append(n)
div.sort()
for d in div:
	pa = s[:d]
	pb = s[d:]
	s = pa[::-1] + pb
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)


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

def make_divisor_list(num):
	if num < 1:
		return []
	elif num == 1:
		return [1]
	else:
		divisor_list = []
		divisor_list.append(1)
		for i in range(2, num // 2 + 1):
			if num % i == 0:
				divisor_list.append(i)
		divisor_list.append(num)
		return divisor_list
d = make_divisor_list(len(s))
for i in sorted(d):
	t = s[:i]
	s = t[::-1] + s[i:]
print(s)


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


import math

def printDivisors(n):
	div = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				div.append(i)
			else:
				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])
	if stop - start > 1:
		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)
strr = ''
for i in st:
	strr = strr + i
print(strr)


def main():
	n = int(input())
	t = input()
	divs = []
	if n ** 0.5 % 1 == 0:
		divs.append(int(n ** 0.5))
	for i in range(1, int(n ** 0.5) + (n ** 0.5 % 1 != 0)):
		if n % i == 0:
			divs.append(i)
			divs.append(n // i)
	divs.sort()
	for i in divs:
		t = t[i - 1::-1] + t[i:]
	print(t)
	return 0
main()


n = int(input())
m = input()
a = list()
for i in range(n):
	if n % (i + 1) == 0:
		a.append(i)
for k in a:
	m1 = m[:k + 1]
	m1 = m1[::-1]
	m2 = m[k + 1:]
	m = m1 + m2
print(m)


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)
sol = ''.join(str)
print(sol)


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


def inverte(str, n):
	aux = str[n - 1::-1]
	str = str[n:len(str)]
	str = aux + str
	return str
tam = int(input())
string = input()
lista = [0 for i in range(tam)]
cont = 0
for i in range(1, tam + 1):
	if tam % i == 0:
		lista[cont] = i
		cont = cont + 1
n0 = lista.count(0)
for i in range(0, n0):
	lista.remove(0)
for i in range(1, len(lista)):
	string = inverte(string, lista[i])
print(string)


import math
x = int(input())
a = list(input())
lol = []
for i in range(1, int(math.sqrt(x)) + 1):
	if x % i == 0:
		if x // i != i:
			lol.append(x // i)
		lol.append(i)
lol.sort()
for i in lol:
	b = a[:i]
	b = b[::-1]
	a = b + a[i:]
print(''.join(a))


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


n = int(input())
L = [i for i in input()]
D = []
for i in range(1, n + 1):
	if n % i == 0:
		D.append(i)
for i in D:
	for j in range((i + 1) // 2):
		(L[j], L[i - 1 - j]) = (L[i - 1 - j], L[j])
for i in L:
	print(i, end='')


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))


n = int(input())
string = input()
string_list = list(string)
division_list = []
for i in range(n):
	if n % (i + 1) == 0:
		division_list.append(i + 1)
division_list.sort()
for division in division_list:
	temp1 = string_list[:division]
	temp2 = string_list[division:]
	temp1 = temp1[::-1]
	string_list = temp1 + temp2
ans = ''.join(string_list)
print(ans)


def main():
	from math import sqrt, floor
	n = int(input())
	encrypted = input()
	divisors = [1]
	for i in range(2, floor(sqrt(n)) + 1):
		if n % i == 0:
			divisors += [i] if i ** 2 == n else [i, n // i]
	if n > 1:
		divisors += [n]
	divisors.sort()
	for d in divisors:
		encrypted = encrypted[:d][::-1] + encrypted[d:]
	print(encrypted)
main()


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


n = int(input())
u = [n]
for i in range(n // 2, 1, -1):
	if n % i == 0:
		u.append(i)
s = list(input())
u.reverse()
for i in u:
	d = s[:i]
	d.reverse()
	s = d + s[i:]
for i in s:
	print(i, end='')


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)


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


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


from math import sqrt

def getDivisor(n):
	div = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			if n // i == i:
				div.append(i)
			else:
				div.append(i)
				div.append(int(n / i))
	return div
length = int(input())
t = input()
div = getDivisor(length)
div.sort()
for i in div:
	t = t[i - 1:0:-1] + t[0] + t[i:]
print(t)


import math
div = []

def Divisors(n):
	i = 1
	while i <= n ** 0.5:
		if n % i == 0:
			if n / i == i:
				(div.append(i),)
			else:
				(div.append(i),)
				(div.append(n // i),)
		i = i + 1
n = int(input())
s = input()
Divisors(n)
div.sort()
for i in div:
	s1 = s[0:i]
	s1 = s1[::-1]
	s = s1 + s[i:]
print(s)


import collections

class Solution:

	def solve(self, n, string):
		stringList = [ch for ch in string]
		for d in range(1, n + 1):
			if n % d == 0:
				stringList[:d] = stringList[:d][::-1]
		return ''.join(stringList)
sol = Solution()
n = int(input().strip())
string = input().strip()
print(sol.solve(n, string))


from math import sqrt
n = int(input())
a = input()
d = []
for i in range(1, int(sqrt(n)) + 1):
	if n % i == 0:
		d.append(i)
		if i != n // i:
			d.append(n // i)
d.sort()
for i in d:
	b = ''
	c = ''
	for j in range(n):
		if j < i:
			b += a[j]
		else:
			c += a[j]
	a = b[::-1] + c
print(a)


import sys
n = int(input())
str = ''
str = sys.stdin.readline()
for i in range(1, n + 1):
	if n % i == 0:
		j = i
		temp = ''
		temp = str[0:i]
		temp = temp[::-1] + str[i:n]
		str = temp
		i = j
print(str)


from __future__ import print_function
from queue import Queue
import sys
import math
import os.path

def log(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

def ni():
	return map(int, input().split())

def nio(offset):
	return map(lambda x: int(x) + offset, input().split())

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

def toString(aList, sep=' '):
	return sep.join((str(x) for x in aList))

def toMapInvertIndex(aList):
	return {k: v for (v, k) in enumerate(aList)}
(n,) = ni()
s = input()
for i in range(1, n + 1):
	if n % i == 0:
		s = s[0:i][::-1] + s[i:n]
print(s)


x = eval(input())
w = str(input())
j = w

def reverse(string):
	string = string[::-1]
	return string
i = 1
l = []
while i <= x:
	if x % i == 0:
		l = l + [i]
	i += 1
i = 0
while i < len(l):
	j = reverse(j[0:l[i]])
	j += w[l[i]:len(w)]
	i += 1
print(j)


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


import sys
input = sys.stdin.readline
n = int(input())
s = list(input().rstrip())
for i in range(1, n + 1):
	if n % i == 0:
		s[:i] = s[:i][::-1]
print(*s, sep='')


def next_divisor(n, x):
	while x <= n:
		if n % x == 0:
			yield x
		x += 1

def solve(n, t):
	s = t
	for x in next_divisor(n, 1):
		s = s[x - 1::-1] + s[x:]
	return s

def main():
	n = int(input())
	t = input()
	print(solve(n, t))
main()


n = int(input())
palabra = input()
for i in range(2, n // 2 + 1):
	if n % i == 0:
		part = palabra[0:i]
		part = part[::-1]
		parte = palabra[i:n]
		palabra = part + parte
palabra = palabra[::-1]
print(palabra, '\n')


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

def findAllDivisors(k):
	lst = []
	for i in range(1, k + 1):
		if k % i == 0:
			lst.append(i)
	return lst
lst = findAllDivisors(n)
for i in range(0, len(lst)):
	newStr = s[0:lst[i]]
	newStr = newStr[::-1]
	newStr1 = s[lst[i]:len(s)]
	s = newStr + newStr1
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)


import sys

def reversed_string(a_string):
	return a_string[::-1]

def decrypt(s):
	n = len(s)
	l = [w for w in range(1, n + 1) if n % w == 0]
	for pos in l:
		s = reversed_string(s[:pos]) + s[pos:]
	return s
n = int(input())
s = input()
decrypt_s = decrypt(s)
print(decrypt_s)


x = int(input())
a = input()
r = ''
t = ''
for i in range(1, x + 1):
	if i == 0:
		continue
	if x % i == 0:
		r = a[i - 1::-1]
		t = a[i:x]
		a = r + t
print(a)


IL = lambda : list(map(int, input().split()))
n = int(input())
s = list(input())
for i in range(1, n + 1):
	if n % i:
		continue
	s[:i] = s[i - 1::-1]
print(''.join(s))


n = int(input())
enc = input()
d = 1
while d <= n:
	if n % d == 0:
		enc = enc[0:0] + enc[0:d][::-1] + enc[d:]
	d += 1
print(enc)


from math import sqrt
n = int(input())
s = input()
x = int(sqrt(n))
l = []
for i in range(1, x + 1):
	if n % i == 0:
		l.append(i)
		if i != n // i:
			l.append(n // i)
l = sorted(l)
s = list(s)
for i in l:
	s[:i] = reversed(s[:i])
print(''.join(s))


def main():
	n = int(input())
	word = input()
	print(solve(n, word))

def solve(n, word):
	divs = divisores(n)
	for d in divs:
		word = word[0:d][::-1] + word[d:]
	return word

def divisores(n):
	lista_div = [1]
	temp_div = 2
	while lista_div[-1] < n:
		if not n % temp_div:
			lista_div.append(temp_div)
		temp_div += 1
	return lista_div
main()


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


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)


from math import sqrt

def main():
	n = int(input())
	t = input()
	d = []
	for i in range(1, n // 2 + 1):
		if n % i == 0:
			d.append(i)
	d.append(n)
	for i in d:
		s_ = t[:i]
		s_ = s_[::-1]
		t = s_ + t[i:]
	print(t)
main()


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


import math
n = int(input())
s = input()
divisors = []
for i in range(1, round(math.sqrt(n)) + 1):
	if n % i == 0:
		if n // i == i:
			divisors.append(i)
		else:
			divisors.append(i)
			divisors.append(n // i)
divisors.sort()
for i in divisors:
	s = s[:i][::-1] + s[i:]
print(s)


n = int(input())
s = input()
for i in range(1, n + 1):
	s = [s[:i][::-1] + s[i:], s][n % i != 0]
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(''.join(string))


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


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


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


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


n = int(input())
t = list(input())
for i in range(2, n + 1):
	if n % i == 0:
		a = 0
		b = i - 1
		while a <= b:
			(t[a], t[b]) = (t[b], t[a])
			a += 1
			b -= 1
print(''.join(t))


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


n = int(input())
ls = list(input())
for i in range(1, n + 1):
	if not n % i:
		copy = ls[:i]
		copy.reverse()
		ls = copy + ls[i:]
print(''.join(ls))


n = int(input())
encrypt = input()
factors = []
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		factors.append(i)
		factors.append(n // i)
factors = list(set(factors))
factors.sort()
for i in factors:
	encrypt = encrypt[0:i][::-1] + encrypt[i:]
print(encrypt)


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


def perevorot(A):
	A = A[::-1]
	return A

def perevorotD(A, d):
	B = A[d:]
	C = A[:d]
	C = perevorot(C)
	return C + B
n = int(input())
K = []
A = input()
for i in range(1, 101):
	if n % i == 0:
		K.append(i)
for i in K:
	A = perevorotD(A, i)
print(A)


n = int(input())
s = input()
x = []
y = []
for i in range(0, n):
	x.append(s[i])
for i in range(1, n + 1):
	if n % i == 0:
		y = x[0:i]
		y.reverse()
		for k in range(0, len(y)):
			x[k] = y[k]
	else:
		continue
for i in range(0, n):
	print(x[i], end='')


n = int(input())
string = str(input())
arr = []
for j in range(2, n + 1, +1):
	if n % j == 0:
		arr.append(j)

def reverse(string, l, h):
	string = list(string)
	while l < h:
		temp = string[l]
		string[l] = string[h]
		string[h] = temp
		l = l + 1
		h = h - 1
	return ''.join(string)
for i in range(len(arr)):
	cur = reverse(string, 0, arr[i] - 1)
	string = cur
print(string)


input()
S = list(input())
for d in range(1, len(S) + 1):
	if len(S) % d == 0:
		S[:d] = S[:d][::-1]
print(''.join(S))


a = int(input())
string = input()
divisors = []
list = []
count = 0
for x in range(a):
	list = list + [string[x]]
for x in range(1, a // 2 + 1):
	if a % x is 0:
		divisors = divisors + [x]
		count = count + 1
divisors = divisors + [a]
i = 1
for t in range(count):
	j = divisors[i] - 1
	for x in range(-(-divisors[i] // 2)):
		k = list[x]
		list[x] = list[j]
		list[j] = k
		j = j - 1
	i = i + 1
for x in list:
	print(x, end='')


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


def getlist(n):
	A = [1, n]
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			if n // i == i:
				A.append(i)
			else:
				A.append(i)
				A.append(n // i)
	A.sort()
	return A
n = int(input())
s = input()
A = getlist(n)
for i in A:
	s = s[:i][::-1] + s[i:]
print(s)


from sys import stdin
from math import *
line = stdin.readline().rstrip().split()
n = int(line[0])
s = stdin.readline().rstrip()
for i in range(n):
	j = i + 1
	if n % j == 0:
		s = s[:j][::-1] + s[j:]
print(s)


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


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


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


n = int(input())
s = list(map(str, input()))
l = []
for i in range(1, n + 1):
	if n % i == 0:
		l.append(i)
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])
j = ''
for i in s:
	j += i
print(j)


a = int(input())
c = input()
i = 1
delit = []
if len(c) != 1:
	while True:
		if a % i == 0:
			delit.append(i)
		i += 1
		if i == len(c):
			break
	for port in range(len(delit)):
		tree = c[:delit[port]]
		tree1 = c[delit[port]:]
		tree = tree[::-1]
		c = tree + tree1
	c = c[::-1]
	print(c)
else:
	print(c)


def divisores(y, x, array):
	if x == 1:
		return array
	elif y % x == 0:
		array.append(int(x))
		return divisores(y, x - 1, array)
	else:
		return divisores(y, x - 1, array)
arrayS = []
n = int(input())
string = input()
arrayS = divisores(n, n, arrayS)
for i in sorted(arrayS):
	string = string[:i][::-1] + string[i:]
print(string)


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


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


n = int(input())
s = str(input())
r = [s]
i = 1
while i <= n:
	if n % i == 0:
		a = i
		p = ''
		while a > 0:
			a -= 1
			p += r[len(r) - 1][a]
		for a in range(i, n):
			p += r[len(r) - 1][a]
		r.append(p)
	i += 1
print(r[len(r) - 1])


n = int(input())
a = list(input())
b = []
d = []
f = []
e = ''
c = 0
for i in range(2, n // 2 + 1):
	if n % i == 0:
		b.append(i)
for i in range(len(b)):
	c = a[0:b[i]]
	for j in range(len(c) - 1, -1, -1):
		d.append(c[j])
	a = d + a[b[i]:len(a)]
	d = []
	c = []
for k in range(len(a) - 1, -1, -1):
	f.append(a[k])
for i in range(len(f)):
	e += f[i]
print(e)


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 = list(input().strip())
	divisors = list(divisorGenerator(n))
	for div in divisors:
		line[:div] = ''.join(reversed(line[:div]))
	print(''.join(line))
main()


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


def divisors(n):
	a = []
	for i in range(1, n + 1):
		if n % i == 0:
			a.append(i)
	a.sort()
	return a
o = int(input())
k = divisors(o)
s = list(input())
w = 1
while w < len(k) - 1:
	s = s[k[w] - 1::-1] + s[k[w]::1]
	w += 1
s = s[::-1]
print(''.join(s))


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


n = int(input())
s = list(map(str, input().split()))
s = list(str(s[0]))
div = []
for i in range(1, n + 1):
	if n % i == 0:
		div.append(i)
for i in div:
	for k in range(i):
		a = s.pop(k)
		s.insert(0, a)
print(''.join(map(str, s)))


from math import *

def reverse(a, n, k):
	for i in range(0, int(k / 2)):
		temp = a[i]
		a[i] = a[k - i - 1]
		a[k - i - 1] = temp
n = int(input().strip())
s = input().strip()
s = list(s)
l = []
for i in range(1, int(sqrt(n)) + 1):
	if n % i == 0:
		l.append(i)
		if i * i != n:
			l.append(int(n / i))
l.sort()
for i in l:
	reverse(s, n, i)
for i in s:
	print(i, end='')


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)


import sys
n = int(sys.stdin.readline())
word = sys.stdin.readline().replace('\n', '')

def change(word, d, f):
	out = ''
	for loop in range(0, d):
		out += word[loop]
	for loop in range(f, d - 1, -1):
		out += word[loop]
	for loop in range(f + 1, len(word), 1):
		out += word[loop]
	return out
for loop in range(1, n + 1, 1):
	if n % loop == 0:
		word = change(word, 0, loop - 1)
print(word)


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

def reverse(s, i):
	temp = s.copy()
	for j in range(i):
		temp[j] = s[i - j - 1]
	return temp
for i in range(2, n + 1):
	if n % i == 0:
		s = reverse(s, i)
print(''.join(s))


t = int(input())
s = list(input())
d = [i for i in range(1, t // 2 + 1) if t % i == 0] + [t]
for di in d:
	s[:di] = s[:di][::-1]
print(''.join(s))


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


l = int(input())
s = list(input())
for i in range(2, l + 1):
	if l % i > 0:
		continue
	s[:i] = s[i - 1::-1]
print(''.join(s))


n = int(input())
s = input()
for i in range(1, n + 1):
	if n % i:
		continue
	s = s[i - 1::-1] + 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))) + 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)
div_last_part = div_last_part[::-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)


from sys import stdin, stdout
n = int(input().strip())
s = list(input())
for i in range(2, n + 1):
	if n % i == 0:
		temp = s[:i]
		temp.reverse()
		s = temp + s[i:]
stdout.write(''.join(s))


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


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


class CodeforcesTask999BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.code = ''

	def read_input(self):
		self.n = int(input())
		self.code = input()

	def process_task(self):
		for x in range(1, self.n + 1):
			if not self.n % x:
				self.code = self.code[:x][::-1] + self.code[x:]
		self.result = self.code

	def get_result(self):
		return self.result
Solution = CodeforcesTask999BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


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


from math import sqrt
import sys
lines = [line.strip() for line in sys.stdin.readlines()]
n = int(lines[0].strip(' '))
s = lines[1].strip(' ')

def divisors(n):
	lim = sqrt(n)
	divs = [n]
	for d in range(2, int(lim) + 1):
		if n % d == 0:
			divs.append(d)
			if d != n / d:
				divs.append(n / d)
	return sorted(divs)
divs = divisors(n)
for div in divs:
	s = s[:int(div)][::-1] + s[int(div):]
print(s)


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


n = int(input())
codeword = input()
for i in range(2, n):
	if n % i == 0:
		temp = codeword[:i]
		rest = codeword[i:]
		temp = ''.join(list(reversed(temp)))
		codeword = temp + rest
codeword = ''.join(list(reversed(codeword)))
print(codeword)


n = int(input())
rem = []
s = input()
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		if n // i != i:
			rem.append(i)
			rem.append(n // i)
		else:
			rem.append(i)
rem.sort()
for i in rem:
	s1 = s[0:i]
	s = s1[::-1] + s[i:n]
print(s)


n = int(input())
ch = str(input())
divisors = []
a = list(ch)
temp = []
for i in range(1, n // 2 + 1):
	if n % i == 0:
		divisors.append(i)
for i in divisors:
	temp = a[0:i]
	for j in temp:
		a.remove(j)
	for j in range(i):
		a.insert(0, temp[j])
a.reverse()
print(*a, sep='')


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


from math import ceil

def dividers(n):
	res = []
	for d in range(2, ceil(n / 2 + 1)):
		if n % d == 0:
			res.append(d)
	return res + [n]
divs = dividers(int(input()))
s = input()
for el in divs:
	s = s[:el][::-1] + s[el:]
print(s)


def string_rev(s):
	return s[::-1]
n = int(input())
text = input()
if n == 1:
	print(text)
else:
	l = []
	for j in range(1, n // 2 + 1):
		if n % j == 0:
			if n // j == j:
				l.append(j)
			else:
				l.append(j)
				l.append(n // j)
	l = set(l)
	l = list(l)
	l.sort()
	for i in range(1, len(l)):
		text = string_rev(text[0:int(l[i])]) + text[int(l[i]):]
	print(text)


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 reverse(s):
	str = ''
	for i in s:
		str = i + str
	return str
n = int(input())
str = str(input())
arr = []
for i in range(n):
	arr.append(str[i])
for i in range(1, n + 1):
	if n % i == 0:
		arr[0:i] = reverse(arr[0:i])
for i in range(n):
	print(arr[i], end='')


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


import math
n = int(input())
t = input()
a = []
for i in range(1, math.floor(math.sqrt(n)) + 1):
	if n % i == 0:
		a.append(i)
		if i != math.sqrt(n):
			a.append(n // i)
a.sort()
for i in a:
	i -= 1
	t = t[i::-1] + t[i + 1:]
print(t)


import math
n = int(input())
t = input()
a = []
j = 0
w = 1
for i in range(1, int(math.sqrt(n)) + 1):
	if n % i == 0:
		a.insert(j, i)
		a.insert(w, n // i)
		j += 1
		w += 1
if a[j - 1] == a[w - 1]:
	a.pop(j)
for i in a:
	r = t[:i]
	t = r[::-1] + t[i:]
print(t)


def decodeString(s, n, d):
	if n == 1:
		return s
	if d == n:
		return s[::-1]
	if n % d != 0:
		return decodeString(s, n, d + 1)
	s1 = s[:d]
	s = s1[::-1] + s[d:]
	return decodeString(s, n, d + 1)
n = int(input())
s = input()
print(decodeString(s, n, 2))


import sys
import math
from collections import Counter

def divs(n, start=2):
	divisors = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				divisors.append(i)
			else:
				divisors.extend([i, n // i])
	return divisors
n = int(input())
s = input()
t = divs(n)
t.sort()
ans = ''
for i in t:
	s = s[:i][::-1] + s[i:]
print(s[::-1])


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


def getDivisors(n):
	ret = []
	for i in range(2, n + 1):
		if n % i == 0:
			ret.append(i)
	return ret
n = int(input().strip())
s = input().strip()
assert n == len(s)
l = list(s)
for i in getDivisors(n):
	l[:i] = list(reversed(l[:i]))
print(''.join(l))


import math

def divisors(n):
	divs = [1]
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			divs.extend([i, n // i])
	divs.extend([n])
	return list(set(divs))
n = int(input().strip())
st = list(input())
div = divisors(n)
div.sort()
for i in range(len(div)):
	st[:div[i]] = st[:div[i]][::-1]
print(''.join(st))


n = int(input())
s = list(input())
for i in range(2, n):
	if n % i == 0:
		s1 = s[0:i].copy()
		s1.reverse()
		for j in s[i:]:
			s1.append(j)
		s = s1.copy()
s.reverse()
print(''.join(s))


from math import sqrt

def invert(s, end):
	return ''.join(list(reversed(s[:end]))) + s[end:]
n = int(input())
s = input()
divs = set()
for i in range(1, int(sqrt(n)) + 1):
	if n % i == 0:
		divs.add(i)
		divs.add(int(n / i))
divs = list(sorted(list(divs)))
for d in divs:
	s = invert(s, d)
print(s)


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

def flipSS(s, l, r):
	return s[:l] + s[l:r][::-1] + s[r:]
for i in range(2, n + 1):
	if n % i == 0:
		s = flipSS(s, 0, i)
print(s)


n = int(input())
s = input().split()
for i in range(2, n + 1):
	if n % i != 0:
		continue
	a = s[0][i:]
	b = s[0][:i]
	s[0] = b[::-1] + a
print(s[0])


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


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


def solve(n, s):
	chars = list(s)
	for d in [x for x in range(1, n + 1) if n / x == n // x]:
		chars[:d] = reversed(chars[:d])
	return ''.join(chars)

def main():
	n = int(input().strip())
	s = input().strip()
	result = solve(n, s)
	print(result)
main()


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


n = int(input())
s = list(input())
a = []
for i in range(1, n + 1):
	if n % i == 0:
		a.append(i)
for i in a:
	k = s[i:]
	s = s[:i]
	s.reverse()
	for j in k:
		s.append(j)
ans = ''.join((str(i) for i in s))
print(ans)


from collections import *
n = int(input())
r = [x for x in range(2, n) if n % x == 0]
l = list(input())
for i in r:
	t = l[0:i]
	t = t[::-1]
	for j in range(i):
		l[j] = t[j]
l = l[::-1]
print(''.join(l))


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


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


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)
n = int(input())
strs = input()
deencrypt(strs, n)


n = int(input())
a = list(input())
a.reverse()
for i in range(2, n):
	if n % i == 0:
		b = a[-i:]
		b.reverse()
		a = a[:-i] + b
for i in a:
	print(i, end='')


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:]
	i += 1
print(''.join(l1))


import math
s = input()
s = int(s)

def split(word):
	return list(word)
word = input()
x = split(word)
for i in range(1, s + 1):
	if s % i == 0:
		z = i // 2
		for b in range(z):
			(x[b], x[i - 1 - b]) = (x[i - 1 - b], x[b])
m = ''
for c in range(s):
	m = m + x[c]
print(m)


def main():
	import sys
	n = int(sys.stdin.readline())
	str = sys.stdin.readline()
	divisors = []
	for i in range(2, n + 1):
		if n % i == 0:
			divisors.append(i)
	for div in divisors:
		lb = 0
		rb = div
		str = str[:lb] + str[lb:rb][::-1] + str[rb:]
	print(str)
main()


def divisor(n):
	(i, l1, l2) = (2, list(), list())
	while i * i < n:
		if n % i == 0:
			l1.append(i)
			l2.append(n // i)
		i += 1
	if i * i == n:
		l1.append(i)
	l2.reverse()
	return l1 + l2
n = int(input())
s = bytearray(input(), encoding='ascii')
for x in divisor(n):
	(i, j) = (0, x - 1)
	while i < j:
		s[i] = s[i] ^ s[j]
		s[j] = s[i] ^ s[j]
		s[i] = s[i] ^ s[j]
		(i, j) = (i + 1, j - 1)
print(s.decode()[::-1])


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


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


x = int(input())
s = input()

def factors(x):
	result = []
	i = 1
	while i * i <= x:
		if x % i == 0:
			result.append(i)
			if x / i != i:
				result.append(int(x / i))
		i += 1
	return result
f = sorted(factors(x))
for i in f:
	s = s[:i][::-1] + s[i:]
print(s)


N = int(input())
S = input()
L = []
for i in range(1, N + 1):
	if N % i == 0:
		L.append(i)
L.sort()
for p in L:
	S = S[:p][::-1] + S[p:]
print(S)


a = int(input())
string = input()
for d in range(2, a + 1):
	if a % d == 0:
		string = string[d - 1::-1] + string[d:]
print(string)


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())
t = list(str(input()))

def make_divisors(n):
	divisors = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
d = make_divisors(n)
for i in d:
	t = list(reversed(t[0:i])) + t[i:]
print(''.join(t))


n = int(input())
po = list(input())
kam = list(range(2, n + 1))
ol = []
for item in kam:
	if n % item == 0:
		ol.append(item)
	else:
		pass
for item in ol:
	tam = po[0:item]
	po[0:item] = tam[::-1]
print(''.join(po))


n = int(input())
s = input()
s = list(s)
t = []

def func(x):
	lis = []
	for i in range(2, x):
		if x % i == 0:
			if i not in lis:
				lis.append(i)
	return lis
for j in range(len(func(n))):
	a = func(n)[j]
	for i in range(a // 2):
		(s[i], s[a - i - 1]) = (s[a - i - 1], s[i])
for i in range(n):
	t.append(s[n - i - 1])
t = ''.join(t)
print(t)


n = int(input())
a = input()
a = list(a)
fact = []
for i in range(1, n + 1):
	if n % i == 0:
		fact.append(i)
for i in range(1, len(fact)):
	s = a[0:fact[i]]
	s2 = a[fact[i]:len(a)]
	s.reverse()
	a = s + s2
for i in range(n):
	print(a[i], end='')


n = int(input())
a = list(input())
l = []
l.extend(a[0:1])
last = 1
for i in range(1, n + 1):
	if n % i == 0:
		l.extend(a[last:i])
		l.reverse()
		last = i
print(''.join(l))


def solve(data):
	n = int(data[0])
	s = data[1]
	res = s
	for i in range(n):
		if n % (i + 1) == 0:
			res = res[i::-1] + res[i + 1:]
	return res
data = []
data.append(input().strip())
data.append(input().strip())
res = solve(data)
print(res)


n = int(input())
s = list(input())
a = []
for d in range(1, n + 1):
	if n % d == 0:
		p = s[0:d]
		a.append(p[::-1])
		s[0:d] = p[::-1]
print(''.join(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(input())
arr = input()
for i in range(n):
	if n % (i + 1) == 0:
		arr = arr[:i + 1][::-1] + arr[i + 1:]
print(arr)


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)


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


a = int(input())
e = list()
b = input()
for i in b:
	e.append(i)
d = list()
for i in range(1, a + 1):
	if a % i == 0:
		d.append(i)
for i in range(len(d)):
	c = e[:d[i]]
	c = c[::-1] + e[d[i]:]
	e = c
for i in e:
	print(i, end='')


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


while True:
	try:
		n = int(input())
		s = input()
		for i in range(n):
			if n % (i + 1) == 0:
				list1 = list(s)
				for j in range(0, i // 2 + 1):
					t = list1[j]
					list1[j] = list1[i - j]
					list1[i - j] = t
				s = ''.join(list1)
		print(s)
	except:
		break


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


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

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


n = int(input())
a = list(input())
for i in range(n):
	if n % (i + 1) == 0:
		for j in range(i // 2 + 1):
			(a[j], a[i - j]) = (a[i - j], a[j])
print(*a, sep='')


input()
encrpyt = input()
n = len(encrpyt)
for i in range(n):
	if not n % (i + 1):
		substr = encrpyt[:i + 1]
		substr = substr[::-1]
		encrpyt = encrpyt[i + 1:]
		encrpyt = substr + encrpyt
print(encrpyt)


import sys
n = int(sys.stdin.readline().strip())
s = sys.stdin.readline().strip()

def do():
	a = s
	for i in range(1, n + 1):
		if n % i:
			continue
		a = a[:i][::-1] + a[i:]
	return a
print(do())


from functools import reduce

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

def Remove(duplicate):
	final_list = []
	for num in duplicate:
		if num not in final_list:
			final_list.append(num)
	return final_list
n = int(input())
string = input()
strlis = list()
for i in range(len(string)):
	strlis.append(string[i])
factor = factors(n)
factor.sort()
factor = Remove(factor)
for op in factor:
	substr = list()
	for i in range(op):
		substr.append(strlis[i])
	substr.reverse()
	for i in range(len(substr)):
		strlis[i] = substr[i]
for let in strlis:
	print(let, end='')


from math import sqrt
import sys

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

def get_ints_lists():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
n = int(input())
s = get_string()
if n == 1:
	print(s)
elif n == 2 or n == 3:
	print(s[::-1])
else:
	p = int(sqrt(n))
	li = []
	for i in range(2, p + 1):
		if i * i == n:
			li.append(i)
		elif n % i == 0:
			li.append(i)
			li.append(n // i)
	li.sort()
	for j in li:
		s = s[j - 1::-1] + s[j:n]
	s = s[::-1]
	print(s)


import math as mt
import sys, string
from collections import Counter, defaultdict
input = sys.stdin.readline
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)
tc = 1
for _ in range(tc):
	main()


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


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):
	a = ''.join(reversed(a[0:i])) + a[i:n]
print(a)


b = []

def dil(n):
	for i in range(n, 1, -1):
		if n % i == 0:
			b.append(i)
n = int(input())
s = input()
dil(n)
for i in range(len(b) - 1, -1, -1):
	s1 = s[0:b[i]]
	s2 = s[b[i]:len(s)]
	s = s1[::-1] + s2
print(s)


import sys

def i_ints():
	return map(int, sys.stdin.readline().split())
(n,) = i_ints()
s = input()
for d in range(1, n + 1):
	if n % d == 0:
		s = s[:d][::-1] + s[d:]
print(s)


n = int(input())
a = []
for i in range(2, n + 1):
	if n % i == 0:
		a.append(i)
s = list(input())
for i in range(len(a)):
	j = s[:a[i]]
	j.reverse()
	for l in range(a[i]):
		s[l] = j[l]
x = ''
for i in s:
	x += i
print(x)


n = int(input())
a = input()
divs = []
for i in range(1, n + 1):
	if n % i == 0:
		divs.append(i)
for i in divs:
	q = list(a[:i])
	q.reverse()
	st = ''
	for j in q:
		st += j
	a = st + a[i:]
print(a)


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


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
print(''.join(l))


import sys, math
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()))

def make_divisors(n):
	divisors = []
	for i in range(1, int(math.sqrt(n)) + 1):
		if n % i == 0:
			divisors.append(i)
			if i != n // i:
				divisors.append(n // i)
	divisors.sort()
	return divisors
n = inp()
now = input()
cnts = make_divisors(n)
for cnt in cnts:
	pre = now[:]
	now = pre[:cnt][::-1] + pre[cnt:]
print(now)


def rotate(s, d):
	l = ''.join(reversed(s[0:d]))
	r = s[d:]
	return l + r
n = int(input())
arr = []
i = 2
while i <= n:
	if n % i == 0:
		arr.append(i)
	i += 1
str = input()
for i in arr:
	str = rotate(str, i)
print(str)


t = int(input())
p = [i for i in input()]
l1 = []
for i in range(1, t + 1):
	if t % i == 0:
		l1.append(t // i)
l1.reverse()
for i in l1:
	p = p[:i][::-1] + p[i:]
print(*p, sep='')


n = int(input())
s = input()
batas = int(n ** 0.5)
has = set()
for i in range(1, batas + 1):
	cek1 = n / i
	cek2 = n // i
	if abs(cek1 - cek2) <= 1e-07:
		has.add(i)
		has.add(cek2)
has = sorted(has)[1:]
for x in has:
	s = s[:x][::-1] + s[x:]
print(s)


n = int(input())
tmp = input()
s = []
for i in tmp:
	s.append(i)
for i in range(2, n, 1):
	if n % i == 0:
		arr = []
		for j in range(i):
			arr.append(s[j])
		arr.reverse()
		s = arr + s[i:]
s.reverse()
for i in s:
	print(i, end='')


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

def reverse_part(s, i):
	q = s[:i]
	return q[::-1] + s[i:]
for i in range(2, n + 1):
	if n % i == 0:
		s = reverse_part(s, i)
print(s)


sayi = int(input())
yazi = input()
yazii = []
index = []
for i in range(1, sayi + 1):
	if sayi % i == 0:
		index.append(i)
for m in range(0, sayi):
	yazii.append(yazi[m])
for z in range(len(index)):
	for n in range(0, int(index[z] / 2)):
		temp = ''
		temp = yazii[index[z] - n - 1]
		yazii[index[z] - 1 - n] = yazii[n]
		yazii[n] = temp
print(*yazii, sep='')


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


import math
n = int(input())
a = input()
i = 2
while i < len(a) // 2 + 1:
	if len(a) % i == 0:
		a = a[i - len(a) - 1::-1] + a[i:]
	i = i + 1
print(a[-1::-1])


n = int(input())
str1 = str(input())
l2 = []
for i in str1:
	l2.append(i)
l1 = []
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)


def reverse_sublist(lst, start, end):
	sublist = lst[start:end]
	sublist.reverse()
	lst[start:end] = sublist
n = int(input())
s = list(input())
for i in range(1, len(s) + 1):
	if n % i == 0:
		reverse_sublist(s, 0, i)
l = ''.join(s)
print(l)


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))


(z, w, m) = (input, int, sorted)
n = int(z())
l = z()
l1 = []
l2 = l
for i in range(1, n + 1):
	if n % i == 0:
		l1.append(i)
for i in l1[1:-1]:
	p = l[i - 1::-1]
	l2 = p + l[i:]
	l = l2
print(l2[::-1])


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


def rev(string):
	string = ''.join(reversed(string))
	return string

def algo(s, n):
	for x in range(2, n + 1):
		if n % x == 0:
			s = rev(s[0:x]) + s[x:n]
	return s
n = int(input())
t = input()
ans = algo(t, n)
print(ans)


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


n = int(input())
s = input()
d = []
for i in range(1, int(n ** 0.5 + 0.999999999999999) + 1):
	if n % i == 0:
		d.append(i)
		d.append(n // i)
d = list(set(d))
d.sort()
for i in d:
	s = s[:i][::-1] + s[i:]
print(s)


size = 0

def decrypt(s: str):
	divList = []
	div = 2
	while div * div <= size:
		if size % div == 0:
			div1 = int(size / div)
			divList.append(div)
			if div != div1:
				divList.append(div1)
		div += 1
	divList.append(size)
	divList.sort()
	sList = list(s)
	for d in divList:
		b = 0
		e = d - 1
		while b < e:
			tmp = sList[b]
			sList[b] = sList[e]
			sList[e] = tmp
			b += 1
			e -= 1
	s = ''.join(sList)
	return s
size = input()
size = int(size)
s = input()
res = decrypt(s)
print(res)


def factor(n):
	b = []
	for i in range(1, n // 2 + 1):
		if n % i == 0:
			b.append(i)
			b.append(n // i)
	return list(set(b))
n = int(input())
a = str(input())
b = factor(n)
b.sort()
for i in b:
	a = a[:i][::-1] + a[i:]
print(a)


import sys
from collections import Counter

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def divisors(N: int) -> set:
	from math import sqrt
	s = {1, N}
	for i in range(2, int(sqrt(N)) + 1):
		if N % i == 0:
			s.add(i)
			s.add(N // i)
	return s

def rev(T, i):
	return T[:i][::-1] + T[i:]
N = INT()
T = list(input())
divs = sorted(divisors(N))
for div in divs:
	T = rev(T, div)
print(''.join(T))


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


n = int(input())
s = input()
for d in range(1, n + 1):
	if n % d == 0:
		a = list(s[:d])
		a.reverse()
		s = ''.join(list(map(str, a))) + s[d:]
print(s)


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


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


def main():
	(n, l) = (int(input()), list(input()))
	for p in range(1, n + 1):
		if not n % p:
			l[:p] = l[p - n - 1::-1]
	print(''.join(l))
main()


from bisect import bisect
from collections import defaultdict
from math import gcd, sqrt, ceil
from collections import Counter

def solve(n):
	la = []
	for i in range(1, int(sqrt(n)) + 1):
		if n % i == 0:
			la.append(n // i)
			if la[-1] != i:
				la.append(i)
	return sorted(la)
n = int(input())
l = solve(n)
s = list(input())
for i in range(len(l)):
	z = l[i]
	k = s[:z][::-1]
	for i in range(z):
		s[i] = k[i]
print(''.join(s))


n = int(input())
s = input()
mas = []
k = 2
while n // 2 + 1 > k:
	if n % k == 0:
		mas.append(k)
	k += 1
mas.append(n)
for ind in mas:
	sub = s[:ind]
	s = sub[::-1] + s[ind:]
print(s)


def dividers(n):
	l = set()
	for i in range(2, int(n ** 0.5) + 1):
		if not n % i:
			l.add(i)
			l.add(n // i)
	return list(l)
n = int(input())
s = input()
div = dividers(n)
div.sort()
for i in div:
	s = s[i - 1::-1] + s[i:]
print(s[::-1])


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

def ws(s):
	sys.stdout.write(s)
	sys.stdout.write('\n')

def wi(n):
	sys.stdout.write(str(n))
	sys.stdout.write('\n')

def wia(a, sep=' '):
	sys.stdout.write(sep.join([str(x) for x in a]))
	sys.stdout.write('\n')

def main():
	n = ri()
	s = rs()
	for d in range(1, n + 1):
		if n % d > 0:
			continue
		s = s[d - 1::-1] + s[d:]
	ws(s)
main()


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


n = int(input())
s = input()
l = []
for q in range(1, n + 1):
	if n % q == 0:
		l.append(q)
for w in l:
	ss = s[:w]
	bs = s[w:]
	ss = ss[::-1]
	s = ss + bs
print(s)


n = int(input())
s = input()
div = []
import math
for i in range(1, int(math.sqrt(n)) + 1):
	if n % i == 0:
		if i * i == n:
			div.append(i)
		else:
			div.append(i)
			div.append(n // i)
div.sort()
div.pop(0)
for i in div:
	temp = s[:i][::-1]
	s = temp + s[i:]
print(s)


n = int(input())
s = list(map(str, input()))
for i in range(2, n + 1):
	if n % i == 0:
		s = s[i - 1:0:-1] + list(s[0]) + s[i:n + 1]
print(*s, sep='')


def rev(S):
	return S[::-1]
N = int(input().strip())
S = input().strip()
factor = []
for i in range(2, N + 1):
	if N % i == 0:
		factor.append(i)
if len(factor) > 0:
	for f in factor:
		S = rev(S[:f]) + S[f:]
print(S)


a = int(input())
b = input()
factors = []
for i in range(2, int(a / 2 + 1)):
	if a % i == 0:
		factors.append(i)
factors.append(a)
for k in factors:
	b = b[k - 1::-1] + b[k:]
print(b)


import math

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

def reverseme(s):
	return s[::-1]
n = int(input())
s = input()
factors = find_factors(n)
for f in factors:
	s = reverseme(s[:f]) + s[f:]
print(s)


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


from sys import stdin, stdout
from math import gcd, ceil, sqrt
from collections import Counter
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
n = ii1()
l = list(range(n))
div = set()
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		div.add(i)
		div.add(n // i)
div = sorted(list(div), reverse=True)
for i in div:
	l = l[:i][::-1] + l[i:]
s = is1()
res = [''] * n
for (i, j) in zip(l, s):
	res[i] = j
print(''.join(res))


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


def update(s, i, j):
	t1 = []
	for i in range(j, -1, -1):
		t1.append(s[i])
	for i in range(j + 1, n):
		t1.append(s[i])
	return t1
n = int(input())
s = input()
for i in range(0, n):
	if n % (i + 1) == 0:
		s = update(s, 0, i)
for i in s:
	print(i, end='')
print()


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


n = int(input())
a = list(input().strip())
i = 1
while i <= n:
	if n % i == 0:
		a = a[:i][::-1] + a[i:]
	i += 1
print(''.join(a))


n = int(input())
string = input()
n2 = n
divisors = []
i = 2
while i < n2:
	if n2 % i == 0:
		divisors.append(i)
	i += 1
for i in divisors:
	toReplace = string[0:i]
	toReplace = toReplace[::-1]
	string = toReplace + string[i:len(string)]
print(string[::-1])


def reverse(string):
	return string[::-1]
(n, s) = (int(input()), input())
i = 2
while i < n:
	if n % i == 0:
		r = s[0:i]
		r = reverse(r)
		s = r + s[i:]
	i += 1
print(reverse(s))


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


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


size = int(input())
word = input()

def getLowerDivisors(size):
	return [i for i in range(1, size // 2 + 1) if size % i == 0]

def getUpperDivisors(size):
	return [size // i for i in getLowerDivisors(size)]

def getDivisors(size):
	return sorted(list(set(getLowerDivisors(size) + getUpperDivisors(size))))

def performOperation(word, pos):
	return word[:pos][::-1] + word[pos:]

def retriveWord(word, size):
	if len(getDivisors(size)) == 2:
		return word[::-1]
	for i in getDivisors(size):
		word = performOperation(word, i)
	return word
print(retriveWord(word, size))


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


inp = int(input())
s = list(map(str, input()))
for x in range(2, len(s) + 1):
	if inp % x == 0:
		t = s[:x]
		t.reverse()
		s = t + s[x:]
for q in s:
	print(q, end='')


import sys

def rev(s, d):
	for i in range(int(d / 2)):
		t = s[i]
		s = s[:i] + s[d - 1 - i] + s[i + 1:]
		s = s[:d - 1 - i] + t + s[d - i:]
	return s

def renc(s):
	for d in range(1, len(s) + 1):
		if len(s) % d == 0:
			s = rev(s, d)
	return s
n = int(sys.stdin.readline()[:-1])
a = sys.stdin.readline()[:-1]
a = renc(a)
print(a)


n = int(input())
x = input()
i = 2
ans = x
while i <= n:
	if n % i == 0:
		sl = x[:i]
		rev = sl[::-1]
		ans = rev + x[i:]
		x = ans
	i += 1
print(ans)


import os
d = int(input())
str = str(input())
divise = []
for i in range(1, d + 1):
	if d % i == 0:
		divise.append(int(i))
for i in divise:
	str = str[:i][::-1] + str[i:]
print(str)


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 - 1::-1] + s[i:]
print(s)


n = int(input())
s = str(input())
A = []
x = ''
for i in range(1, n + 1):
	if n % i == 0:
		A.append(i)
for i in A:
	s = s[i - 1::-1] + s[i:]
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(int(n / i))
	for divisor in reversed(large_divisors):
		yield divisor
n = int(input())
s = input()
divisor_list = list(divisorGenerator(n))
for value in divisor_list:
	s = s[:value][::-1] + s[value:]
print(s)


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


def read_nums():
	return [int(x) for x in input().split()]

def main():
	(n,) = read_nums()
	s = input()
	for i in range(1, n + 1):
		if n % i == 0:
			one = s[:i][::-1]
			two = s[i:]
			s = one + two
	print(s)
main()


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

def reverse(s, r):
	str = ''
	s1 = s[:r]
	s2 = s[r:]
	for i in s1:
		str = i + str
	return str + s2
for i in range(1, n + 1):
	if n % i == 0:
		t = reverse(t, i)
print(t)


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


import math

def printDivisors(n):
	l = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	l.sort()
	return l
n = int(input())
div = printDivisors(n)
s = input()
for i in range(1, len(div)):
	k = s[:div[i]]
	k = k[::-1]
	ans = k + s[div[i]:]
	s = ans
print(s)


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


from math import *
from collections import deque
from copy import deepcopy
import sys

def inp():
	return sys.stdin.readline().rstrip('\r\n')

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))

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
n = int(input())
s = inp()
a = list(s)
for i in range(n):
	if n % (i + 1) == 0:
		temp = a[i::-1]
		a[:i + 1] = deepcopy(temp)
for i in a:
	print(i, end='')


def f(n):
	ans = []
	d = 1
	while d * d < n:
		if n % d == 0:
			ans.append(d)
			ans.append(n // d)
		d += 1
	if d * d == n:
		ans.append(d)
	ans = sorted(ans)
	return ans
n = int(input())
s = input()
a = f(n)
for i in range(len(a)):
	s = s[:a[i]][::-1] + s[a[i]:]
print(s)


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


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


n = int(input())
s = list(input())
divisor = []
for i in range(1, n + 1):
	if n % i == 0:
		divisor.append(i)
ans = s
for num in divisor:
	mae = ans[num - 1::-1]
	ato = ans[num:]
	ans = mae + ato
print(''.join(ans))


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


from math import sqrt
n = int(input())
s = list(input())
aux = [0 for i in range(n)]
divisors = []
for i in range(1, int(sqrt(n)) + 1):
	if n % i == 0:
		divisors.append(i)
		if n / i != i:
			divisors.append(n / i)
divisors.sort()
for i in divisors:
	s[0:int(i)] = reversed(s[0:int(i)])
print(''.join(s))


def rev(l, d):
	ll = l[d:]
	ll1 = l[:d]
	ll = ll1[::-1] + ll
	return ll
n = int(input())
s = str(input())
di = []
for i in range(1, n + 1):
	if n % i == 0:
		di.append(i)
l = list(s)
for i in range(len(di)):
	l = rev(l, di[i])
print(''.join(l))


p = int(input())
n = input()
k = []
for i in range(2, int(p ** 0.5) + 1):
	if p % i == 0:
		if p // i == i:
			k.append(i)
		else:
			k.append(i)
			k.append(p // i)
k.sort()
for i in k:
	n = n[:i][::-1] + n[i:]
print(n[::-1])


n = int(input())
r = input()
r1 = r
for i in range(1, n + 1):
	if n % i == 0:
		r2 = r1[:i]
		r1 = r2[::-1] + r1[i:]
	else:
		continue
print(r1)


N = int(input())
S = list(input())
i = 0
SS = []
N1 = N
for i in range(N - 1, 0, -1):
	if N1 % (i + 1) == 0:
		SS.append(i + 1)
SS = sorted(SS)
for i in range(0, len(SS)):
	w = SS[i]
	Sw = S[0:w]
	Sww = Sw[::-1]
	Swww = S[w:]
	S = Sww + Swww
print(''.join(S))


from sys import stdin, stdout

def decrypt(t, n):
	for i in range(2, n):
		if n % i == 0:
			t = t[i - 1::-1] + t[i:]
	t = t[::-1]
	return t
n = int(stdin.readline())
t = stdin.readline()
s = decrypt(t, n)
stdout.write(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)
	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))


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


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()
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())
sp = input()
d = []
for i in range(2, n // 2 + 1):
	if n % i == 0:
		d.append(i)
for i in d:
	(a1, a2) = (sp[:i], sp[i:])
	sp = a1[::-1] + a2
sp = sp[::-1]
print(sp)


n = int(input())
s = input()
denominators = []
for i in range(n, 0, -1):
	if n % i == 0:
		if i not in denominators:
			denominators.append(i)
denominators = sorted(denominators)
s = list(s)
s.insert(0, '0')
for i in range(len(denominators)):
	d = denominators[i]
	lol = s[d::-1]
	del s[:d + 1]
	s = lol + s
s.remove('0')
print(''.join(s))


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


from math import ceil
n = int(input())
s = input()
factors = []
for num in range(1, ceil(pow(n + 1, 0.5))):
	if n % num == 0:
		factors.append(num)
		if n / num not in factors:
			factors.append(int(n / num))
for i in sorted(factors):
	s = s[0:i][::-1] + s[i:]
print(''.join(s))


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

def divisors_test(x):
	L = []
	for i in range(1, x + 1):
		if x % i == 0:
			L.append(i)
	return L
M = divisors_test(n)
s = list(t)
s1 = ''
for i in M:
	a = s[0:i]
	b = s[i:len(s) + 1]
	a.reverse()
	s = a + b
for i in range(len(s)):
	s1 = s1 + s[i]
print(s1)


def delit(n):
	i = 1
	arr = []
	while i * i <= n:
		if n % i == 0:
			arr.append(i)
			if i != n // i:
				arr.append(n // i)
		i += 1
	return sorted(arr)

def reverse(s):
	str = ''
	for i in s:
		str = i + str
	return str

def jifr(arr, ta, na):
	arr2 = ''
	for i in arr:
		arr2 = reverse(ta[:i])
		ta = ta[i:]
		ta = arr2 + ta
	return ta
n = int(input())
t = input()
de = delit(n)
del de[0]
print(jifr(de, t, n))


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


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


def z(y):
	return y[::-1]
n = int(input())
a = input()
a = list(a)
l = []
for i in range(2, n + 1):
	if n % i == 0:
		a[0:i] = z(a[0:i])
for i in range(n):
	print(a[i], end='')


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


def reverse(string):
	string = ''.join(reversed(string))
	return string
n = input()
n = int(n)
enc = input()
divisors = list()
for i in range(2, n + 1):
	if n % i == 0:
		divisors.append(i)
for n in divisors:
	enc = reverse(enc[:n]) + enc[n:]
print(enc)


n = int(input())
s = input()
divisors = []
for i in range(1, int(n ** 0.5) + 2):
	if n % i == 0:
		divisors.append(i)
		divisors.append(n // i)
divisors = sorted(set(divisors))
for i in divisors:
	t = s[:i]
	t = t[::-1]
	s = t + s[i:]
print(s)


n = int(input())
s = input()
s = list(s)
for i in range(1, n + 1):
	if n % i == 0:
		st = 0
		end = i - 1
		while end > st:
			m = s[st]
			s[st] = s[end]
			s[end] = m
			end -= 1
			st += 1
print(''.join(s))


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
main()


prime = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 87]
n = int(input())
s = input()
if n in prime:
	print(s[::-1])
else:

	def find_divisor(n):
		div = [n]
		sq = int(n ** 0.5) + 1
		for i in range(2, sq):
			if n % i == 0:
				div += [i, n // i]
		return div
	div = list(set(find_divisor(n)))
	div.sort()
	for i in div:
		a = s[:i]
		a = a[::-1]
		b = s[i:]
		s = a + b
	print(s)


def reverse():
	n = int(input())
	word = input()
	dividers = []
	if n < 1:
		print(word)
		exit()
	for i in range(round(n / 2 + 1)):
		if i != 0 and n % i == 0:
			dividers.append(i)
	dividers.append(n)
	for d in dividers:
		new_string = reverse_string(word[:d]) + word[d:]
		word = new_string
	print(word)

def reverse_string(string_to_reverse):
	return string_to_reverse[::-1]
reverse()


dhor = int(input())
s = str(input())
a = sorted([i for i in range(1, dhor + 1) if dhor % i == 0], reverse=False)
for i in range(len(a)):
	s = s[a[i] - 1::-1] + s[a[i]:]
print(s)


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


n = int(input())
a = set()
for i in range(1, int(n ** 0.5) + 1):
	if n % i == 0:
		a.add(i)
		a.add(n // i)
a = list(a)
a.sort()
s = input()
for i in range(len(a)):
	s1 = ''
	for j in range(a[i] - 1, -1, -1):
		s1 += s[j]
	for k in range(a[i], len(s)):
		s1 += s[k]
	s = s1[:]
print(s)


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


n = int(input())
s = input()
l1 = list(s)
c = 0
for i in range(2, n + 1):
	l2 = []
	if n % i == 0:
		l2 = l1[0:i]
		l2.reverse()
		l1[0:i] = l2
		c += 1
for i in range(len(l1)):
	print(l1[i], end='')


def get_divisors(n):
	res = []
	for d in range(2, n // 2 + 1):
		if not n % d:
			res.append(d)
	return res

def reverse(S, n):
	(i, j) = (0, n - 1)
	while i < j:
		(S[i], S[j]) = (S[j], S[i])
		i += 1
		j -= 1
n = int(input())
S = list(input())
for d in get_divisors(n):
	reverse(S, d)
print(''.join(S)[::-1])


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


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(input())
s = input()
s = list(s)

def reverse(a, l, r):
	for i in range(int((r - l + 1) / 2)):
		tmp = a[l - 1 + i]
		a[l - 1 + i] = a[r - 1 - i]
		a[r - 1 - i] = tmp
for d in range(2, n + 1):
	if n % d == 0:
		reverse(s, 1, d)
for i in range(len(s)):
	print(s[i], end='')


from functools import cmp_to_key
n = int(input())
s = input()
s = list(s)
for i in range(1, n + 1):
	if n % i == 0:
		b = s.copy()
		for j in range(0, i):
			b[j] = s[i - j - 1]
		s = b
s = ''.join(s)
print(s)


n = int(input())
s = input()
ms1 = []
ms2 = []
for i in range(1, 11):
	if i * i > n:
		break
	if i * i == n:
		ms1.append(i)
		break
	if n % i == 0:
		ms1.append(i)
		ms2.append(n // i)
for m in (ms1 + ms2[::-1])[1:]:
	s = s[m - 1::-1] + s[m:]
print(s)


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


import os
import sys
debug = True
if debug and os.path.exists('input.in'):
	input = open('input.in', 'r').readline
else:
	debug = False
	input = sys.stdin.readline

def inp():
	return int(input())

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

def insr():
	s = input()
	return s[:len(s) - 1]

def invr():
	return map(int, input().split())
test_count = 1
if debug:
	test_count = inp()
for t in range(test_count):
	if debug:
		print('Test Case #', t + 1)
	n = inp()
	a = insr()
	for i in range(2, n + 1):
		if n % i == 0:
			a = a[0:i][::-1] + a[i:]
	print(a)


def divs(x):
	for i in range(1, x + 1):
		if x % i == 0:
			yield i
n = int(input())
a = [i for i in divs(n)]
s = input()
for el in a:
	s = s[0:el][::-1] + s[el:len(s)]
print(s)


n = int(input())
data = str(input())
ans = list(data)
divs = []
for i in range(1, n + 1):
	if n % i == 0:
		divs.append(i)
for d in divs:
	for j in range(d // 2):
		(ans[j], ans[d - j - 1]) = (ans[d - j - 1], ans[j])
print(''.join((el for el in ans)))


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


import math

def printDivisors(n):
	i = 1
	d = []
	while i <= math.sqrt(n):
		if n % i == 0:
			if n / i == i:
				d.append(i)
			else:
				d.append(i)
				d.append(n / i)
		i = i + 1
	return d
n = int(input())
d = printDivisors(n)
d = list(map(int, d))
d = sorted(d)
s = list(input())
for i in d:
	s[0:i] = s[0:i][::-1]
print(''.join(s))


def reversch(ch, k):
	ch1 = ''
	for i in range(k):
		ch1 = ch[i] + ch1
	return ch1
n = int(input())
ch = input()
for d in range(1, n + 1):
	if n % d == 0:
		ch = reversch(ch, d) + ch[d:]
print(ch)


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


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

def divisors(n):
	ret = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			ret.append(i)
			if n != i ** 2:
				ret.append(n // i)
	ret.sort()
	return ret
divisor = divisors(n)
L = len(divisor)
t = list(t)
count = 0
l = 0
r = L
prev = divisor[-1]
for i in range(L):
	t[:divisor[i]] = t[:divisor[i]][::-1]
print(''.join(t))


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

def reverse(s, i):
	s1 = []
	for i in s[0:i]:
		s1.append(i)
	for (k, i) in enumerate(reversed(s1)):
		s[k] = i
	return s
n = int(input())
s = [i for i in input()]
divs = dividers(n)
for i in divs:
	s = reverse(s, i)
print(''.join(s))


n = int(input())
s = input()
l1 = []
l2 = []
for g in range(0, len(s)):
	l2.append(s[g])
for v in range(1, n + 1):
	if n % v == 0:
		l1.append(v)
for v in range(0, len(l1)):
	x = l1[v]
	y = int(x / 2)
	for b in range(0, y):
		fg = l2[b]
		l2[b] = l2[x - 1 - b]
		l2[x - 1 - b] = fg
df = ''
for dfg in range(0, len(l2)):
	df += l2[dfg]
print(df)


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, 1)
print(s)


import math

def div(n):
	s = int(math.sqrt(n)) + 1
	arr = []
	for i in range(1, s):
		if n % i == 0:
			if n / i == i:
				arr.append(i)
			else:
				arr.append(i)
				arr.append(int(n / i))
	arr.sort(reverse=False)
	return arr

def main():
	n = int(input())
	t = input()
	arr = div(n)
	for d in arr:
		t = ''.join(reversed(t[:d])) + t[d:]
	print(t)
main()


q = int(input())
p = input()
s = []
for i in p:
	s.append(i)
for i in range(1, q + 1):
	if q % i == 0:
		s[0:i] = list(reversed(s[:i]))
ans = ''
for q in s:
	ans += q
print(ans)


def povorot(s):
	for i in range(2, len(s) + 1):
		if len(s) % i != 0:
			continue
		s = s[:i][::-1] + s[i:]
	return s
n = int(input())
t = input()
print(povorot(t))


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(input())
t = list(map(str, input()))
for i in range(1, n + 1):
	if n % i == 0:
		t = t[:i][::-1] + t[i:]
for i in t:
	print(i, end='')


n = int(input())
s = input()
A = []
for i in range(n, 0, -1):
	if n % i is 0:
		A.append(i)
li = []
for i in range(0, len(s)):
	li.append(s[i])
s = li
A.sort()
for i in A:
	x = []
	y = []
	for j in range(0, i):
		x.append(s[j])
	for j in range(i, n):
		y.append(s[j])
	x.reverse()
	s = None
	s = []
	for j in x:
		s.append(j)
	for j in y:
		s.append(j)
print(''.join(s))


z = input
mod = 10 ** 9 + 7
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0:
			return 0
	return 1
n = int(z())
l = z()
ans = []
for i in range(1, ceil(n / 2) + 1):
	if n % i == 0:
		ans.append(i)
ans.append(n)
for i in ans:
	x = l[:i][::-1] + l[i:]
	l = x
print(l)


count = input()
count = int(count)
instring = input()
numbers = []
for i in range(2, int(count / 2 + 1)):
	if count % i == 0:
		numbers.append(int(count / i) - 1)
numbers.append(count - 1)
numbers.sort()
for i in numbers:
	templist = instring[0:i + 1]
	templist = templist[::-1]
	instring = templist + instring[i + 1:]
print(instring)


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())
a = list(input())
for q in range(1, n + 1):
	if n % q == 0:
		a[:q] = a[:q][::-1]
print(*a, sep='')


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())
a = input()
l = [i for i in range(1, n + 1) if n % i == 0]
for i in l:
	a = a[i - 1::-1] + a[i:]
print(a)


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

def divisor(n):
	ans = list()
	for i in range(1, n + 1):
		if n % i == 0:
			ans.append(i)
	return ans
for d in divisor(n):
	s = s[0:d][::-1] + s[d:]
print(s)


length = int(input())
line = list(input())
divisors = [i for i in range(1, length + 1) if length % i == 0]
for divisor in divisors:
	for i in range(divisor // 2):
		t = line[i]
		line[i] = line[divisor - i - 1]
		line[divisor - i - 1] = t
print(''.join(line))


def reverse(a, i):
	for j in range((i + 1) // 2):
		(a[j], a[i - j]) = (a[i - j], a[j])
n = int(input())
s = input()
a = list(s)
for i in range(2, n + 1):
	if n % i == 0:
		reverse(a, i - 1)
print(''.join(a))


n = int(input())
s = list(input())
for i in range(1, n + 1):
	if len(s) % i == 0:
		subS = s[0:i]
		subS.reverse()
		for j in range(i):
			s[j] = subS[j]
for i in range(n):
	print(s[i], end='')


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


import sys
n = int(sys.stdin.readline())
s = str(sys.stdin.readline())
for i in range(n):
	if n % (i + 1) == 0:
		start = s[:i + 1]
		end = s[i + 1:]
		s = start[::-1] + end
print(s)


def print_arr(arr):
	print(*arr, sep='')
(n, s) = (int(input()), input())
s_sort = list(s)
n_div = n // 2
for i in range(1, n_div + 1, 1):
	if n % i == 0:
		s_sort[0:i] = list(reversed(s_sort[0:i]))
s_sort = list(reversed(s_sort))
print_arr(s_sort)


lenght = int(input())
string = input()

def findAllDivisors(k):
	lst = []
	for i in range(1, k + 1):
		if k % i == 0:
			lst.append(i)
	return lst
lst = findAllDivisors(lenght)
for i in range(0, len(lst)):
	newStr = string[0:lst[i]]
	newStr = newStr[::-1]
	newStr1 = string[lst[i]:len(string)]
	string = newStr + newStr1
print(string)


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


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


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)
for i in range(0, len(div)):
	first = s[0:div[i]]
	sec = s[div[i]:]
	s = first[::-1] + sec
print(s)


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


import math
n = int(input())
s = str(input())
d = []
for x in range(1, int(n / 2) + 1):
	if n % x == 0:
		d.append(x)
d.append(n)
for x in range(0, len(d)):
	tmp = s[:d[x]]
	tmp1 = s[d[x]:]
	tmp = tmp[::-1]
	s = tmp + tmp1
print(s)


import sys
import math

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

def get_list():
	return list(get_ints())

def printspx(*args):
	return print(*args, end='')

def printsp(*args):
	return print(*args, end=' ')

def printchk(*args):
	return print(*args, end=' \\ ')
MODPRIME = int(1000000000.0 + 7)
BABYMODPR = 998244353
n = int(input())
s = input()
for i in range(n):
	if not n % (i + 1):
		s = s[:i + 1][::-1] + s[i + 1:]
print(s)


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


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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 main():
	n = int(input())
	s = str(input())
	d = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			d.append(i)
			if i * i != n:
				d.append(n // i)
	sd = sorted(d)
	for j in sd:
		s = s[:j][::-1] + s[j:]
	print(s[::-1])
main()


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


n = int(input())
string = list(input())
div = []
for i in range(2, n + 1):
	if n % i == 0:
		div.append(i)
for i in range(len(div)):
	temp = string[:div[i]]
	temp.reverse()
	for j in range(div[i]):
		string[j] = temp[j]
print(''.join(string))


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


input()
s = input()

def find_divisor(n):
	divisor = []
	for i in range(1, int(n ** (1 / 2)) + 1):
		if n % i == 0:
			divisor.append(i)
			divisor.append(n // i)
	return list(set(divisor))
divisor = find_divisor(len(s))
divisor.sort(reverse=False)
for i in divisor:
	manipulate = s[:i]
	s = manipulate[::-1] + s[i:]
print(s)


def rev(lst, s, e):
	lst[s:e] = lst[s:e][::-1]
	return lst
n = int(input())
l = [i for i in input()]
for i in range(1, n + 1):
	if n % i == 0:
		l = rev(l, 0, i)
print(''.join(l))