博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Uva10290 - {Sum+=i++} to Reach N
阅读量:4558 次
发布时间:2019-06-08

本文共 1733 字,大约阅读时间需要 5 分钟。

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 
#include
#include
#include
#include
#include
#include
using namespace std;const int maxn = 1e7+10;typedef long long ll;bool isPrime[maxn];vector
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<
<
= 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<
<

转载于:https://www.cnblogs.com/mengfanrong/p/3946491.html

你可能感兴趣的文章
NEFU 109
查看>>
HDU 5435
查看>>
git从已有分支拉新分支开发
查看>>
滚动条隐藏兼容写法
查看>>
SQL2005查询所有表的大小
查看>>
Shell 正则表达式
查看>>
Docker run命令参数整理
查看>>
qt-opencv配置mingw编译器
查看>>
CSS之Medial Queries的另一用法:实现IE hack的方法
查看>>
linux-CentOS6.4下安装oracle11g详解
查看>>
实力为王 八年DBA经验谈
查看>>
2-sat 问题 【例题 Flags(2-sat+线段树优化建图)】
查看>>
ext3.2 右击动态添加node的treepanel
查看>>
Database links
查看>>
1035 插入与归并(25 分)
查看>>
STL中排序函数的用法(Qsort,Sort,Stable_sort,Partial_sort,List::sort)
查看>>
如何解决php 生成验证码图片不显示问题
查看>>
PHP,javascript实现大文件上传
查看>>
c#图像处理算法学习
查看>>
webApi之FromUri和FromBody区别
查看>>