CF955C Sad powers
CF955C Sad powers
题面翻译
给你
数据范围:
。 。
Translated by Eason_AC
2021.10.8
题目描述
You're given
For each query you have to find the number of such
输入格式
The first line contains the number of queries
The next
输出格式
Output
样例 #1
样例输入 #1
6
1 4
9 9
5 7
12 29
137 591
1 1000000
样例输出 #1
2
1
0
3
17
1111
提示
In query one the suitable numbers are
Solution
2023 春赛观光团。
对于一个询问
考虑
记
对于一个数
代码实现的时候有一个很麻烦的东西,就是
Code
#include<bits/stdc++.h>
#define int long long
using namespace std;
int l, r;
int a[100005];
inline long double Qpow(int x, int y) {
long double res = 1, base = x;
for (; y; y >>= 1, base *= base) {
if (y & 1) {
res *= base;
}
}
return res;
}
inline int GetRoot(int x, int y) {
int v = powl(x, (long double)1.0 / y + 1e-9);
if (Qpow(v + 1, y) < x)
for (++v; Qpow(v + 1, y) < x; ++v);
if (Qpow(v, y) > x)
for (--v; Qpow(v, y) > x; --v);
return v;
}
int Calc(int n) {
if (n == 0) return 0;
int res = 1;
int lim = 0;
for (int i = 2; ; ++i) {
int v = GetRoot(n, i);
lim = i;
if (v <= 1) break;
a[i] = v - 1;
}
for (int i = lim - 1; i >= 2; --i) {
for (int j = i + i; j < lim; j += i) {
a[i] -= a[j];
}
}
for (int i = 2; i < lim; ++i) {
res += a[i];
}
return res;
}
void Solve() {
cin >> l >> r;
cout << Calc(r) - Calc(l - 1) << '\n';
}
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int T; cin >> T;
while (T--) Solve();
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步