#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  char s[n + 1];
  cin >> s;
  for (int i = 2; i <= n; i++)
    if (n % i == 0) {
      reverse(s, s + i);
    }
  cout << s << "\n";
}
