JZOJ4742 单峰

Description

Input

Output

Sample Input

2

Sample Output

2

Data Constraint

Solution

  打完暴力发现前几位的方案数时1,2,4,8,16......,直接快速幂。
 1 #include<cstdio>
 2 #define LL long long
 3 #define N 1000000007
 4 LL n;
 5 LL ksm(LL x){
 6     if (x==0) return 1;
 7     if (x==1) return 2;
 8     LL s=ksm(x/2);
 9     s*=s;
10     if (s>N) s%=N;
11     if (x%2==1) s*=2;
12     if (s>N) s%=N;
13     return s;
14 }
15 int main(){
16     scanf("%lld",&n);
17     LL ans=ksm(n-1);
18     printf("%lld\n",ans);
19 }
View Code

 

posted @ 2018-08-25 09:18  kasiruto  阅读(127)  评论(0编辑  收藏  举报