[Uoj 74] "UR #6" crack password

Source: Internet
Author: User

Title Link: UOJ-74

Problem analysis

Topic, the first character of the string S is moved to the end, and the other characters move forward one position, and f (s) changes from Hi to hi+1.

Let's analyze this process: Suppose the first character is C, (hi-26^ (n-1) * C) * + + c = hi+1

* hi-hi+1 = (26^n-1) * C

c = (* hi-hi+1) * INV (26^n-1)

Then each C can be directly solved, because the topic guaranteed to have the solution, so each C solution out of must be [0, 25] number.

Well.. It looks very right. Submit up .... wa.50

Why do we have to have 50 points? because: " when there is division, be sure to consider the case of no inverse element!" "

When (26^n-1)% P = 0, the 26^n-1 is not inverse. This point has 5 "Qaq" in the data.

So in the preceding equation, hi-hi+1 = (26^n-1) * C has a term coefficient of 0, which is eliminated and becomes Hi * = hi+1.

Because the equation is not related to C, C is any one letter that can be set up.

Then we have to find this S from f (s) = Hi, we know that f (s) is equivalent to the string as a 26 binary number, then here's Hi * = hi+1.

So we think of H0 as a 26 binary number to find the corresponding string, then move left one is equivalent to the H by 26, still conforms to f (S) = hi+1.

Code
#include <iostream> #include <cstdlib> #include <cstdio> #include <cmath> #include <cstring > #include <algorithm>using namespace std;const int maxn = 100000 + 5;typedef long long ll;int N, p, T;int H[MAXN] ; LL A0, Temp; LL X[MAXN]; ll Pow (ll a, int b) {LL ret = 1, f = a;while (b) {if (b & 1) {ret *= f;ret%= p;} b >>= 1;f *= f;f%= p;} return ret;} ll NY (ll x) {x = ((x% p) + p)% P;return Pow (x, p-2);} int main () {scanf ("%d%d", &n, &p), for (int i = 0; i < n; ++i) scanf ("%d", &h[i]); if (Pow (26LL, n)! = 1) {Tem p = NY (Pow (26LL, N)-1), for (int i = 0; i < n; ++i) {if (i = = n-1) T = 0;else T = i + 1; X[i] = ((LL) h[i] *-(LL) h[t])% p * TEMP; X[i] = ((X[i]% p) + p)% p;}} Else{int Pos = N;while (H[0]) {X[--pos] = h[0]% 26; H[0]/= 26;}} for (int i = 0; i < n; ++i) printf ("%c", ' a ' + x[i]);p rintf ("\ n"); return 0;}

  

[Uoj 74] "UR #6" crack password

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.