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
  1. 10
  2. rocesfedoc
Output
  1. codeforces
Input
  1. 16
  2. plmaetwoxesisiht
Output
  1. thisisexampletwo
Input
  1. 1
  2. z
Output
  1. z

Note

The first example is described in the problem statement.

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

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. char s[105];
  4. int main()
  5. {
  6. int n;
  7. while(~scanf("%d",&n))
  8. {
  9. getchar();
  10. scanf("%s",s);
  11. for(int i = 1; i < n ; i ++)
  12. {
  13. if(n % i == 0)
  14. {
  15. for(int j = 0; j < i / 2; j ++)
  16. {
  17. char op = s[j];
  18. s[j] = s[i - j - 1];
  19. s[i-j -1 ] = op;
  20. }
  21. }
  22. }
  23. for(int i = 0; i <=(n -1)/2; i ++)
  24. {
  25. char op = s[i];
  26. s[i] = s[n - i - 1];
  27. s[n - i - 1] = op;
  28. }
  29. printf("%s",s);
  30. printf("\n");
  31. }
  32. return 0;
  33. }

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. ASM实例修改SYS密码

    修改ASM实例中SYS用户密码 How To Change ASM SYS PASSWORD ? (文档 ID 452076.1) Oracle Database - Enterprise Editi ...

  2. axios全局配置及拦截器

    axios使用说明文档 axios 全局配置: //axios-init.js import axios from 'axios': let loadingInstance; //创建Loading ...

  3. [NOIP2018模拟赛10.20A]挂分报告

    闲扯 先看看了B组,T1 ZROI刚好讲过一个性质原根一般很小的,直接枚举;T2一眼二分然后似乎状压 T3没看 然后上来A组题,T1 flow这名字...网络流?! T1题面非常的社会主义核心价值观, ...

  4. 字蛛webfont 安装及使用方法

    先安装nodejs和git,比如放在D:/nodejs/  文件夹 cmd 进入该文件夹,安装npm install express 安装 npm install font-spider -g 安装  ...

  5. 关于微信小程序的父子组件互相传值

    一:父组件传值给子组件 1. 在父组件中引用子组件 1.1 在父组件json中导入子组件 1.2 在子组件的json中,把自己定义为子组件 2. 在父组件中,子组件的引用处,绑定一个属性( text ...

  6. MySql Host is blocked because of many connection errors 问题的解决方法

    错误日志: message from server: "Host '10.250.112.141' is blocked because of many connection errors; ...

  7. Go微服务 grpc/protobuf

    了解grpc/protobuf gRPC是一个高性能.通用的开源RPC框架,其由Google主要面向移动应用开发并基于HTTP/2协议标准而设计,基于ProtoBuf(Protocol Buffers ...

  8. 6.NIO2-Path、Paths、Files

    NIO.2 jdk1.7中,java对 NIO 极大的扩展,主要增强的是对文件处理 和 文件系统特性的支持 关于其中一些API的使用 public class TestNIO_2_Path_File ...

  9. linux命令返回值 / $?

    原文:http://blog.csdn.net/wyabc1986/article/details/7876673 在 Linux 下,不管你是启动一个桌面程序也好,还是在控制台下运行命令,所有的程序 ...

  10. stm32f429 仿真器不能识别芯片

    刚买的野火挑战者开发板,下载几次程序后,忽然就不能通过JLINK下载了,提示如下错误: No Cortex-M Device found in JTAG chain. Error: Flash Dow ...