#include <bits/stdc++.h>
using namespace std;
void _init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  _init();
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> divisors;
  for (int i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      if (n / i == i)
        divisors.push_back(i);
      else {
        divisors.push_back(i);
        divisors.push_back(n / i);
      }
    }
  }
  sort(divisors.begin(), divisors.end());
  for (int i : divisors) {
    string temp = s.substr(0, i);
    reverse(temp.begin(), temp.end());
    for (int j = 0; j < temp.length(); ++j) {
      s[j] = temp[j];
    }
  }
  cout << s << endl;
  return 0;
}
