Uva10290 - {Sum+=i++} to Reach N
2014-07-31 17:47
183 查看
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
题意:问你N可以由多少种方案:连续的x个整数相加和为N
思路:转化为求奇因数,分解质因数后求排列数
{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
题意:问你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; }
相关文章推荐
- UVa 10290 - {Sum+=i++} to Reach N
- Uva10290 - {Sum+=i++} to Reach N
- UVa 10290 - {Sum+=i++} to Reach N
- UVa 10290 {Sum+=i++} to Reach N (数论-整数和素数,组合数学-排列组合)
- uva 10290 {Sum+=i++} to Reach N (数论-整数和素数)
- uva 10290 {Sum+=i++} to Reach N (数论-整数和素数)
- uva 10290 - {Sum+=i++} to Reach N(数论-整数因子分解)
- uva 1541 - To Bet or Not To Bet(记忆化+概率)
- nios 9.1 IDE报错:Unable to reach errno (at 0x) from the global pointer (at 0x0000b2b0) because t
- uva 10791【 Minimum Sum LCM】
- UVA 10828 Back to Kernighan-Ritchie 高斯约当消元
- 【LeetCode】Sum Root to Leaf Numbers
- 【UVA】1210 - Sum of Consecutive Prime Numbers
- Uva 12223 Moving to Nuremberg(树形dp)
- UVA - 10791 Minimum Sum LCM
- leetcode129---Sum Root to Leaf Numbers
- [LeetCode]Sum Root to Leaf Numbers
- UVA 10820 Send a Table 欧拉函数制phi表 累加sum
- uva 10071 Back to High School Physics
- Uva-202 - Repeating Decimals-WA to AC