codeforces 598A Tricky Sum】的更多相关文章

传送门: http://codeforces.com/problemset/problem/598/A A. Tricky Sum time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output In this problem you are to calculate the sum of all integers from 1 to n, b…
题目链接:http://codeforces.com/contest/598/problem/A 题目分类:大数 题意:1到n 如果是2的次方则减去这个数,否则就加上这个数,求最后的结果是多少 题目分析:数很大,关键是精度问题,刚开始用__int64和double发现都是不对的,后来发现用long long 可以过 代码: #include<bits/stdc++.h> using namespace std; #define LL long long LL a[]={,,,,,,,,, ,,…
A. Tricky Sum Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/598/problem/A Description In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum.…
题目链接:Codeforces 396B On Sum of Fractions 题解来自:http://blog.csdn.net/keshuai19940722/article/details/20076297 题目大意:给出一个n,ans = ∑(2≤i≤n)1/(v(i)*u(i)), v(i)为不大于i的最大素数,u(i)为大于i的最小素数, 求ans,输出以分式形式. 解题思路:一開始看到这道题1e9,暴力是不可能了,没什么思路,后来在纸上列了几项,突然想到高中时候求等差数列时候用到…
codeforces 963A Alternating Sum 题解 计算前 \(k\) 项的和,每 \(k\) 项的和是一个长度为 \((n+1)/k\) ,公比为 \((a^{-1}b)^k\) 的等比数列. 当公比为 \(1\) 时,不能用等比数列求和公式. 什么时候公比为 \(1\) ? 当 \(a=b\) 时,\(a^{-1}b=1(mod\ p)\) 当 \(a=p-b\) 时,\(a^{-1}b=(p-b)^{-1}b=-1(mod\ p)\),如果此时 \(k\) 是偶数,公比就…
codeforces 1217E E. Sum Queries? (线段树 传送门:https://codeforces.com/contest/1217/problem/E 题意: n个数,m次询问 单点修改 询问区间内最小的unbalanced number balanced number定义是,区间内选取数字的和sum sum上的每一位都对应着选取的数上的一位 否则就是unbalanced number 题解: 根据题意 如果区间存在unbalance number,那么一定存在两个数就可…
http://codeforces.com/problemset/problem/577/B 题意:有n个数,求有无一个子序列满足和是m的倍数 思路:用模下的背包做,发现n是十的六次方级别,但是有个神奇的性质,就是抽屉原理,当n大于等于m的时候,总会有sum[i]和sum[j]满足sum[i]%m=sum[j]%m,于是当n>=m的时候就可以特判掉,DP的复杂度就是O(n^2)的 总结:一定要记住,在模m下的前缀和这样的东西,一定要记得有抽屉原理! 然后这题的XX细节真是坑死我了 #includ…
题目链接:http://codeforces.com/contest/85/problem/D 做法果然男默女泪啊..... 大概就是直接开了一个$vector$每次插入删除都用自带的$insert$和$erase$,然后查询也是暴力搞. 那么为啥么过得很有理有据呢? 1.首先考虑如果没有修改我就能继承上一次的答案... 2.修改我们假设(就是)${O(logn)}$的. 3.每次暴力查询是$5$个数字一步. 4.显然一开始并不是上来就有${100000}$个数字 所以大概复杂度会是${O(n^…
B. Odd sum 题目链接:http://codeforces.com/problemset/problem/797/B time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given sequence a1, a2, ..., an of integer numbers of length n. Your ta…
题目链接:http://codeforces.com/problemset/problem/963/A 题目大意:就是给了你n,a,b和一段长度为k的只有'+'和‘-’字符串,保证n+1被k整除,让你你计算. 解题思路: 暴力肯定超时的,我们可以先计算出0~k-1这一段的值,当做a1,可以发现如果把每段长度为k的段的值当做一个元素,他们之间是成等比的,比值q=(b/a)^k, 然后就直接用等比数列求和公式求出答案即可.昨天把q当成b/a了,我的脑子啊... 注意,判断q==1时不能通过判断a==…