uva 10290 {Sum+=i++} to Reach N (数论-整数和素数)
2014-07-31 20:00
441 查看
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
(Math Lovers’ Contest, Problem Setter: Shahriar Manzoor)
题目大意:
问一个数n用连续的几个数相加表示的方案数。
解题思路:
假设首项为a,有m项,则 (a+a+m-1)*m=2*n,所以为奇数*偶数的结果,只需要算出2*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
(Math Lovers’ Contest, Problem Setter: Shahriar Manzoor)
题目大意:
问一个数n用连续的几个数相加表示的方案数。
解题思路:
假设首项为a,有m项,则 (a+a+m-1)*m=2*n,所以为奇数*偶数的结果,只需要算出2*n用奇数表示的方法数即可。
解题代码:
#include <iostream> #include <cstdio> #include <map> #include <vector> #include <cstring> using namespace std; typedef long long ll; const int maxn=30000010; bool isPrime[maxn]; vector <ll> v; ll tol; void get_prime(){ tol=0; memset(isPrime,true,sizeof(isPrime)); for(ll i=2;i<maxn;i++){ if(isPrime[i]){ tol++; v.push_back(i); } for(ll j=0;j<tol && i*v[j]<maxn;j++){ isPrime[i*v[j]]=false; if(i%v[j]==0) break; } } //for(ll i=0;i<20;i++) cout<<v[i]<<endl; } inline map <ll,ll> getPrime(ll x){ map <ll,ll> mp; for(ll i=0;i<tol && x>=v[i]*v[i];i++){ while(x>0 && x%v[i]==0){ x/=v[i]; mp[v[i]]++; } } if(x>1) mp[x]++; return mp; } int main(){ get_prime(); ll x; while(cin>>x){ ll sum=1; map <ll,ll> mp=getPrime(2*x); for(map <ll,ll>::iterator it=mp.begin();it!=mp.end();it++){ //cout<<it->first<<" "<<it->second<<endl; if((it->first)&1) sum*=(it->second+1); } cout<<sum<<endl; } return 0; }
相关文章推荐
- 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
- Uva10290 - {Sum+=i++} to Reach N
- UVa 10290 - {Sum+=i++} to Reach N
- Uva10290 - {Sum+=i++} to Reach N
- UVa 10791 - Minimum Sum LCM (数论 推理)
- 算法导论-----数论-----素数测试和pollard整数因子分解
- uva 10791 Minimum Sum LCM(数论)
- UVA - 10791 - Minimum Sum LCM (数论相关!)
- HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)
- 数论之大素数检测与大整数分解(10^18)
- UVa 10791 Minimum Sum LCM (数论&素因子分解)
- UVa 10791 - Minimum Sum LCM 质因数分解加素数筛优化
- UVa 10791 - Minimum Sum LCM 质因数分解加素数筛优化
- 数论寻找等差素数UVA 10650
- UVA 10791 Minimum Sum LCM (数论)
- 数论——素数筛选法与整数的素因子分解
- uva 10773 - Back to Intermediate Math(数论)