Xiao Ming series Stories--Senior help
Time limit:3000/1000 MS (java/others) Memory limit:65535/32768 K (java/others)
Total submission (s): 5427 Accepted Submission (s): 1461
Problem Description Xiao Ming since the farewell to ACM/ICPC, began to study mathematics problems, a can for the next grind to prepare, 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 small Ming embarrassed: If reply said oneself do 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 data The first line is a positive integer t, indicating that there is a T group of 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 outputs the T-unit time after which the n numbers become 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 Input23 2 51 2 33 0 51 2 3
Sample OUTPUT50 75 251 2 3 know that the loop section is N, fast power, and then output.
#include <stdio.h>#include<string.h>using namespaceStd;typedefLong LongLL;Const intN =10005;ConstLL mod =1000000007; LL A[n]; ll Pow_mod (ll a,ll N) {ll ans=1; while(n) {if(n&1) ans = a*ans%MoD; A= a*a%MoD; N>>=1; } returnans;}intMain () {inttcase; scanf ("%d",&tcase); intn,t; LL K; while(tcase--) {scanf ("%d%d%lld",&n,&t,&k); LL M=Pow_mod (k, (LL) t); for(intI=1; i<=n;i++) {LL val; scanf ("%lld",&val); A[i]= m*val%MoD; } intm = t%N; for(intI= (n-m+1); i<=n;i++) {printf ("%lld", A[i]); } for(intI=1; i<n-m+1; i++){ if(i!=n-m) printf ("%lld", A[i]); Elseprintf"%lld\n", A[i]); } }}
HDU 4506 (Math, follow link + fast power)