Test instructions
Give you a set of elements of 1 to n, so that you ask how many non-empty sets, the sum of the elements within the subset is an even number.
Analytical:
If the sum of the elements in a subset is even, the odd number in the geometry must be the same.
Then an even number of cases can be arbitrarily taken. A geometry that has n / 2 An even number, with < Span class= "Mrow" id= "mathjax-span-6794" > ( n + 1 span class= "Mo" id= "mathjax-span-6799" style= "Font-family:mathjax_main;" >) / 2 An odd number.
So the end result is ∑ < Span class= "Texatom" id= "mathjax-span-6808" >n / 2 i=1 C < Span class= "Mi" id= "mathjax-span-6824" style= "font-size:70.7%; Font-family:mathjax_math-italic; " >i n/2 ?< span class= "Mo" id= "mathjax-span-6834" style= "FONT-FAMILY:MATHJAX_SIZE1; Vertical-align:0.003em; " >∑ ( n + 1 ) Span class= "Texatom" id= "mathjax-span-6842" >/ 2 J=1 C J ( n + 1 ) Span class= "Texatom" id= "mathjax-span-6861" >/ 2 =2 n 1 ?1
Because the result is relatively large, so we need to use fast power to touch.
my code
#include <cstdio>#include <cstring>#include <algorithm>using namespace STD;typedef Long LongllConstll MOD =1000000007;intN;ll Modpow (ll A, ll K) {ll c =1; while(k) {if(K &1) C = (c*a)% MOD; A = (a*a)% MOD; K >>=1; }returnC;}intMain () {intTscanf("%d", &t); while(t--) {scanf("%d", &n);printf("%lld\n", Modpow (2, N-1) -1); }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 5363 Key Set (Fast power modulo)