题意:
求连续的一段数字和是给定的n 的组合种数
思路:
自己推一下就可以知道, n 的奇数因子都能提供一个组合方式
那样就转化为求 n 的素质因子的组合方式
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<map>
#define PI acos(-1.0)
#define in freopen("in.txt", "r", stdin)
#define out freopen("out.txt", "w", stdout)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e7 + 7, maxd = 670000 + 7, mod = 1e9 + 7;
const int INF = 0x7f7f7f7f;
ll n;
bool p[maxn];
int cnt = 0, prim[maxd];
void init() {
memset(p, 1, sizeof p);
cnt = 0;
for(int i = 4; i < maxn; i += 2)
p[i] = 0;
prim[cnt++] = 2;
for(int i = 3; i < maxn; i += 2) {
if(p[i]) {
prim[cnt++] = i;
}
for(int j = 0; prim[j]*i < maxn && j < cnt; ++j) {
p[i*prim[j]] = 0;
if( !(i%prim[j])) break;
}
}
//cout << cnt << endl;
//for(int i = 0; i < 10000; ++i)
// cout << prim[i] << " ";
}
int main() {
init();
int T;
scanf("%d", &T);
for(int tt = 1; tt <= T; ++tt) {
scanf("%lld", &n);
int ans = 1;
while(n % 2 == 0) n /= 2;
for(int i = 1; (ll)prim[i]*prim[i] <= n && i < cnt; ++i) {
if(n < maxn && p[n]) break;
int t = 0;
while(n % prim[i] == 0) {
t++;
n /= prim[i];
}
ans *= (t+1);
}
if(n > 1) ans *= 2;
printf("Case %d: %d\n", tt, ans-1);
}
return 0;
}