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 ...
随机推荐
- Vanya and Lanterns
Description Vanya walks late at night along a straight street of length l, lit by n lanterns. Consid ...
- 自绘ListBox的两种效果
本文利用Listbox自绘实现了两种特殊效果(见图),左边的风格是自己突然灵感触发想到的,右边的风格来自"C++ Builder 研究"的一个帖子,老妖用BCB实现了,这里则用Delphi实现它. 演 ...
- Jsp中使用数据库连接池.
原文 Jsp中使用数据库连接池. 1. 在tomcat服务器目录下面的conf中找到一个叫Context.xml的配置文件,在其中加入以下代码 <Resource name="jdbc ...
- response.sendRedirect 传递参数的问题
response.sendRedirect是通过浏览器来做转向的. 假设在A.jsp页面设置request.setAttribute("username","admin& ...
- 11661 - Burger Time?
Burger Time? Everybody knows that along the more important highways there are countless fast food ...
- OpenStack使用Bosh部署CloudFoundry(一)—准备OpenStack环境
版本说明: CloudFoundry:V2版本 OpenStack:Folsom或者Grizzly版本 本篇文章采用OpenStack Folsom+nova-network的OpenStack环境, ...
- hdu 4090 GemAnd Prince
题目大意: 别人说是消消看,至于你玩没玩过.反正我是没玩过的. 就是选择一个钻石,可以消除与它相连的所有钻石.并获得 消除数量*消除数量 的分 思路: 直接暴搜,然后用一个cnt数组表示每一种钻石剩 ...
- [置顶] Codeforces 70D 动态凸包 (极角排序 or 水平序)
题目链接:http://codeforces.com/problemset/problem/70/D 本题关键:在log(n)的复杂度内判断点在凸包 或 把点插入凸包 判断:平衡树log(n)内选出点 ...
- CImage类
CImage封装了DIB(设备无关位图)的功能,因而可以让我们能够处理每个位图像素.这里介绍GDI+和CImage的一般使用方法和技巧. TAG: GDI CImage 后处理 我们知道,Vi ...
- Mysql对自增主键ID进行重新排序
Mysql数据库表的自增主键ID号经过一段时间的添加与删除之后乱了,需要重新排列. 原理:删除原有的自增ID,重新建立新的自增ID. 1,删除原有主键: ALTER TABLE `table_name ...