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 inte…
http://www.spoj.com/problems/INTSUB/en/ 题意:给定一个集合,该集合由1,2,3....2n组成,n是一个整数.问该集合中有趣子集的数目,答案mod1e9+7. x的子集合有趣定义为,该子集中至少有两个数,a和b,b是a的倍数且a是集合中最小的元素. 思路:考虑集合中最小的元素a,对于每个a,使得可以构成子集的元素(即b)有beishu = 2 * n / a - 1个,那么这里只考虑这些有2^beishu - 1个.那么还剩下other = 2 * n -…
题目大意: 一个有n面的色子抛掷多少次能使所有面都能被抛到过,求期望值 总面数为n,当已经抛到过 i 个不同面时,我们抛出下一个不同面的概率为 (n-i)/n,那么抛的次数为 n/(n-i) 将所有抛出下个面的次数累加起来就好了 #include <cstdio> int main(){ int kase,n; scanf("%d",&kase); while(kase--){ scanf("%d",&n); ; ;i <= n;i…
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). 就是每次走的都是对角线的长度. #include <bits/stdc++.h…
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…
There is a robot on the 2D plane. Robot initially standing on the position (0, 0). Robot can make a 4 different moves: Up (from (x, y) to (x, y + 1)) with probability U. Right (from (x, y) to (x + 1, y)) with probability R. Down (from (x, y) to (x, y…
Given an array of N integers A1, A2, A3…AN. If you randomly choose two indexes i ,j such that 1 ≤ i < j ≤ N, what is the expected value of Ai | Aj? Input First line contains an integer T, the number of test cases. Each test case consists of two lines…
题意: 给出一个数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),等差数列求和即可…
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 大量的数据输入.没处理好就超时 - 这里使用buffer解决 2 因子分解的算法 a)暴力法超时 b)使用sieve(筛子),只是当中的算法逻辑也挺不easy搞对的. 数值N因子分解逻辑: 1 保存全部能够sqrt(N)范围内的质素 2 找到能够被N除尽的质素d, 然后用d去除N.使用deg变量,保存度.即有多少个d能够被N除尽 3 用d去乘全部已经找到的因子(包含1),假设度deg大于1.那么循环i从1到deg, 用d*i去乘全部找到的因子 找到全部因子相加,减去N,就是…