题目分析
我们首先可以发现如果一个数x能转化为另一个y进制,很明显x能整除y。这样一来就转化成求因子数
x=p1a1∗p2a2∗p3a3∗.......∗pnan
这样因子个数为:
ans=(1+a1)∗(1+a2)∗(1+a3)∗......∗(1+an).
但是这里面因子包括了1,后来我们需要去掉。
#include <cstdio>
#include <cmath>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 1e6+100;
#define LL long long
int prime[80000], vis[maxn];
void init(){ //素数打表
int tot = 0;
for(LL i = 2; i < maxn; i++)if(!vis[i]){
prime[tot++] = i;
for(LL j = i*i; j < maxn; j += i) vis[j] = 1;
}
}
void solve(LL x){
LL ans = 1;
for(int i = 0; (LL)prime[i]*prime[i] <= x; i++) if(x%prime[i] == 0){
int tot = 0;
while(x%prime[i] == 0){
tot++;
x /= prime[i];
}
ans *= (tot+1);
}
if(x > 1) ans *= 2; //说明x存在大于1e6+100的因子,需要乘以(1+1).
printf("%lld\n", ans-1); //去除1
}
int main(){
init();
int T;
scanf("%d", &T);
for(int kase = 1; kase <= T; kase++){
LL x;
scanf("%lld", &x);
if(x == 1) printf("Case %d: 0\n", kase);
else{
printf("Case %d: ", kase);
solve(x);
}
}
return 0;
}