码迷,mamicode.com
首页 > 其他好文 > 详细

Key Set HDU - 5363

时间:2019-07-19 23:59:50      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:typedef   ace   code   pac   lld   fine   --   pre   def   

这个题目套公式 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

标签:typedef   ace   code   pac   lld   fine   --   pre   def   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!