日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【 HDU - 5363】Key Set(水题,快速幂,组合数学)

發布時間:2023/12/10 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【 HDU - 5363】Key Set(水题,快速幂,组合数学) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

soda has a set?SS?with?nn?integers?{1,2,…,n}{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?SS?are key set.

Input

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

The first line contains an integer?nn?(1≤n≤109)(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

解題報告:

? ?這應該算是多校里面的大水題了吧?(ps:當時寫的快速冪也太丑陋了吧、、、)

因為集合S中的元素是從1開始的連續的自然數,所以所有元素中奇數個數與偶數個數相同,或比偶數多一個。另外我們要知道偶數+偶數=偶數,奇數+奇數=偶數,假設現在有a個偶數,b個奇數,則

根據二項式展開公式

以及二項式展開式中奇數項系數之和等于偶數項系數之和的定理

可以得到

最后的結果還需減去

即空集的情況,因為題目要求非空子集

所以最終結果為

部分題解來自這里

AC代碼:

#include<bits/stdc++.h> #define mod 1000000007 typedef long long ll;using namespace std; ll n; ll qpow(ll a,ll k) {ll ans = 1;while(k > 0) {if(k&1) {ans*=a;}ans%=mod;a*=a;a%=mod;k>>=1;}return ans%mod; } int main() {int t;ll ans;cin>>t;while(t--) {scanf("%lld", &n);ans = qpow(2,n%mod-1);printf("%lld\n",ans-1);}return 0; }

?

總結

以上是生活随笔為你收集整理的【 HDU - 5363】Key Set(水题,快速幂,组合数学)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。