#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long> v;
  for (long long i = 1; i <= sqrt(n); i++) {
    if (n % i == 0) {
      if (n / i == i)
        v.push_back(i);
      else {
        v.push_back(i);
        v.push_back(n / i);
      }
    }
  }
  sort(v.begin(), v.end());
  string final = s;
  for (long long i = 0; i < v.size(); i++) {
    string s1 = final.substr(0, v[i]);
    reverse(s1.begin(), s1.end());
    string s2 = final.substr(v[i], n - v[i]);
    final = s1 + s2;
  }
  cout << final;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  for (long long i = 0; i < t; i++) solve();
  return 0;
}
