#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 20;
const int MOD = 1e9 + 7;
priority_queue<pair<long long int, int> > pq;
vector<pair<long long int, long long int> > vp;
map<long long int, long long int> mp, mpp;
long long int dp[N];
vector<long long int> v, v1, v2;
stack<long long int> s, s1;
long long int visit[N];
struct domingo {
  int val, left, right;
} o[N];
long long int BIT[N];
long long int seg_tree[4 * N];
set<long long int> se[250];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, m, val, k, d, mi = 1e9, mx(0);
  long long int sum(0), ct(0), p(0), q(0);
  string s;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    if (n % i == 0) v.push_back(i);
  }
  cin >> s;
  for (int i = 0; i < v.size(); i++) {
    string t = s.substr(0, v[i]);
    reverse(t.begin(), t.end());
    for (int j = 0; j < v[i]; j++) {
      s[j] = t[j];
    }
  }
  cout << s;
}
