Hduoj 4506 Xiao Ming series story-Senior help "analysis test Instructions"

Source: Internet
Author: User

Xiao Ming Series Stories-Senior help

Description

Xiao Ming since farewell to Acm/icpc, began to devote himself to the study of mathematical problems, a can be prepared for the next examination, and can take this opportunity to help some students, especially the beautiful sister. This is not, the only girl in the class to take a math problem to ask Xiao Ming, xiaoming of course very happy to accept. But after he carefully read the question, found himself will not do, this next Xiao Ming? Tray to drink curled? replied that he did not understand, is not very face?
So, he is asking you to help solve this problem in private now, the topic is this:
Give you n numbers, respectively, are a1,a2,a3,a4,a5......an, these numbers will change every unit of time, assuming that the number of a unit time is A1 ', A2 ', A3 ' ... an ', then this unit time number a[i] = a[i-1] ' * K (i = = 1 when a [1] = A[n] ' * k), where k is the given coefficient.
Now, the question is, what is this n number when I ask for a unit of time? Since the numbers can be very large, so long as you output the number to 10^9 + 7 After the result of the remainder.

Input

Input data The first line is a positive integer t, indicating that there is a T group test data;
Each group of data has two lines, the first line contains input three integers n, t, K, where n is the number of digits, T is the T unit time, K is the coefficient, and the second line is the number of n digits AI, which represents how many times each number starts.

[Technical specification]
T <= 100
1 <= N <= 10 ^ 4
0 <= T <= 10 ^ 9 where t = 0 indicates the initial state
1 <= k <= 10 ^ 9
1 <= ai<= 10 ^ 9

Output

For each set of data, output the T-unit time after the N-number becomes what, when the output between each of the two numbersOutput a space, the end of the line do not output extra space, see the example.

Sample Input

23 2 51 2 33 0 51 2 3

Sample Output

50 75 251) 2 3

"Analysis" state transfer equation is a[i]==a[i-t]*k^t% mod; So the i-t>=1 and i-t<=1 two cases (starting from a[1] to store data) K^t can be obtained with the help of fast exponentiation.

It should be noted that when t>n, what to do???? First of all, the fast power can not be changed here, the following for the T in the loop in advance to the N modulus, in which reason does not need to be clear. AC Code:
1#include <cstdio>2 3 #defineLL Long Long4 #defineMoD 10000000075 intN, t, K;6LL a[10005], b[10005]; 7 8 ll Quick (ll A, ll b)9 {TenLL ans =1,Base= a%MoD; One      while(b) A     { -         if(B &1)  -Ans = (ans*Base) %MoD; the         Base= (Base*Base) %MoD; -b>>=1; -     } -     returnans; + } -  + intMain () A { at     intT;SCANF ("%d", &T); -      while(t--) -     {         -scanf" %d%d%d", &n, &t, &k); -          for(inti =1; I <= N; i++) -scanf"%lld", &a[i]); inLL cnt =Quick (k, t);  -T%=N; to          for(inti =1; I <= N; i++) +         { -             if(I-t >=1) theB[i] = (a[i-t] * cnt)%MoD;  *             Else $B[i] = (a[n+i-t] * cnt)%MoD;Panax Notoginseng         } -          for(inti =1; I < n; i++) theprintf"%lld", B[i]); +printf"%lld\n", B[n]); A     } the     return 0; +}

Hduoj 4506 Xiao Ming series story-Senior help "analysis test Instructions"

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.