1712: [Usaco2007 china]summing Sums Encryption

Source: Internet
Author: User

1712: [Usaco2007 china]summing Sums encryption time limit:5 Sec Memory limit:64 MB
submit:338 solved:127
[Submit] [Status] [Discuss] Description that n cute cows just learned many algorithms about passwords, and finally, they created the encryption method that belonged to the cows. Because they are not experienced, their encryption method is very simple: the first cow has the first number of the password, I start with Ci (0≤ci<90000000). When encrypting, the first cow calculates all the other cows ' numbers and And divide this number by 98765431 to take the remainder. After all cows have been counted, each cow will replace the number with its own number.    In other words, they have completed an encryption once. In November, the cows told Moose Carmen that the law of cryptography, Carmen was stunned. Then, in a fog-filled Christmas Eve, Carmen and the cows: "Your algorithm is very primitive, very easy to be cracked." So you have to repeat the encryption process T (1≤t≤1414213562) times to achieve the encryption effect. "It was a cow's turn to be shocked. It is clear that cows are particularly sick of doing the same boring thing many times. After a long debate, Carmen and the cows finally found the solution: You were just coming to encrypt the numbers. Input line 1th enters N and T, and then an integer of n lines per line represents the initial CI. The Output is a total of n rows, one integer per line, representing the CI after the T-session encryption. Sample Input 3 4
1
0
4

INPUT DETAILS:

Three cows, with starting numbers 1, 0, and 4; Four repetitions of the
Encryption algorithm.
Sample Output 26
25
29

OUTPUT DETAILS:

The following is a table of the cows ' numbers for each turn:

Cows ' numbers
Turn Cow1 Cow2 Cow3
0 1 0 4
1 4 5 1
2 6 5 9
3 14 15 11
4 26 25 29
HINT Source

Gold

Key: In fact, directly according to the original test instructions hand push, it is not difficult to find the law, in fact, this is mainly by a geometric series and composition, and other not difficult, push and push can

I.. Incredibly the number of the mold to start as 987654321, the results also cost a half a day to seek Phi, but also WA off the TT, and then found that the title of 98765431 is a prime TT, other really did not, feel avoid the examination room again tease than TT

1 Constp=98765431;2 var3 I,j,k,l,m,n:longint;4 Sum,a1,a2,a3,a4:int64;5A:Array[0..1000000] ofInt64;6 functionKSM (X,y:int64): Int64;7          varZ:int64;8          begin9               ify=0  ThenExit1);Ten               ify=1  ThenExit (xMoDp); OneZ:=KSM (x, yDiv 2)MoDp; Az:= (Z*z)MoDp; -               ifOdd (Y) Thenz:= (z*x)MoDp; - exit (z); the          End; - functionTrans (X:int64): Int64; -          begin -               ifx>=0  ThenExit (xMoDp); +x:= (x+ (ABS (x)Divp+1) *p)MoDp; - exit (x); +          End; A begin at readln (n,m); -       fori:=1  toN Doreadln (A[i]); -sum:=0; -       fori:=1  toN Do -          begin -A[i]:=a[i]MoDp; inSum:= (Sum+a[i])MoDp; -          End; toA1:= (1-KSM (1-n,m)); +A1:= ((SUM*A1)MoDp); -A1:= (KSM (n,p-2) *a1)MoDp; theA2:=KSM (-1, m+1); *       fori:=1  toN DoWriteln (Trans (a2* (a1-A[i] )); $ Readln;Panax Notoginseng End.

1712: [Usaco2007 china]summing Sums Encryption

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.