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 example9Can be expressed in three such ways,2 + 3 + 4,4 + 5Or9. Given an integer less(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 less1100Lines of input. Each line contains a single integerN (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 waysNCan be expressed as summation of consecutive integers.
Sample Input
9
11
12
Sample output
3
2
2
Question: How many solutions can n be used: the sum of X consecutive integers and N
Train of Thought: convert it to an odd factor, and separate the prime factor to find the number of permutation
#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