#include <bits/stdc++.h>
using namespace std;
string encrypt(string s, int n) {
  vector<int> div;
  string a, b;
  for (int i = 2; i < n; i++)
    if (n % i == 0) div.push_back(i);
  for (auto it : div) {
    a = s.substr(0, it);
    reverse(a.begin(), a.end());
    b = s.substr(it, n);
    s = a + b;
  }
  reverse(s.begin(), s.end());
  return s;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  cout << encrypt(s, n) << endl;
  return 0;
}
