hdu4506 Xiao Ming series Stories--Senior help (regular simulation + fast Power)

Source: Internet
Author: User

problem Description
http://acm.hdu.edu.cn/showproblem.php?pid=4506
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 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.
 InputInput 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
 Outputfor each set of data output T unit time after this n number into what, the output when the output of a space between every two digits , 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
Topic Analysis: See Code comments

AC Code:
/** * @xiaoran * fast power problem, equivalent to a[i]=a[i-1]* (k^t)%mod * There are: The final sequence is a[i]=a[i]* (k^t)%mod composition, * Manual simulation will know the position of the output, for 3 2 5 k^t=25 *   Into sequence: 1 2 3 * sequence after direct operation: 25 75 50 * Manual Simulation Results * First: 15 5 10 * Second: 50 75 25 * Compared with direct results, you need to move the top left t=2 bit * so you can directly derive the sequence composition, output a[(i-t+n)%n] */#include <iostream> #include <cstdio> #include <map> #include <cstring> #include <string > #include <algorithm> #include <queue> #include <vector> #include <stack> #include < cstdlib> #include <cctype> #include <cmath> #define LL long long#define MOD 1000000007using namespace std; LL a[10005],b[10005];    ll Qpow (ll A,ll b) {//a^b non-recursive if (b==0) return 1;    LL Res=1,tp=a;        while (b) {if (b&1) RES*=TP;        Res%=mod;        b=b>>1;    tp= (TP*TP)%mod; } return res%mod;}    ll Qpow1 (ll A,ll b) {//a^b recursive LL t = 1;    if (b = = 0) return 1;    if (b = = 1) return a%mod;    t = Qpow1 (A, b>>1);    t = t*t% MOD;    if (b&1) {//b is an odd t = t*a% MOD; } return t;} int MAIn () {int n,c;    LL k,t;    Cout<<qpow (2,3) <<endl;    scanf ("%d", &c);        while (c--) {scanf ("%d%lld%lld", &n,&t,&k);        LL Tmp=qpow (k,t);        LL Tmp=qpow1 (k,t);            for (int i=0;i<n;i++) {scanf ("%lld", &a[i]);        a[i]=a[i]*tmp%mod;//gets the last sequence set} t=t%n;        printf ("%lld", a[(0-t+n)%n]);        for (int i=1;i<n;i++) {printf ("%lld", a[(i-t+n)%n]);    } printf ("\ n"); }return 0;}



hdu4506 Xiao Ming series Stories--Senior help (regular simulation + fast Power)

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.