#include <bits/stdc++.h>
#pragma GCC optimize("-Ofast")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")
#pragma GCC optimize("-funroll-all-loops,-fpeel-loops,-funswitch-loops")
using namespace std;
long long read() {
  long long a = 0;
  char b = 1, c;
  do
    if ((c = getchar()) == 45) b = -1;
  while (c < 48 || c > 57);
  do a = (a << 3) + (a << 1) + (c & 15);
  while ((c = getchar()) > 47 && c < 58);
  return a * b;
}
void write(long long x) {
  if (x < 0) putchar('-'), x = -x;
  char a[10], s = 0;
  do a[s++] = x % 10 | 48;
  while (x /= 10);
  do putchar(a[--s]);
  while (s);
}
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> v;
  for (int i = 2; i <= n; ++i) {
    if (n % i == 0) v.push_back(i);
  }
  int it = 0;
  while (it < v.size()) {
    reverse(s.begin(), s.begin() + v[it]);
    ++it;
  }
  cout << s;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
