http://www.elijahqi.win/archives/3817
题目描述
A string
s
s of length
n
n can be encrypted by the following algorithm:
iterate over all divisors of
n
n in decreasing order (i.e. from n
n to 1
1 ),
for each divisor
d
d , reverse the substring s[1 \dots d]
s[1…d] (i.e. the substring which starts at position 1
1 and ends at position d
d ).
For example, the above algorithm applied to the string
s
s =”codeforces” leads to the following changes: “codeforces”
\to
→ “secrofedoc”
\to
→ “orcesfedoc”
\to
→ “rocesfedoc”
\to
→ “rocesfedoc” (obviously, the last reverse operation doesn’t change the string because
d=1
d=1 ).
You are given the encrypted string
t
t . Your task is to decrypt this string, i.e., to find a string
s
s such that the above algorithm results in string
t
t . It can be proven that this string
s
s always exists and is unique.
输入输出格式
输入格式:
The first line of input consists of a single integer
n
n (
1 \le n \le 100
1≤n≤100 ) — the length of the string
t
t . The second line of input consists of the string
t
t . The length of
t
t is
n
n , and it consists only of lowercase Latin letters.
输出格式:
Print a string
s
s such that the above algorithm results in
t
t .
输入输出样例
输入样例#1: 复制
10
rocesfedoc
输出样例#1: 复制
codeforces
输入样例#2: 复制
16
plmaetwoxesisiht
输出样例#2: 复制
thisisexampletwo
输入样例#3: 复制
1
z
输出样例#3: 复制
z
说明
The first example is described in the problem statement.
reverse 末端指针+1
#include<bits/stdc++.h>
using namespace std;
char s[110];
int main(){
// freopen("b.in","r",stdin);
int n;scanf("%d",&n);
scanf("%s",s+1);
for (int i=1;i<=n;++i){
if (n%i) continue;
reverse(s+1,s+i+1);
}
printf("%s",s+1);
return 0;
}