SPOJ - INTSUB 数学

题目链接:点击传送

INTSUB - Interesting Subset

no tags

You are given a set X = {1, 2, 3, 4, … , 2n-1, 2n} where n is an integer. You have to find the number of interesting subsets of this set X.

A subset of set X is interesting if there are at least two integers a & b  such that b is a multiple of a, i.e. remainder of b divides by a is zero and a is the smallest number in the set.

Input

The input file contains multiple test cases. The first line of the input is an integer T(<=30) denoting the number of test cases. Each of the next T lines contains an integer ‘n‘ where 1<=n<=1000.

Output

For each test case, you have to output as the format below:

Case X: Y

Here X is the test case number and Y is the number of subsets. As the number Y can be very large, you need to output the number modulo 1000000007.

Example

Input:
3
1
2
3

Output:
Case 1: 1
Case 2: 9
Case 3: 47

Submit solution!

题意:给你2*n个数,你最小需要选两个,使得这个子集中含有最小值的倍数;

思路:枚举最小值,对于其倍数最小取一个,其余随意取与不取;

#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<iostream>
#include<cstdio>
#include<cmath>
#include<string>
#include<queue>
#include<algorithm>
#include<stack>
#include<cstring>
#include<vector>
#include<list>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define pi (4*atan(1.0))
#define eps 1e-14
#define bug(x)  cout<<"bug"<<x<<endl;
const int N=1e5+10,M=1e6+10,inf=2147483647;
const ll INF=1e18+10,mod=1e9+7;
ll qpow(ll a,ll b,ll c)
{
    ll ans=1;
    while(b)
    {
        if(b&1)ans=(ans*a)%c;
        b>>=1;
        a=(a*a)%c;
    }
    return ans;
}
int main()
{
    int T,cas=1;
    scanf("%d",&T);
    while(T--)
    {
        int n;
        scanf("%d",&n);
        ll ans=0;
        for(int i=1;i<=n;i++)
        {
            int p=(2*n-i);
            int b=((2*n)/i-1);
            ans=(ans+(qpow(2,p-b,mod)*(qpow(2,b,mod)+(mod-1))%mod)%mod)%mod;
        }
        printf("Case %d: %lld\n",cas++,ans);
    }
    return 0;
}

Interesting Subset

SPOJ - INTSUB

时间: 2024-08-03 22:55:10

SPOJ - INTSUB 数学的相关文章

SPOJ FAVDICE 数学期望

题目大意: 一个有n面的色子抛掷多少次能使所有面都能被抛到过,求期望值 总面数为n,当已经抛到过 i 个不同面时,我们抛出下一个不同面的概率为 (n-i)/n,那么抛的次数为 n/(n-i) 将所有抛出下个面的次数累加起来就好了 1 #include <cstdio> 2 int main(){ 3 int kase,n; 4 scanf("%d",&kase); 5 while(kase--){ 6 scanf("%d",&n); 7

SPOJ:NPC2016A(数学)

http://www.spoj.com/problems/NPC2016A/en/ 题意:在一个n*n的平面里面,初始在(x,y)需要碰到每条边一次,然后返回(x,y),问最短路径是多长. 思路:像样例中给出的,假设一开始是在(x,y),那么走一个斜率为1和-1的路径,因为两边对称,所以ans = 2 * x * sin(45°) + 2 * (n - x) * sin(45°) = 2 * n * sqrt(2). 就是每次走的都是对角线的长度. 1 #include <bits/stdc++

SPOJ SUMPRO(数学)

题意: 给出一个数N,问所有满足n/x=y(此处为整除)的所有x*y的总和是多少.对答案mod(1e9+7). 1 <= T <= 500. 1 <= N <= 1e9. 分析: 可以枚举x得到y,但是这样是O(n)的会TLE 当x<=sqrt(n)的时候,我们可以暴力枚举 当x>sqrt(n)的时候,我们发现很多x对应的y值都相等,这些组成一个等差序列,实际上,这时候的(x,y)就是我们之前暴力过的(y,x),等差数列求和即可

SPOJ Favorite Dice(数学期望)

BuggyD loves to carry his favorite die around. Perhaps you wonder why it's his favorite? Well, his die is magical and can be transformed into an N-sided unbiased die with the push of a button. Now BuggyD wants to learn more about his die, so he raise

SPOJ 74. Divisor Summation 分解数字的因子

本题有两个难点: 1 大量的数据输入,没处理好就超时 - 这里使用buffer解决 2 因子分解的算法 a)暴力法超时 b)使用sieve(筛子),不过其中的算法逻辑也挺不容易搞对的. 数值N因子分解逻辑: 1 保存所有可以sqrt(N)范围内的质素 2 找到可以被N除尽的质素d, 然后用d去除N,使用deg变量,保存度,即有多少个d可以被N除尽 3 用d去乘所有已经找到的因子(包括1),如果度deg大于1,那么循环i从1到deg, 用d*i去乘所有找到的因子 找到所有因子相加,减去N,就是答案

杜教筛进阶+洲阁筛讲解+SPOJ divcnt3

Part 1:杜教筛进阶在了解了杜教筛基本应用,如$\sum_{i=1}^n\varphi(i)$的求法后,我们看一些杜教筛较难的应用.求$\sum_{i=1}^n\varphi(i)*i$考虑把它与$id$函数狄利克雷卷积后的前缀和.$$\sum_{i=1}^n\sum_{d|i}\varphi(d)*d*\frac id=\sum_{i=1}^ni^2$$枚举$T=\frac id$,原式化为$$\sum_{T=1}^nT\sum_{d=1}^{\lfloor\frac nT\rfloor}

『转』数学专辑

1.burnside定理,polya计数法 这个大家可以看brudildi的<组合数学>,那本书的这一章写的很详细也很容易理解.最好能完全看懂了,理解了再去做题,不要只记个公式. *简单题:(直接用套公式就可以了) pku2409 Let it Bead   http://acm.pku.edu.cn/JudgeOnline/problem?id=2409 pku2154 Color http://acm.pku.edu.cn/JudgeOnline/problem?id=2154 pku12

[HNOI2011]数学作业

题目描述 小 C 数学成绩优异,于是老师给小 C 留了一道非常难的数学作业题: 给定正整数 N 和 M,要求计算 Concatenate (1 .. N) Mod M 的值,其中 Concatenate (1 ..N)是将所有正整数 1, 2, -, N 顺序连接起来得到的数.例如,N = 13, Concatenate (1 .. N)=12345678910111213.小C 想了大半天终于意识到这是一道不可能手算出来的题目,于是他只好向你求助,希望你能编写一个程序帮他解决这个问题. 输入输

codeforces_346A Alice and Bob(数学)

题目链接:http://codeforces.com/problemset/problem/346/A 参考链接:http://blog.csdn.net/loy_184548/article/details/50174615 感受到数学在博弈论中的强大. 考虑最后终止状态的序列-无法取出任意两个数他们的差值不存在这个序列中:那么这必定是个首项等于公差的等差序列 而这个序列是 d 2d 3d....,因此可以通过a[1] a[2] a[3] ...的最大公约数得到 然后计算有几个数没在数组中,判