#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = (long long)1000000007 * 1000000007;
const double EPS = 1e-9;
const long double eps = 1e-8;
const long double pi = acos(-1.0);
int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) {
      reverse(s.begin(), s.begin() + i);
    }
  }
  cout << s << endl;
  return 0;
}
