Uva10290 - {Sum+=i++} to Reach N
Problem H
{sum+=i++} to Reach N
Input: standard input
Output: standard output
Memory Limit: 32 MB
All the positive numbers can be expressed as a sum of one, two or more consecutive positive integers. For example 9 can be expressed in three such ways, 2+3+4, 4+5 or 9. Given an integer
less than (9*10^14+1) or (9E14 + 1) or (9*1014 +1) you will have to determine in how many ways that number can be expressed as summation of consecutive numbers.
Input
The input file contains less than 1100 lines of input. Each line contains a single integer N (0<=N<= 9E14). Input is terminated by end of file.
Output
For each line of input produce one line of output. This line contains an integer which tells in how many ways N can be expressed as summation of consecutive integers.
Sample Input
9
11
12
Sample Output
3
2
2
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
using namespace std;
const int maxn = 1e7+10;
typedef long long ll; bool isPrime[maxn];
vector<int> prime,cnt;
ll n; void getPrime(){
memset(isPrime,1,sizeof isPrime);
for(int i = 2; i < maxn; i++){
if(isPrime[i]){
prime.push_back(i);
for(int j = i+i; j < maxn; j+=i){
isPrime[j] = 0;
}
}
}
} void getDigit(){ while(n%2==0) n/=2;
// cout<<n<<endl;
for(int i = 1; i < prime.size()&&n >= prime[i]; i++){
if(n%prime[i]==0){
int t = 0;
while(n%prime[i]==0){
n /= prime[i];
t++;
}
cnt.push_back(t);
}
}
if(n!=1) cnt.push_back(1);
} int main(){ getPrime();
while(~scanf("%lld",&n)){
cnt.clear();
getDigit();
ll ans = 1;
for(int i = 0; i < cnt.size(); i++) ans *= (cnt[i]+1);
cout<<ans<<endl; }
return 0;
}
Uva10290 - {Sum+=i++} to Reach N的更多相关文章
- UVa 10290 - {Sum+=i++} to Reach N
题目:给你一个数字问将他写成连续的数字的和的形式.有几种写法. 分析:数论. 设拆成的序列个数为k,我们分两种情况讨论: 1.拆成奇数个连续数.那么设中位数是a,则有n = k * a: 2.拆成偶数 ...
- Leetcode: Path Sum III
You are given a binary tree in which each node contains an integer value. Find the number of paths t ...
- Maya Calendar 分类: POJ 2015-06-11 21:44 12人阅读 评论(0) 收藏
Maya Calendar Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 70016 Accepted: 21547 D ...
- [HDU5765]Bonds
题面 题意 给出一张\(n\)点\(m\)边无向连通图,求每条边出现在多少个割集中. \(n\le20,m\le\frac{n(n-1)}{2}\) sol 所谓割集,就是指把\(n\)个点分成两个集 ...
- Storm概念学习系列之storm-starter项目(完整版)(博主推荐)
不多说,直接上干货! 这是书籍<从零开始学Storm>赵必厦 2014年出版的配套代码! storm-starter项目包含使用storm的各种各样的例子.项目托管在GitHub上面,其网 ...
- 洛谷P1315 [NOIP2011提高组Day2T3] 观光公交
P1315 观光公交 题目描述 风景迷人的小城Y 市,拥有n 个美丽的景点.由于慕名而来的游客越来越多,Y 市特意安排了一辆观光公交车,为游客提供更便捷的交通服务.观光公交车在第 0 分钟出现在 1号 ...
- Leetcode: Split Array Largest Sum
Given an array which consists of non-negative integers and an integer m, you can split the array int ...
- LeetCode: Unique Paths I & II & Minimum Path Sum
Title: https://leetcode.com/problems/unique-paths/ A robot is located at the top-left corner of a m ...
- [LeetCode#110, 112, 113]Balanced Binary Tree, Path Sum, Path Sum II
Problem 1 [Balanced Binary Tree] Given a binary tree, determine if it is height-balanced. For this p ...
随机推荐
- web攻击方式和防御方法
在http请求报文中载入攻击代码,就能发起对web应用的攻击.通过url查询字段或者表单.http首部.cookie等途径吧攻击代码传入,若这时web应用存在安全漏洞,那内部信息就会遭到窃取! 对we ...
- MSSQL - 用GUID值来完成数据表行标识
地址:http://www.cnblogs.com/huangfr/archive/2012/03/28/2420780.html [Guid] [uniqueidentifier] NOT NULL ...
- 用DELPHI的RTTI实现对象的XML持久化
去年我花了很多时间尝试用DELPHI进行基于XML的WEB应用开发.起初的设想是很美好的,但结果做出来的东西很简陋.一部分原因就在于XML到Object之间的数据绑定实现太麻烦(另一部分是因为对XSL ...
- iot表输出按主键列排序,heap表不是
<pre name="code" class="html"> create table t1 (id char(10) primary key,a1 ...
- 党建凯,创新工场知乎团队Web前端工程师
Nicholas C. Zakas谈怎样才能成为优秀的前端工程师: 昨天,我负责了Yahoo!公司组织的一次面试活动,感触颇深的是其中的应聘者提问环节.我得说自己对应聘者们提出的大多数问题都相当失望. ...
- css hack 如何区分 ie7 ie8
.style { width:100px; /*火狐以及一般浏览器*/ width:200px\9; /*IE8*/ *width:150px; /*IE7*/ _width:50px; /*IE6* ...
- 【Demo 0005】Java基础-类继承性
本章学习要点: 1. 了解Java继承特性; 2. 掌握继承实现方法; 3. 掌握override规则: 一.类继承特性 1. 继承定义:使用己 ...
- Mac与Window之间的共享文件
Mac访问Window: Finder 菜单 “前往” ,然后“连接服务器”,在服务器地址输入 smb://windows主机名或ip地址/共享名(前提window已设置共享文件) Windows访问 ...
- android中,如果使用imageButton可以在drawable 中设置一个selector,但是imageView设置不起作用
android中,如果使用imageButton可以在drawable 中设置一个selector,但是imageView设置不起作用,只要把Imageview的src给去掉就成了,src捕获了bac ...
- Android性能优化---布局优化
我们从事Android开发编写布局的时候大多数是使用XML来布局,这给我们带来了方便性,这样操作可以布局界面的代码和逻辑控制的Java代码分离出来,使程序的结构更加清晰.明了.特别的复杂的布局,但是这 ...