Задача Dehash

Файл входного файла: dehash.in
Файл выходного файла: dehash.out
Ограничение по памяти: 64 MB
Ограничение по времени: 2 s

Описание

A `hash function is any well-defined procedure or mathematical function that converts a large, possibly variable-sized amount of data into a small datum, usually a single integer that may serve as an index to an array. The values returned by a hash function are called hash values, hash codes, hash sums, or simply hashes.

Hash functions are often used in to solve string problems.
Here is the one example of the function that gets a single integer (hash) from the sequence of digits and letters of the latin alphabet.

Pascal:


function gethash(t: ansistring): int64;
var
    i,j: longint;
begin
    result := 0;
    for i := 1 to length(t) do begin
        result := (result * 62) mod M;
        if t[i] in ['a'..'z'] then
                result := result + ord(t[i]) - ord('a');
        if t[i] in ['A'..'Z'] then
            result := result + ord(t[i]) - ord('A') + 26;
        if t[i] in ['0'..'9'] then
            result := result + ord(t[i]) - ord('0') + 52;
    end;
    result := result mod M;
end;

C:


long long gethash(string t)
{
    long long result = 0; 
    for (int i = 0; i < t.size(); i++) {
        result = (result * 62) % M;
        if (t[i] >= 'a' && t[i] <= 'z') result += t[i] - 'a';
        if (t[i] >= 'A' && t[i] <= 'Z') result += t[i] - 'A' + 26;
        if (t[i] >= '0' && t[i] <= '9') result += t[i] - '0' + 52;
    }
    return result % M;
}

In this problem you have to find the inverse function, i.e. the function that finds any sequence of alpha-numberic characters of latin alphabet of the length L such that its hash function is equal to H by modulo M .

Формат входных данных

The first and only line of the input file contains 3 integer numbers - L , H and M . ( 1 <= L <= 10 6 , 0 <= H < M, 1 <= M <= 10 16 ).

Формат выходных данных

Write "NO" (without quotes) in the first line of the output file if no string of the length L has the hash function equal to H modulo M . Otherwise the first line of the output file must contain word "YES" and the second line must contain the required string itself.

Примеры:

ввод вывод

9 790954381 1000000007

YES
zxcZXC193

Added: admin
Difficulty: 0.721944011165
Accepted: 1
Submitted: 2
Источник задачи: KBTU OPEN 2010 SPRING
Автор: Tulegenov Amir
Analyze this Discuss

Обсуждение:

Начать обсуждение:

Powered by django, eJudge.