const int N = 5e6 + 5,M=5e5+5;
int t;
int cnt, p[M];
bool book[N];
ull phi[N];
void x_x_oula()
{
phi[1] = 1;
f(i, 2, N)
{
if (!book[i]) { p[cnt++] = i;phi[i] = i - 1; }
for (int j = 0;p[j] <= N / i;++j)
{
book[i*p[j]] = true;
if (i%p[j] == 0)
{
phi[i*p[j]] = phi[i] * p[j];
break;
}
phi[i*p[j]] = phi[i] * (p[j] - 1);
}
}
f(i, 2, N)phi[i] = phi[i - 1] + phi[i] * phi[i];
//f(i, 4900000, 4900200)cout << phi[i] << endl;
}
int main()
{
//freopen("in.txt", "r", stdin);
int a, b;
x_x_oula();
cin >> t;
int cot = 0;
while (t--)
{
scanf("%d%d", &a, &b);
printf("Case %d: ", ++cot);
cout << phi[b] - phi[a-1] << endl;
}
return 0;
}
Mathematically Hard(线性筛预处理欧拉函数)
最新推荐文章于 2021-09-10 20:44:55 发布