#include <bits/stdc++.h>
using namespace std;
long long n;
string s, t;
int main() {
  ios_base::sync_with_stdio(false);
  long long precision = numeric_limits<long double>::digits10;
  cin >> n >> s;
  t = s;
  for (long long i = 1; i <= n; i++) {
    if (n % i == 0) {
      string temp = t.substr(0, i);
      for (long long j = 0; j <= i - 1; j++) t[j] = temp[i - 1 - j];
    }
  }
  cout << t << "\n";
}
