#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int maxm = 1e6 + 10;
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-7;
int n;
char str[maxn];
int main() {
  cin >> n >> str;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      reverse(str, str + i);
    }
  }
  cout << str << endl;
}
