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. HDU 4070 Phage War

    贪心,t 大的放到前面...因为感染所有cell需要的phage的总数是一定的,所以产生phage需要的时间是一定的,只需要考虑用来感染的时间,这样考虑的话,把 t 小的放后面的话,可以发现总时间的最 ...

  2. error -27257: Pending web_reg_save_param/reg_find/create_html_param[_ex] request(s) detected and reset at the end of iteration number 1

    检查点函数  web_reg_find("Search=body",     "savecount=num",     "Text=test1&quo ...

  3. hdu4707 Pet

    Pet Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submissio ...

  4. 浅C#中的装箱和拆箱

    1.什么是装箱和拆箱? 简单的来说: 装箱就是值类型转换为引用类型:拆箱就是引用类型转换为值类型 值类型,包括原类型(Sbyte.Byte.Short.Ushort.Int.Uint.Long.Ulo ...

  5. TCP与UDP各自特点对比

    UDP和TCP是我们最常用的两种通信方式,下面就两者之间的特点做一个对比: 1.UDP主要用在实时性要求高以及对质量相对较弱的地方,如流媒体. 2.TCP既然是面向连接的,那么运行环境必然要求其保证可 ...

  6. Spark SQL Catalyst源代码分析之TreeNode Library

    /** Spark SQL源代码分析系列文章*/ 前几篇文章介绍了Spark SQL的Catalyst的核心执行流程.SqlParser,和Analyzer,本来打算直接写Optimizer的,可是发 ...

  7. POJ 3619 Speed Reading(简单题)

    [题意简述]:有K头牛,N页书,每次第i头牛每分钟仅仅能读Si页书,连续读Ti分钟,之后歇息Ri分钟.如今问我们第i头牛花费多少时间能够读完这N页书. [分析]:简单的模拟 //220K 32Ms # ...

  8. Struts2通过自己定义拦截器实现登录之后跳转到原页面

    这个功能对用户体验来说是非常重要的.实现起来事实上非常easy. 拦截器的代码例如以下: package go.derek.advice; import go.derek.entity.User; i ...

  9. 谈论multistage text input(中国输入法)下一个UITextView内容长度的限制

    我以前写<如何更好地限制UITextField输入长度>.接使用 UIKIT_EXTERN NSString *const UITextFieldTextDidChangeNotifica ...

  10. PAI里field module的on input和on request区别

    在编辑屏幕的PAI的时候,对字段的检查一般用field xxx module xxx或者用chain.有两种操作可供选择,一种是on input,另一种是on request. 区别是: on inp ...