HDU4506+快速求幂

solve(a,b,c)=a^b%c

View Code
 1 /*

 2 快速求幂

 3 solve(a,b,c)==a^b%c

 4 */

 5 #include<stdio.h>

 6 #include<string.h>

 7 #include<stdlib.h>

 8 #include<algorithm>

 9 #include<iostream>

10 #include<queue>

11 #include<math.h>

12 using namespace std;

13 typedef __int64 int64;

14 const int maxn = 10005;

15 const int64 mod = 1000000007;

16 int64 a[ maxn ],b[ maxn ];

17 int solve( int64 m,int64 n,int64 mod ){

18     int sum = 1;

19     while( n>=1 ){

20         if( n%2==1 ){

21             sum = sum*m%mod;

22         }

23         m = m*m%mod;

24         n/=2;

25     }

26     return sum%mod;

27 }    

28 int main(){

29     int ca;

30     scanf("%d",&ca);

31     while( ca-- ){

32         int n;

33         int64 t,k;

34         scanf("%d%I64d%I64d",&n,&t,&k);

35         for( int i=0;i<n;i++ )

36             scanf("%I64d",&a[ i ]);

37         int64 t1,t2;

38         t1=t/n;

39         t2=t%n;

40         int64 tt = solve( k,t,mod );

41         for( int i=0;i<n;i++ ){

42             if( t2<= i ) b[ i ] = a[ i-t2 ]*tt%mod;

43             else b[ i ] = a[ n-( t2-i ) ]*tt%mod;

44         }

45         for( int i=0;i<n;i++ )

46             if( i==0 ) printf("%d",b[ i ]);

47             else printf(" %d",b[ i ]);

48         printf("\n");

49     }

50     return 0;

51 }

 

 

你可能感兴趣的:(HDU)