标签:因数分解 ase too ati continue 质因数 sqrt printf sha
#include<cstdio>
#include<cmath>
const int maxn = 1e6 + 10;
bool no_prime[maxn];
int prime[maxn];
int shai(int n)
{
int cnt = 0;
for (int i = 2; i <= n; i++)
{
if (!no_prime[i])
prime[++cnt] = i;
for (int j = 1; j <= cnt && prime[j] * i <= n; j++)
{
no_prime[prime[j] * i] = 1;
if (i % prime[j] == 0) break;
}
}
return cnt;
}
void solve()
{
int cnt = shai(maxn - 1);
int t;
scanf("%d", &t);
for (int i = 1; i <= t; i++)
{
long long n, r;
int b;
scanf("%lld%d", &n, &b);
if (b > sqrt(n))
{
printf("Case %d: 0\n", i);
continue;
}
r = n;
bool tag = 0;
long long ans = 1;
for (int i = 1; i <= cnt && 1ll * prime[i] * prime[i] <= r && n != 1; i++)
{
int p = prime[i];
int cnt = 0;
while (n % p == 0)
n /= p, cnt++;
ans *= (cnt + 1);
if (n <= 1e6 && !no_prime[n])
{
tag = 1;
ans *= 2;
break;
}
}
if (n != 1 && !tag)
ans *= 2;
ans /= 2;
for (int i = 1; i < b; i++)
if (r % i == 0) ans--;
printf("Case %d: %lld\n", i, ans);
}
}
int main()
{
freopen("Testin.txt", "r", stdin);
freopen("Testout.txt", "w", stdout);
solve();
return 0;
}
LightOJ1341 Aladdin and the Flying Carpet 约数相关问题
标签:因数分解 ase too ati continue 质因数 sqrt printf sha
原文地址:https://www.cnblogs.com/danzh/p/11412205.html