SPOJ - INTSUB 数学
题目链接:点击传送
INTSUB - Interesting Subset
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
题意:给你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+,M=1e6+,inf=;
const ll INF=1e18+,mod=1e9+;
ll qpow(ll a,ll b,ll c)
{
ll ans=;
while(b)
{
if(b&)ans=(ans*a)%c;
b>>=;
a=(a*a)%c;
}
return ans;
}
int main()
{
int T,cas=;
scanf("%d",&T);
while(T--)
{
int n;
scanf("%d",&n);
ll ans=;
for(int i=;i<=n;i++)
{
int p=(*n-i);
int b=((*n)/i-);
ans=(ans+(qpow(,p-b,mod)*(qpow(,b,mod)+(mod-))%mod)%mod)%mod;
}
printf("Case %d: %lld\n",cas++,ans);
}
return ;
}
Interesting Subset
SPOJ - INTSUB 数学的更多相关文章
- SPOJ INTSUB - Interesting Subset(数学)
http://www.spoj.com/problems/INTSUB/en/ 题意:给定一个集合,该集合由1,2,3....2n组成,n是一个整数.问该集合中有趣子集的数目,答案mod1e9+7. ...
- SPOJ FAVDICE 数学期望
题目大意: 一个有n面的色子抛掷多少次能使所有面都能被抛到过,求期望值 总面数为n,当已经抛到过 i 个不同面时,我们抛出下一个不同面的概率为 (n-i)/n,那么抛的次数为 n/(n-i) 将所有抛 ...
- SPOJ:NPC2016A(数学)
http://www.spoj.com/problems/NPC2016A/en/ 题意:在一个n*n的平面里面,初始在(x,y)需要碰到每条边一次,然后返回(x,y),问最短路径是多长. 思路:像样 ...
- SPOJ Favorite Dice(数学期望)
BuggyD loves to carry his favorite die around. Perhaps you wonder why it's his favorite? Well, his d ...
- SPOJ:Robot(数学期望)
There is a robot on the 2D plane. Robot initially standing on the position (0, 0). Robot can make a ...
- SPOJ:OR(位运算&数学期望)
Given an array of N integers A1, A2, A3…AN. If you randomly choose two indexes i ,j such that 1 ≤ i ...
- SPOJ SUMPRO(数学)
题意: 给出一个数N,问所有满足n/x=y(此处为整除)的所有x*y的总和是多少.对答案mod(1e9+7). 1 <= T <= 500. 1 <= N <= 1e9. 分析 ...
- 杜教筛进阶+洲阁筛讲解+SPOJ divcnt3
Part 1:杜教筛进阶在了解了杜教筛基本应用,如$\sum_{i=1}^n\varphi(i)$的求法后,我们看一些杜教筛较难的应用.求$\sum_{i=1}^n\varphi(i)*i$考虑把它与 ...
- SPOJ 74. Divisor Summation 分解数字的因子
本题有两个难点: 1 大量的数据输入.没处理好就超时 - 这里使用buffer解决 2 因子分解的算法 a)暴力法超时 b)使用sieve(筛子),只是当中的算法逻辑也挺不easy搞对的. 数值N因子 ...
随机推荐
- for练习相关
for嵌套: 大圈套小圈思想:有一种重复的情况而这种情况每一次对应另外情况多次. ------------------------------------------------------- 例如: ...
- SQL中常见语句
SQL中常见语句笔记: --替换字段中的回车符和换行符 ) ), '') --删除表命令 DROP TABLE [dbo].[MGoods_Test] --删除表中数据命令 DELETE FROM [ ...
- 机器学习理论基础学习14.2---线性动态系统-粒子滤波 particle filter
一.背景 与卡曼滤波不同的是,粒子滤波假设隐变量之间(隐变量与观测变量之间)是非线性的,并且不满足高斯分布,可以是任意的关系. 求解的还是和卡曼滤波一样,但由于分布不明确,所以需要用采样的方法求解. ...
- windows下编译和安装boost库
boost是一个功能强大.构造精巧.跨平台.开源并且完全免费的C++程序库. 获取方式 boost提供源码形式的安装包,可以从boost官方网站下载,目前最新版本是1.59.0. 本机上正好有boos ...
- VMware Coding Challenge: Removing Duplicates Entries
static LinkedListNode removeDuplicates(LinkedListNode list) { LinkedListNode cur = list; HashSet< ...
- C++Builder6.0 新建和打开项目软件死机
大清早上班打开C++Builder6.0软件,打开项目却卡死,甚是奇怪,然后尝试新建项目也同样卡死.尝试打开一个CPP文件,可以打开,再尝试打开项目.bpr文件,便打开了.至于原因为什么,那就不得而知 ...
- BP神经网络的Java实现(转)
http://fantasticinblur.iteye.com/blog/1465497 课程作业要求实现一个BPNN.这次尝试使用Java实现了一个.现共享之.版权属于大家.关于BPNN的原理,就 ...
- UVA 103
/* 这题说的的是 N 维的坐标, 每个盒子的N维坐标 可以进行 随意方式的调换 然后求出 A全部的坐标小于B的 则 A 可以嵌套在B中 然后 计算出最多的 盒子嵌套个数 简单的状态转移 我为何如此的 ...
- [转]autoid文件上传
原文地址:https://www.cnblogs.com/yoyoketang/p/7612026.html 前言 关于非input文件上传,点上传按钮后,这个弹出的windows的控件了,已经跳出三 ...
- 中国用户通过rchange用银联充值到PerfectMoney再给BTC-E充值进行搬砖的方法
最近迷上了比特币这个疯狂的东西,相信很多技术人员都感兴趣. 比特币.莱特币钱包下载和把数据迁移到C盘以外其他盘的方法. 莱特币和山寨币的原理跟比特币基本上一样,可以参考这个方法进行,莱特币的钱包数据迁 ...