2017 Multi-University Training Contest - Team 2 &&hdu 6050 Funny Function

Funny Function

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1109    Accepted Submission(s): 527

 

Sample Input
2
2 2
3 3
Sample Output
2 33
Source
 
生病了  找时间来解释
 1 #include<iostream>
 2 #include<cstdio>
 3 #include<algorithm>
 4 #include<cstring>
 5 #include<cstdlib>
 6 #include<string.h>
 7 #include<set>
 8 #include<vector>
 9 #include<queue>
10 #include<stack>
11 #include<map>
12 #include<cmath>
13 typedef long long ll;
14 typedef unsigned long long LL;
15 using namespace std;
16 const double PI=acos(-1.0);
17 const double eps=0.0000000001;
18 const int maxn=1000+10;
19 const int mod=1e9+7;
20 int pow_mod(ll a,ll b)
21 {
22     ll ans=1;
23     while(b)
24     {
25         if(b&1)ans=(ans*a)%mod;
26         a=(a*a)%mod;
27         b>>=1;
28     }
29     return ans;
30 }
31 int main() 
32 {
33     int t;
34     ll n,m;
35     scanf("%d",&t);
36     while(t--)
37     {
38         int x,y,ans;
39         scanf("%lld%lld",&n,&m);
40         if(m==1)printf("1\n");
41         else
42         {
43             x=pow_mod(3,mod-2);
44             //printf("%d\n",x);
45             y=(pow_mod(2,n)-1+mod)%mod;
46             y=pow_mod(y,m-1);
47             ans =(1ll*x*y*2)%mod;
48             if(n%2)
49             ans=(ans+x)%mod;
50         }
51         printf("%d\n",ans);
52     }
53     return 0;
54 }

 

posted on 2017-07-30 00:12  见字如面  阅读(152)  评论(0编辑  收藏  举报

导航