JZOJ 3013. filling board

topic

Description

A horizontal stroke a vertical stroke, a horizontal stroke, vertical stroke a small ............ R n * m shown a board.

Since NOIP is coming, small R has a fantastic idea.

Fill a N, O, I, P four letters in each of the small checkerboard, if each of the board 2 * 2 have little chessboard N, O, I, P four letters, small R to think this board is lucky chessboard. R would like to know a little how many different lucky board total. Because of this result may be large, you only need the output value of the modulo 1,000,000,007.
 

Input

Two integers n, m represents the size of the board.

Output

Fortunately, a number of board integer of a value obtained by modulo 1,000,000,007.

 

Sample Input

2 3

Sample Output

48
 

Data Constraint

 
 

Hint

For 30% of the data, n, m≤10

For 70% of the data, n, m≤1,000,000

To 100% of the data, 2≤n, m≤2,000,000,000

 

analysis

 

  • Obviously, we first starting 2 * 2 * 2 on every down, left * 2
  • The down for such numbers will be defined, so do not control
  • And then went to repeat 24

Code

 1 #include<iostream>
 2 #define mod 1000000007
 3 using namespace std;
 4 long long ksm(long long a,long long b)
 5 {
 6     long long x=a,ans=1;
 7     while (b)
 8     {
 9         if (b&1!=0) ans=ans*x%mod;
10         x=x*x%mod;
11         b>>=1;
12     }
13     return ans%mod;
14 }
15 int main ()
16 {
17     long long n,m;
18     cin>>n>>m;
19     long long a=ksm(2,n-1),b=ksm(2,m-1);
20     cout<<(a+b-2)*12%mod;  
21 }

 

 

Guess you like

Origin www.cnblogs.com/zjzjzj/p/11134902.html