#include <bits/stdc++.h>
using namespace std;
const long double PI = 3.141592653589793;
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  for (long long i = 0; i < n; i++) {
    if (n % (i + 1) == 0) {
      string c;
      for (long long j = 0; j <= i; j++) c += s[j];
      reverse(c.begin(), c.end());
      for (long long j = 0; j <= i; j++) s[j] = c[j];
    }
  }
  cout << s << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cout << fixed << setprecision(13);
  ;
  long long T;
  T = 1;
  while (T--) solve();
  return 0;
}
