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