#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a;
  for (int i = 1; i <= n; i++)
    if (n % i == 0) a.push_back(i);
  for (int i = 1; i < a.size(); i++) {
    for (int j = 0; j < a[i] / 2; j++) swap(s[j], s[a[i] - j - 1]);
  }
  cout << s << endl;
  return 0;
}
