题目链接:
http://www.spoj.com/problems/INTSUB/
题意:
给定一个集合,该集合由1,2,3….2n组成,n是一个整数。问该集合中有趣子集的数目,答案mod1e9+7。
x的子集合有趣定义为,该子集中至少有两个数,a和b,b是a的倍数且a是集合中最小的元素。
题解:
枚举子集中最小的元素,然后确定其他的元素。
假设现在最小元素为a,则有2n/a-1个大于a的元素是a的倍数,且这些元素必须在子集中出现至少一个,剩下的大于a的数取和不取对答案不造成影响。
累计不同的a对答案的贡献即可。(具体公式请参看程序)
代码:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MS(a) memset(a,0,sizeof(a))
#define MP make_pair
#define PB push_back
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3fLL;
inline ll read(){
ll x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
//////////////////////////////////////////////////////////////////////////
const int maxn = 2e3+10;
const int mod = 1000000007;
int f[maxn];
int main(){
f[0] = 1;
for(int i=1; i<100; i++)
f[i] = (f[i-1]<<1)%mod;
int T = read();
for(int cas=1; cas<=T; cas++){
int n = read();
int ans = 0;
for(int i=1; i<=n; i++){
ans += 1LL * (f[2*n/i-1]-1) * f[2*n-i-(2*n/i-1)]%mod;
ans %= mod;
}
printf("Case %d: %d\n",cas,ans);
}
return 0;
}