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

思路:转化为求奇因数,分解质因数后求排列数
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstring>
  4. #include <vector>
  5. #include <string>
  6. #include <algorithm>
  7. #include <queue>
  8. using namespace std;
  9. const int maxn = 1e7+10;
  10. typedef long long ll;
  11.  
  12. bool isPrime[maxn];
  13. vector<int> prime,cnt;
  14. ll n;
  15.  
  16. void getPrime(){
  17. memset(isPrime,1,sizeof isPrime);
  18. for(int i = 2; i < maxn; i++){
  19. if(isPrime[i]){
  20. prime.push_back(i);
  21. for(int j = i+i; j < maxn; j+=i){
  22. isPrime[j] = 0;
  23. }
  24. }
  25. }
  26. }
  27.  
  28. void getDigit(){
  29.  
  30. while(n%2==0) n/=2;
  31. // cout<<n<<endl;
  32. for(int i = 1; i < prime.size()&&n >= prime[i]; i++){
  33. if(n%prime[i]==0){
  34. int t = 0;
  35. while(n%prime[i]==0){
  36. n /= prime[i];
  37. t++;
  38. }
  39. cnt.push_back(t);
  40. }
  41. }
  42. if(n!=1) cnt.push_back(1);
  43. }
  44.  
  45. int main(){
  46.  
  47. getPrime();
  48. while(~scanf("%lld",&n)){
  49. cnt.clear();
  50. getDigit();
  51. ll ans = 1;
  52. for(int i = 0; i < cnt.size(); i++) ans *= (cnt[i]+1);
  53. cout<<ans<<endl;
  54.  
  55. }
  56. return 0;
  57. }

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

    Description You play a computer game. Your character stands on some level of a multilevel ice cave. ...

  2. SuperSocket应用之FTP源码解析

    一 简述 命令行协议是一种使用比较多的协议,其优点在于使用简单易于扩展性,同时也利于解析和使用.FTP,POP,SMTP等均采用命令行协议,其中FTP在早起互联网时期成为网络资源共享的主要方式,可见F ...

  3. Spring MVC RedirectAttributes的用法解决办法

    Spring MVC RedirectAttributes的用法很久没发过技术贴了,今天对于一个问题纠结了2小时,遂放弃研究用另一种方法解决,奈何心中一直存在纠结,发帖求解 我先解释下什么是Redir ...

  4. JavaScript函数节流与函数去抖

    介绍 首先解释一下这两个概念: 函数节流(throttle):是让一个函数无法在很短的时间间隔内连续调用,当上一次函数执行后过了规定的时间间隔,才能进行下一次该函数的调用. 函数去抖(debounce ...

  5. Swift - 计算次方(2的N次方,2的随机次方)

    1,使用<<计算2的N次方 1 2 var value = 1<<4  //2的4次方 var value = 1<<Int(arc4random_uniform( ...

  6. 用yum查询想安装的软件

    1.使用YUM查找软件包  命令:yum search~  2.列出所有可安装的软件包  命令:yum list  3.列出所有可更新的软件包  命令:yum list updates  4.列出所有 ...

  7. c vs c++ in strcut and class

    c vs c++ in strcut and class 总习惯用c的用法,现在学习C++,老爱拿来比较.声明我用的是g++4.2.1 SUSE Linux.看例子吧 #include <ios ...

  8. 构建基于Javascript的移动web CMS——模板

    在上一篇<构建基于Javascript的移动CMS--Hello,World>讲述了墨颀 CMS的大概组成,并进行了一个简单的演示样例,即Hello,World.这一次,我们将把CMS简单 ...

  9. KMP算法详解(转自中学生OI写的。。ORZ!)

    KMP算法详解 如果机房马上要关门了,或者你急着要和MM约会,请直接跳到第六个自然段. 我们这里说的KMP不是拿来放电影的(虽然我很喜欢这个软件),而是一种算法.KMP算法是拿来处理字符串匹配的.换句 ...

  10. C++著名类库和C++标准库介绍

    C++著名类库 1.C++各大有名库的介绍——C++标准库 2.C++各大有名库的介绍——准标准库Boost 3.C++各大有名库的介绍——GUI 4.C++各大有名库的介绍——网络通信 5.C++各 ...