#include <bits/stdc++.h>
using namespace std;
int n, m;
string s;
int main() {
  cin >> n >> s;
  s = 'F' + s;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      reverse(s.begin() + 1, s.begin() + i + 1);
    }
  }
  reverse(s.begin(), s.end());
  s.pop_back();
  reverse(s.begin(), s.end());
  cout << s;
}
