#include <bits/stdc++.h>
using namespace std;
int main() {
  char s[999999];
  int n;
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) reverse(s, s + i);
  }
  cout << s << endl;
  return 0;
}
