#include <bits/stdc++.h>
using namespace std;
void solve(string& s, int r) {
  int n;
  if (r % 2 == 0)
    n = (r / 2) - 1;
  else
    n = (r / 2);
  for (int i = 0; i <= n; i++) {
    swap(s[i], s[r - i - 1]);
  }
}
int main() {
  int n;
  string s;
  scanf("%d", &n);
  cin >> s;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) solve(s, i);
  }
  cout << s << endl;
}
