质因子
直接暴力枚举
C++ 代码
#include <bits/stdc++.h>
#define int long long
#define end '\n'
using namespace std;
const int N = 1e7 + 10;
int primes[N], cnt;
bool st[N];
inline void get(int x)
{
for (int i = 2; i <= x; i ++ )
{
if (!st[i]) primes[cnt ++] = i;
for (int j = 0; primes[j] * i <= x; i ++ )
{
st[primes[j] * i] = true;
if (i % primes[j] == 0) break;
}
}
}
inline int solve()
{
int n;
cin >> n;
int res = 1;
for (int i = 0; i < cnt && primes[i] * primes[i] <= n; i ++ )
{
int p = primes[i];
if (n % p == 0)
{
int s = 0;
while (n % p == 0) n /= p, s ++;
res *= (2 * s + 1);
}
}
if (n > 1) res *= (2 * 1 + 1);
return (res + 1) / 2;
}
signed main()
{
int t = 1;
cin >> t;
get(N);
for (int i = 1; i <= t; i ++)
printf("Case %lld: %lld\n", i, solve());
return 0;
}