#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 10;
int curr[N] = {0};
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, i;
  vector<long long int> v;
  cin >> n;
  string s;
  cin >> s;
  for (i = 2; i <= n / 2; i++) {
    if (n % i == 0) v.push_back(i);
  }
  for (i = 0; i < v.size(); i++) {
    reverse(s.begin(), s.begin() + v[i]);
  }
  reverse(s.begin(), s.end());
  cout << s;
  return 0;
}
