BNU - Consecutive Sums 公式与素数
来源:互联网 发布:移动搜索引擎seo 编辑:程序博客网 时间:2024/04/29 12:27
连续数字,前面p个和后面q个相加相等。 已知q,问p有多少种。
a - p , ..... a - 1, a, ....... , a + q - 1;
p(a - p) + (p - 1 ) * p / 2 = q * a + (q - 1) * q / 2;
2a = p + q + 1 + 2 * q * q / ( p - q) ; 右边肯定是个偶数。于是我们就讨论已知q,p的取法。
当q是偶数的时候,讨论p的奇偶性,发现p - q的取值要不是2^0,要不是2 ^ (q里面所有2的个数 + 1)。
当q是奇数的时候,p - q的取值为q的所有因数。
这题做得相当纠结。我发觉我做题没有好好思考。这像不像就是在做数学题呢?
其实我考试的时候也从不好好思考,只凭记忆。过了一阵子,就什么都忘了。外加我无论做什么正在做的事情,我总是想着以后有时间了再做,总是比人家慢半拍。
看来是多年养成的不会思考的习惯。21天,能改吗?
#include <functional>#include <algorithm>#include <iostream>#include <iomanip>#include <numeric>#include <sstream>#include <cstring>#include <cstdio>#include <string>#include <vector>#include <bitset>#include <queue>#include <stack>#include <cmath>#include <ctime>#include <list>#include <set>#include <map>using namespace std;/* .................................................................................................................................. *//***************************************prime tableO(n)***************************************/#define LL long longconst int PRIMERANGE = 10000000;LL prime[PRIMERANGE + 1];int getPrime(){ prime[0] = 0; for(int i = 2; i < PRIMERANGE; i ++){ if(!prime[i]) prime[++prime[0] ] = i; for(int j = 1; j <= prime[0] && prime[j] <= PRIMERANGE / i; j ++){ prime[prime[j] * i] = 1; if(i % prime[j] == 0) break; } } return prime[0];}LL n;void solve(){ while (n % 2 == 0) n /= 2; LL ans = 2; for (int i = 1 ; prime[i] * prime[i] <= n ; ++i){ if (n % prime[i] == 0){ LL k = 0; while (n % prime[i] == 0){ k++; n /= prime[i]; } ans *= (2 * k + 1); } } if (n > 1LL) ans *= 3; printf("%lld\n",ans);//cout << ans << endl;}int main(){ getPrime(); while (~scanf("%lld",&n) && n) solve();}
- BNU - Consecutive Sums 公式与素数
- bnu 素数三元法
- ZOJ Problem Set - 2773 Triangular Sums【公式】
- 素数生成公式
- 素数普遍公式
- ACM-ICPC 2011 Asia Phuket Regional [J] Consecutive Sums
- BNU
- BNU 13288 Bi-shoe and Phi-shoe 【素数筛选】
- 筛法求素数,组合数公式,唯一分解定理(选择与除法,uva 10375)
- BNU 背包密码(编码与解密)
- Sums
- sums
- 素数与素数检测
- POJ 2739 Sum of Consecutive Prime Numbers(素数表)
- 1259. Sum of Consecutive Primes(连续素数求和)
- poj 2739 Sum of Consecutive Prime Numbers(筛选素数 预处理)
- poj2739 - Sum of Consecutive Prime Numbers(求素数)
- poj 2739 Sum of Consecutive Prime Numbers【素数筛】
- 操作系统开发 – 婴儿教程 3
- 【研发管理】从技术到管理,思维转变是关键
- oracle查询语句中select from where group by having order by的解释与应用
- 操作系统开发 – 婴儿教程 4
- 操作系统开发 – 婴儿教程 5
- BNU - Consecutive Sums 公式与素数
- 网络经济与企业管理总结
- Android系统匿名共享内存(Anonymous Shared Memory)C++调用接口分析
- net中SessionState相关配置
- Android应用程序线程消息循环模型分析
- 操作系统开发 – 婴儿教程 6
- Struts 2的property标签的原理
- [小e笔记]之一步一步学习备份恢复——第二篇备份恢复原理
- 操作系统开发 – 婴儿教程 7