HDU 5363 Key Set(快速幂取余)

Key Set

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)

Total Submission(s): 362    Accepted Submission(s): 238

Problem Description

soda has a set S with n integers {1,2,…,n}.
A set is called key set if the sum of integers in the set is an even number. He wants to know how many nonempty subsets of S are
key set.

Input

There are multiple test cases. The first line of input contains an integer T (1≤T≤105),
indicating the number of test cases. For each test case:

The first line contains an integer n (1≤n≤109),
the number of integers in the set.

Output

For each test case, output the number of key sets modulo 1000000007.

Sample Input

4
1
2
3
4

Sample Output

0
1
3
7

Source

2015 Multi-University Training Contest 6

题目链接:点击打开链接

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
__int64 f( __int64 n,__int64 m,__int64 s)
{
    __int64 t;
    n=n%s;
    t=1;
    if(n==0)return 0;
    while(m)
    {
        if(m%2==1)
        {
            t*=n;
            t%=s;
        }
        n*=n;
        n%=s;
        m/=2;
    }
    return t;
}
int main()
{
    __int64 n,i,x;
    scanf("%I64d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%I64d",&x);
        if(x==1)
        {
            printf("0\n");
            continue;
        }

       __int64 t=f(2,x-1,1000000007);
       printf("%I64d\n",t-1);
    }

}

版权声明:本文为博主原创文章,如有特殊需要请与博主联系 QQ : 793977586。

时间: 2024-08-23 06:22:28

HDU 5363 Key Set(快速幂取余)的相关文章

HDU 5363 Key Set(快速幂取模)

Key Set Problem Description soda has a set $S$ with $n$ integers $\{1, 2, \dots, n\}$. A set is called key set if the sum of integers in the set is an even number. He wants to know how many nonempty subsets of $S$ are key set. Input There are multipl

hdu 5363 Key Set 快速幂

Problem Description soda has a set S with n integers {1,2,…,n}. A set is called key set if the sum of integers in the set is an even number. He wants to know how many nonempty subsets of S are key set. Input There are multiple test cases. The first l

hdu 2817 A sequence of numbers(快速幂取余)

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2817 题目大意:给出三个数,来判断是等差还是等比数列,再输入一个n,来计算第n个数的值. 1 #include <iostream> 2 #include <cstdio> 3 #include <cmath> 4 #define m 200907 5 6 using namespace std; 7 8 __int64 fun(__int64 j,__int64 k) 9

HDU1061_Rightmost Digit【快速幂取余】

Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 33161    Accepted Submission(s): 12696 Problem Description Given a positive integer N, you should output the most right digit of

hdu 3221 Brute-force Algorithm(快速幂取模,矩阵快速幂求fib)

http://acm.hdu.edu.cn/showproblem.php?pid=3221 一晚上搞出来这么一道题..Mark. 给出这么一个程序,问funny函数调用了多少次. 我们定义数组为所求:f[1] = a,f[2] = b, f[3] = f[2]*f[3]......f[n] = f[n-1]*f[n-2].对应的值表示也可为a^1*b^0%p,a^0*b^1%p,a^1*b^1%p,.....a^fib[n-3]*b^fib[n-2]%p.即a,b的指数从n=3以后与fib数列

poj 1845 Sumdiv (同余定理,快速幂取余)

链接:poj 1845 题意:求A^B的所有因子的和对9901取余后的值 如:2^3=8,8的因子有 1,2,4,8,所有和为15,取余后也是15 应用定理主要有三个: (1)整数的唯一分解定理: 任意正整数都有且只有一种方式写出其素因子的乘积表达式. A=(p1^k1)*(p2^k2)*(p3^k3)*....*(pn^kn)   其中pi均为素数 (2)约数和公式: 对于已经分解的整数A=(p1^k1)*(p2^k2)*(p3^k3)*....*(pn^kn) 有A的所有因子之和为 S = 

快速幂取余 [转]

转自: http://blog.csdn.net/acm_code/article/details/38270829 求a^b mod c 算法1. 首先直接地来设计这个算法: int ans=1, i; for(i=1;i<=b;i++) ans*=a; ans%=c; 这个算法的时间复杂度体现在for循环中,为O(b). 这个算法存在着明显的问题,如果a和b过大,很容易就会溢出. 那么,我们先来看看第一个改进方案:在讲这个方案之前,要先有这样一个公式: a^b mod c=(a mod c)

LightOJ - 1282 - Leading and Trailing(数学技巧,快速幂取余)

链接: https://vjudge.net/problem/LightOJ-1282 题意: You are given two integers: n and k, your task is to find the most significant three digits, and least significant three digits of nk. 思路: 后三位快速幂取余,考虑前三位. \(n^k\)可以表示为\(a*10^m\)即使用科学计数法. 对两边取对数得到\(k*log

快速幂取余算法

下面是一个快速幂的介绍: 先贴一个秦九韶算法(Horner算法)的原理: 设有项的次函数 将前项提取公因子,得 再将括号内的前项提取公因子,得 如此反复提取公因子,最后将函数化为 令 ...... 则即为所求 下面是讲解快速幂的:(By  夜せ︱深   感谢作者) 快速幂取模算法 在网站上一直没有找到有关于快速幂算法的一个详细的描述和解释,这里,我给出快速幂算法的完整解释,用的是C语言,不同语言的读者只好换个位啦,毕竟读C的人较多~ 所谓的快速幂,实际上是快速幂取模的缩写,简单的说,就是快速的求