HDU 5363 Key Set (Fast power modulo)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.