首页 > 其他 > 详细

Key Set HDU - 5363

时间:2019-07-20 00:29:21      阅读:107      评论:0      收藏:0      [点我收藏+]

这个题目套公式 2^(n-1)-1,再来个快速幂基本上就可以AC了

写这个题目的: 公式容易推到错: 容易写成 2^n-1/2。。。这样写出来结果也不错  但是一直哇

AC:

#include<iostream>
#include<cstdio>
#include<cstring> 
#define N 1000000007
using namespace std;
typedef long long ll;
int pow(ll x,ll y)
{
    ll res=1;
    while(y)
    {
        if(y&1)
            res = res * x %N;
        x = x * x % N;
        y>>=1;
    }
    return res-1;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        ll n,m;
        scanf("%lld",&n);
        m=pow(2,n-1);
        cout<<m<<endl; 
    }
}

 

Key Set HDU - 5363

原文:https://www.cnblogs.com/Accepting/p/11216062.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!