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+44+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


题意:问你N能够由多少种方案:连续的x个整数相加和为N

思路:转化为求奇因数,分解质因数后求排列数
#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的更多相关文章

  1. UVa 10290 - {Sum+=i++} to Reach N

    题目:给你一个数字问将他写成连续的数字的和的形式.有几种写法. 分析:数论. 设拆成的序列个数为k,我们分两种情况讨论: 1.拆成奇数个连续数.那么设中位数是a,则有n = k * a: 2.拆成偶数 ...

  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 ...

  3. Maya Calendar 分类: POJ 2015-06-11 21:44 12人阅读 评论(0) 收藏

    Maya Calendar Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 70016   Accepted: 21547 D ...

  4. [HDU5765]Bonds

    题面 题意 给出一张\(n\)点\(m\)边无向连通图,求每条边出现在多少个割集中. \(n\le20,m\le\frac{n(n-1)}{2}\) sol 所谓割集,就是指把\(n\)个点分成两个集 ...

  5. Storm概念学习系列之storm-starter项目(完整版)(博主推荐)

    不多说,直接上干货! 这是书籍<从零开始学Storm>赵必厦 2014年出版的配套代码! storm-starter项目包含使用storm的各种各样的例子.项目托管在GitHub上面,其网 ...

  6. 洛谷P1315 [NOIP2011提高组Day2T3] 观光公交

    P1315 观光公交 题目描述 风景迷人的小城Y 市,拥有n 个美丽的景点.由于慕名而来的游客越来越多,Y 市特意安排了一辆观光公交车,为游客提供更便捷的交通服务.观光公交车在第 0 分钟出现在 1号 ...

  7. Leetcode: Split Array Largest Sum

    Given an array which consists of non-negative integers and an integer m, you can split the array int ...

  8. 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  ...

  9. [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 ...

随机推荐

  1. Cordys BOP 4平台开发入门实战演练——Webservices开发(0基础)

    0.文章导读 本文档针对Cordys BOP-4 WS-AppServer基础功能进行验证和高速开发指导.(高级实践文档请參考兴许文档). 0.1.WS-AppServer概述 WS-AppServe ...

  2. JSP的学习(4)——中文乱码的解决

    本篇将以JSP页面中可能存在的中文乱码问题进行分析和解决. 中文乱码的问题一直是国人在编程过程中的一大头疼问题,这点上在JSP.Servlet或Tomcat上随处可见.比如我们在写一个Servlet时 ...

  3. JQuery 插件之Ajax Autocomplete(ajax自动完成)

    平时用百度,谷歌搜索的时候 会有一个下 拉列表进行提示 这是一个非常好的功能 本文要介绍的这个JQuery 插件 名叫Ajax Autocomplete 顾名思义 ajax 也就是用ajax的方式获取 ...

  4. CF 258B Little Elephant and Elections [dp+组合]

    给出1,2,3...m 任取7个互不同样的数a1,a2,a3,a4,a5,a6,a7 一个数的幸运度是数位上4或7的个数 比方244.470幸运度是2. 44434,7276727.4747,7474 ...

  5. jquery实现鼠标焦点十字效果

    系统开发时很多地方需要有焦点效果,例如:鼠标点击聚焦,地图定位,在图片上突出显示,焦点定位页面元素. 本小功能通过jquery和graphics二次开发,实现通过鼠标点击页面任何区域,聚焦当前点击位置 ...

  6. Java中取某一个范围的随机数

    一.取模操作 public static void main(String[] args) { for (int i = 1; i <= 20; i++) { int j = i % 11; S ...

  7. java.text.MessageFormat格式化字符串时的小技巧

    java.text.MessageFormat格式化字符串时的小技巧 public static void main(String[] args) throws InterruptedExceptio ...

  8. Oracle 执行计划了的rows概念

    alter session set statistics_level=all; select t1.* from t1,t2 where t1.id=t2.id and t1.id<3; sel ...

  9. CentOS6.4 编译安装Python 3.3.2 - CRPER木木

    基础环境: CentOS6.4(预装GCC,或者联网YUM---GCC编译写进这里太臃肿,找机会另外写一篇) Python 3.3.2     下载链接: http://www.python.org/ ...

  10. json转换成list map集合

    import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Set; i ...