[sicily]1209. Sequence Sum Possibi
来源:互联网 发布:时间序列的数据挖掘 编辑:程序博客网 时间:2024/05/16 19:18
1209. Sequence Sum Possibi
Constraints
Time Limit: 1 secs, Memory Limit: 32 MB
Description
Most positive integers may be written as a sum of a sequence of at least two consecutive positive integers. For instance,
6 = 1 + 2 + 3
9 = 5 + 4 = 2 + 3 + 4
but 8 cannot be so written.
Write a program which will compute how many different ways an input number may be written as a sum of a sequence of at least two consecutive positive integers.
Input
The first line of input will contain the number of problem instances N on a line by itself, (1<=N<=1000) . This will be followed by N lines, one for each problem instance. Each problem line will have the problem number, a single space and the number to be written as a sequence of consecutive positive integers. The second number will be less than 2^31 (so will fit in a 32-bit integer).
Output
The output for each problem instance will be a single line containing the problem number, a single space and the number of ways the input number can be written as a sequence of consecutive positive integers.
Sample Input
7 1 6 2 9 3 8 4 1800 5 987654321 6 987654323 7 987654325
Sample Output
1 1 2 2 3 0 4 8 5 17 6 1 7 23
简单的数论题。给定一个数,找出有多少组连续数字之和为该数。利用等差数列公式,枚举项数。设有 i 项,为 l,l+1,l+2....l+i-1; 则,(2l + i-1 ) * i = 2n ; 即:2l*i + (i-1)*i = 2n,由于 l 大于0的整数,则,可判断出 i 的范围以及 i 能否成为项数的条件。具体代码如下:
#include <iostream>using namespace std;int main(){ int t; cin>>t; while(t--) { int count = 0; int index, num; cin>>index>>num; for(int i=2; i*i-i < 2*num; i++) { if( (2*num - i*(i-1)) % (2*i) == 0) count++; } cout<<index<<" "<<count<<endl; } //system("pause"); return 0;}
- [sicily]1209. Sequence Sum Possibi
- sicily 1209. Sequence Sum Possibi
- Sicily 1209. Sequence Sum Possibi
- Sicily 1209 Sequence Sum Possibi
- 1209. Sequence Sum Possibi
- 1209. Sequence Sum Possibi
- Sequence Sum Possibi
- Sicily1209. Sequence Sum Possibi题解
- [Sicily] sicily 1091. Maximum Sum
- Sicily 1800. Sequence
- Sicily 1800 Sequence(RMQ)
- sicily 1800.Sequence
- sicily 1089. Farey Sequence
- Sicily 1888. Circular Sequence
- Sicily 2680. Sequence
- Sicily 1803. Arithmetic Sequence
- Sicily 1089. Farey Sequence
- Sicily 1038. EKG Sequence
- postgresql libpq C语言网络库接口操作数据库例子
- 使用h5做上传图片的即时显示
- Linux档案内容查阅的命令
- 数据结构实验之栈:行编辑器
- QT:界面切换之飞入飞出
- [sicily]1209. Sequence Sum Possibi
- 数据结构实验:哈希表
- HTML5 Web app开发工具Kendo UI Web教程:创建自定义组件(一)
- 虚拟化中的SR-IOV
- 【读书笔记】iOS网络-测试与操纵网络流量
- [转载]Qt实现滚动图片效果
- #pragma mark - 去除重复对象
- 数据结构实验:连通分量个数
- Qt之再谈阴影边框