B - Reversing Encryption

A string s of length n can be encrypted by the following algorithm:

  • iterate over all divisors of n in decreasing order (i.e. from n to 1),
  • for each divisor d, reverse the substring s[1…d] (i.e. the substring which starts at position 1 and ends at position d).

For example, the above algorithm applied to the string s="codeforces" leads to the following changes: "codeforces" → "secrofedoc" → "orcesfedoc" → "rocesfedoc" →"rocesfedoc" (obviously, the last reverse operation doesn't change the string because d=1).

You are given the encrypted string t. Your task is to decrypt this string, i.e., to find a string s such that the above algorithm results in string t. It can be proven that this string s always exists and is unique.

Input

The first line of input consists of a single integer n (1≤n≤100 ) — the length of the string t. The second line of input consists of the string t. The length of tis n, and it consists only of lowercase Latin letters.

Output

Print a string s such that the above algorithm results in t.

Examples

Input
10
rocesfedoc
Output
codeforces
Input
16
plmaetwoxesisiht
Output
thisisexampletwo
Input
1
z
Output
z

Note

The first example is described in the problem statement.

题目的意思就是例子里面写的那样,已知这个字符串的长度为n,如果一个数d为它的因子,那么从1到d都要逆序(字符串从1开始计数),将所有的因子求出,依次进行逆序就可以了,但是要注意的是,这里是从最小的因子开始逆序。

#include <bits/stdc++.h>

using namespace std;

char s[105];
int main()
{
int n;
while(~scanf("%d",&n))
{
getchar();
scanf("%s",s);
for(int i = 1; i < n ; i ++)
{
if(n % i == 0)
{
for(int j = 0; j < i / 2; j ++)
{
char op = s[j];
s[j] = s[i - j - 1];
s[i-j -1 ] = op;
}
}
}
for(int i = 0; i <=(n -1)/2; i ++)
{
char op = s[i];
s[i] = s[n - i - 1];
s[n - i - 1] = op;
}
printf("%s",s);
printf("\n");
}
return 0;
}

CodeForces - 999B Reversing Encryption的更多相关文章

  1. CF 999B. Reversing Encryption【模拟/string reverse】

    [链接]:CF [代码]: #include<bits/stdc++.h> #define PI acos(-1.0) #define pb push_back #define F fir ...

  2. Reversing Encryption(模拟水题)

    A string ss of length nn can be encrypted(加密) by the following algorithm: iterate(迭代) over all divis ...

  3. CF999B Reversing Encryption 题解

    Content 给一个长度为 \(n\) 的字符串 \(s\),执行以下操作: 降序遍历 \(n\) 的所有因子(从 \(n\) 到 \(1\)). 对于每一个因子 \(i\) 翻转字符串 \(s_{ ...

  4. Codeforces Round #490 (Div. 3)

    感觉现在\(div3\)的题目也不错啊? 或许是我变辣鸡了吧....... 代码戳这里 A. Mishka and Contes 从两边去掉所有\(≤k\)的数,统计剩余个数即可 B. Reversi ...

  5. [Codeforces]Codeforces Round #490 (Div. 3)

    Mishka and Contest #pragma comment(linker, "/STACK:102400000,102400000") #ifndef ONLINE_JU ...

  6. Codeforces 958C3 - Encryption (hard)

    C3 - Encryption (hard) 思路: 记sum[i]表示0 - i 的和对 p 取模的值. 1.如果k * p > n,那么与C2的做法一致,O(k*p*n)复杂度低于1e8. ...

  7. Codeforces 958C3 - Encryption (hard) 区间dp+抽屉原理

    转自:http://www.cnblogs.com/widsom/p/8863005.html 题目大意: 比起Encryption 中级版,把n的范围扩大到 500000,k,p范围都在100以内, ...

  8. Encryption (hard) CodeForces - 958C3 (树状数组)

    大意: 给定序列$a$, 要求将$a$分成$k$个非空区间, 使得区间和模$p$的和最小, 要求输出最小值. $k$和$p$比较小, 直接暴力$dp$, 时间复杂度是$O(nklogp)$, 空间是$ ...

  9. Codeforces Gym 100015H Hidden Code 暴力

    Hidden Code 题目连接: http://codeforces.com/gym/100015/attachments Description It's time to put your hac ...

随机推荐

  1. React-intl相关使用介绍

    React-intl用于国际化react组件,提供react组件和api来格式化日期.数字,字符等等.其中一个很重要的功能是实现文本翻译,将你所做的中文版应用所有文字转为英文. 关于配置什么的,请参照 ...

  2. 情感交流篇:HTML页面如何与后端联系

    通过ajax get方法: 基本格式:$.get("后台一般处理程序文件路径",{传值,格式为  KEY:VULES},function(后台返回值){接到后台数据后处理}); $ ...

  3. VUE.js devtool 安装简易教程(转)

    最简便的方法是用FQ来通过google应用商店进行安装,但是大多数人还是处在非FQ的状态 尝试过安装Node的方法来安装,但是极其不建议用这个方法安装,非常麻烦,而且必须要有node的基础,非常不接地 ...

  4. ubuntu16.04 一键安装nginx-rtmp

    给nginx加rtmp协议,网上写的都是重新编译安装,这样会比较麻烦,编译的时候会报很多依赖缺失的问题,这个其实是可以通过apt-get一键安装 参考:https://blog.csdn.net/ka ...

  5. js中prototype与__proto__的关系详解

    一.构造函数: 构造函数:通过new关键字可以用来创建特定类型的对象的函数.比如像Object和Array,两者属于内置的原生的构造函数,在运行时会自动的出现在执行环境中,可以直接使用.如下: var ...

  6. vue + element-ui 国际化实现

    1. 安装组件和插件 cnpm i element-ui -S // 安装elementcnpm i vue-i18n -S //安装i18n 2.将国际化资源放在assets目录下 3.在src下新 ...

  7. MUI顶部导航布局

    一.头部 核心css mui-bar mui-bar-nav <header class="mui-bar mui-bar-nav"> <a class=&quo ...

  8. Oracle学习笔记——Linux下开启Oracle

    1.开启数据库 sqlplus  /  as sysdba startup 2.启动监听:lsnrctl  start; 查看监听状态:lsnrctl status; 3.登入数据库 Linux 设置 ...

  9. SmartBinding工作原理分析

    关于kbmMW SmartBinding,我翻译了作者写的几篇文章,其强大的绑定机制,将可视控制与各种数据源灵活绑定在一起,实现了类似DBEdit数据敏感控件的效果,可以及大的减少我们的代码,实现界面 ...

  10. curl函数错误码对照信息表