#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  for (long long i = 1; i <= n; i++)
    if (!(n % i)) reverse(s.begin(), (s.begin() + i));
  cout << s << "\n";
  return 0;
}
