Reversing Encryption

A string ss of length nn can be encrypted(加密) by the following algorithm:

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

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

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

Input

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

Output

Print a string ss such that the above algorithm results in tt.

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的最小因子开始,反转从开始到因子的字符串。

之前做这道题的时候理解错意思了,一直以为是一半一半的反转字符串,很是可惜,没有做出来

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int main()
{
    int n,i;
    char s[110];
    scanf("%d",&n);
    getchar();
    scanf("%s",&s);
    for(i=1;i<=n;i++)
    {
        if(n%i==0)
        {
            reverse(s,s+i);
        }
    }
    printf("%s\n",s);
    return 0;
}

这里有我之前一篇关于字符串反转函数的博客

 1 #include<stdio.h>
 2 #include<string.h>
 3 #include<algorithm>
 4 using namespace std;
 5 int main()
 6 {
 7     int n,i,j,count;
 8     char s[110];
 9     int a[110];
10     scanf("%d",&n);
11     getchar();
12     scanf("%s",&s);
13     count=0;
14     for(i=1;i<=n;i++)
15     {
16         if(n%i==0)
17         {
18             a[count++]=i;///记录n因子
19         }
20     }
21     for(i=0;i<count;i++)
22     {
23         for(j=0;j<a[i]/2;j++)
24         {
25             swap(s[j],s[a[i]-j-1]);
26         }
27     }
28     printf("%s\n",s);
29     return 0;
30 }

原文地址:https://www.cnblogs.com/wkfvawl/p/9343465.html

时间: 2024-11-15 00:46:03

Reversing Encryption的相关文章

CF 999 B. Reversing Encryption

题目地址 分析: 规律:当i为n的倍数时,从0至i翻转(从前往后) 新知识: reverse(s+a,s+b);把字符串s中,地址从a到b间的内容反转 代码: 1 #include<iostream> 2 #include<algorithm> 3 #include<cstring> 4 using namespace std; 5 6 int main() 7 { 8 char s[105]; 9 int n; 10 cin >> n >> s

Codeforces Round #490 (Div. 3)

A.Mishka and Contest 思路:简单贪心.每次删掉首尾不超过k的元素,直到分别第一次遇到超过k的元素就不再继续删除即可. AC代码: 1 #include <cstdio> 2 #include <cstring> 3 #include <cstdlib> 4 #include <cmath> 5 #include <iostream> 6 #include <algorithm> 7 #include <iom

backup, file manipulation operations (such as ALTER DATABASE ADD FILE) and encryption changes on a database must be serialized.

昨天在检查YourSQLDba备份时,发现有台数据库做备份时出现了下面错误信息,如下所示: <Exec>   <ctx>yMaint.ShrinkLog</ctx>   <inf>Log Shrink</inf>   <Sql> --  ======================================================================== -- Shrink of log file E:\SQ

十三:Transparent Encryption in HDFS(转)

透明加密:http://blog.csdn.net/linlinv3/article/details/44963429 hadoop透明加密  kms 简介 Hadoop Key Management Server(KMS)是一个基于HadoopKeyProvider API编写的密钥管理服务器.他提供了一个client和一个server组件,client和server之间基于HTTP协议使用REST API通信.Client是一个KeyProvider的实现,使用KMS HTTP REST A

[JavaSecurity] - RSA Encryption

1. RSA Algorithm RSA is one of the first practical public-key cryptosystems and is widely used for secure data transmission. In such a cryptosystem, the encryption key (public key) is public and differs from the decryption key (private key) which is

AES advanced encryption standard 3

This optimized <../aesbench/> AES implementation conforms to FIPS-197. aes.h #ifndef _AES_H #define _AES_H #ifndef uint8 #define uint8 unsigned char #endif #ifndef uint32 #define uint32 unsigned long int #endif typedef struct { uint32 erk[64]; /* en

AES advanced encryption standard 2

/* * FIPS-197 compliant AES implementation * * Copyright (C) 2006-2007 Christophe Devine * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * * Redi

HNU 12888 Encryption(map容器)

题目链接:http://acm.hnu.cn/online/?action=problem&type=show&id=12890&courseid=274 解题报告:输入一个有n个单词的句子,然后再输入这n个单词对应的意思是什么,要你翻译出这个句子最后是什么. 一个裸的map 1 #include<cstdio> 2 #include<cstring> 3 #include<iostream> 4 #include<algorithm>

Unique Encryption Keys (思维题 预处理)

题目 题意:给m个数字, q次询问, 询问b到e之间如果有重复数字就输出, 没有就输出OK 思路:用f[i]数组 记录从i开始向后最近的有重复数字的 位置, 如 1 3 2 2, 则f[1] = 4; 如果离a最近的重复数字的位置 都大于b, 就说明没有重复数字. f[]数组需要预处理,从后向前. 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <vector>