Secret Code
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others) total submission (s): 670 Accepted S Ubmission (s): 109
Problem DescriptionThe sarcophagus itself is locked by a secret numerical code. When somebody wants to open it, he must know the code and set it exactly on the top of the sarcophagus. A very intricate mechanism then opens the cover. If an incorrect code was entered, the tickets inside would catch fire immediately and they would has been lost forever. The code (consisting of up to integers) is hidden in the Alexandrian Library but unfortunately, as you probably know, The library burned down completely.
But an almost unknown archaeologist have obtained a copy of the code something during the 18th century. He was afraid, the code could get to the "wrong people" so he had encoded the numbers in a very special. He took a random complex number B that is greater (in absolute value) than any of the encoded numbers. Then he counted the numbers as the digits of the system with basis B. That's means the sequence of numbers an, an-1, ..., A1, A0 was encoded as the number X = a0 + a1b + a2b2 + ... + anbn.
Your goal is to decrypt the secret code, i.e. to express a given number X in the number system to the base B. In other words, given the numbers X and byou is to determine the "digit" a0 through an.
Inputthe input consists of T test cases. The number of them (T) is given in the first line of the input file. Each test case consists of one single line containing four integer numbers Xr, Xi, Br, Bi (| xr|,| xi| <= 1000000, | br|,| bi| <= 16). These numbers indicate the real and complex components of numbers x and B, i.e. x = Xr + i.xi, B = Br + i.bi. B is the basis of the system (| b| > 1), X is the number of you and has to express.
Outputyour program must, output A, single, line, test case. The line should contain the "digits" an, an-1, ..., A1, A0, separated by commas. The following conditions must be satisfied:For all I in {0, 1, 2, ... n}: 0 <= ai < | b| X = a0 + a1b + a2b2 + ... + anbn if n > 0 then an <> 0 n <= If there is no numbers me Eting these criteria, output the sentence "The code cannot be decrypted." If There is more possibilities, print any of them.
Sample input4-935 2475-11-151 0-3-293 16 3 2191-192 11-12
Sample output8,11,181the code cannot be decrypted.16,15
1#include <stdio.h>2#include <string.h>3 Const intM =5000000 ;4 typedef __int64 LL;5 ll XR, xi, BR, BI;6 intN;7 ll INI;8 ll A[m];9 ll T;Ten One BOOLDFS (ll L, LL R,intDEP) A { - if(Dep > -)return false ; - if(L = =0&& r = =0) { then =DEP; - return true ; - } - ll al, AR; + for(inti =0; I * i < INI; i + +) { -Al = L-i; AR =R; + if((((1LL * Al * br + 1ll *ar * bi)% t) = =0&& ((1ll *ar * br-1ll * al * bi)% t) = =0 ) { AA[DEP] =i; at if(Dfs ((((1LL * Al * br + 1ll * ar * bi)/t), (((1LL * ar * br-1ll * al * bi)/t), DEP +1) ) - return true ; - } - } - return false ; - } in - intMain () to { + //freopen ("A.txt", "R", stdin); - ll T; thescanf ("%i64d", &T); * while(T--) { $scanf ("%i64d%i64d%i64d%i64d", &XR, &xi, &BR, &bi);Panax Notoginsengt = br * BR + bi *bi; -INI = br * br + bi *bi; the if(Dfs (XR, XI,0) ) { + if(n = =0) puts ("0") ; A Else { the for(inti = n-1; I >=0; I--) printf ("%i64d%c", a[i], i = =0?'\ n':',') ; + } - } $ ElsePuts ("The code cannot be decrypted.") ; $ } - return 0 ; -}
View Code
Qin Jiushao algorithm:
In General, the evaluation of a unary n-th polynomial needs to undergo [n (n+1)]/2 and N-times addition, whereas the Qin Jiushao algorithm requires only n multiplication and n-th addition. At the time of manual calculation, the operation process is greatly simplified. put an n-th polynomialRewrite it in the following form:when you find the value of a polynomial, first calculate the value of the first polynomial within the inner parentheses, i.e.the values of the polynomial are then computed by the inward and outer layers, i.e.In this way, the value of the n-th polynomial f (x) is converted to the value of the N-once polynomial.
Conclusion: For an n-th polynomial, at most, do n multiplication and N-time addition. (When the highest-order coefficients are not 1 o'clock for n-times and N-Times, when the highest-order coefficients are 1 o'clock, respectively, n-1 multiplication, N-time addition.) )
Complex Division operations:
set Complex A + bi, C + di;
T = c * C + d * D;
then (a + bi)/(c + di) = (AC + BD)/T + (BC-AD)/t * i;
Hdu.1111.secret Code (Dfs + qin Jiushao algorithm)