Given an integer , you have to find the number of ways you can express as sum of consecutive integers. You have to use at least two integers.
For example, has three solutions,
Input
Input starts with an integer
denoting the number of test cases.
Each case starts with a line containing an integer
Output
For each case, print the case number and the number of ways to express
as sum of consecutive integers.
Sample Input
5
10
15
12
36
828495
Sample Output
Case 1: 1
Case 2: 3
Case 3: 1
Case 4: 2
Case 5: 47
给你一个正整数 ,用一段连续正整数的和表示 的方法有多少种?
也就是找奇数因子的个数
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn = 10000000, INF = 0x7fffffff;
int primes[1000000];
bool vis[maxn];
int ans = 0;
void init()
{
memset(vis,0,sizeof(vis));
for(int i=2; i<maxn; i++)
{
if(vis[i]) continue;
primes[ans++] = i;
for(LL j=(LL)i*i; j<maxn; j+=i)
vis[j] = 1;
}
}
int main()
{
init();
int t;
scanf("%d",&t);
int kase=0;
while(t--)
{
LL n, res = 1;
cin>> n;
for(int i=0; i<ans && primes[i]*primes[i] <= n; i++)
{
LL cnt2 = 0;
while(n % primes[i] == 0)
{
n /= primes[i];
cnt2++;
}
if(cnt2 > 0 && primes[i] % 2)
res *= (cnt2 + 1);
}
if(n > 1 && n % 2)
{
res *= 2;
}
printf("Case %d: %lld\n", ++kase, res - 1);
}
return 0;
}