【杭电】[5363]Key Set

文章字数:104

问题描述

问题分析

随便找下规律吧
答案是$2^{n-1}-1$
注意用快速幂时中间值溢出

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<stdio.h>
int MOD=1000000007;
int pow(int a,int b) {
    __int64 r=1,t=a%MOD;
    while(b) {
        if(b&1)
            r=r*t%MOD;
        t=t*t%MOD;
        b>>=1;
    }
    return (int)r;
}
int main() {
    int T;
    scanf("%d",&T);
    while(T--) {
        int n;
        scanf("%d",&n);
        printf("%d\n",pow(2,n-1)-1);
    }
    return 0;
}

该内容采用 CC BY-NC-SA 4.0 许可协议。

如果对您有帮助或存在意见建议,欢迎在下方评论交流。

加载中...