Codeforces 758F Geometrical Progression

时间:2023-03-09 08:32:12
Codeforces 758F Geometrical Progression

Geometrical Progression

n == 1的时候答案为区间长度, n == 2的时候每两个数字都可能成为答案,

我们只需要考虑 n == 3的情况, 我们可以枚举公差, 其分子分母都在sqrt(1e7)以内,

然后暴力枚举就好啦。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, l, r; struct Node {
int x, y;
bool operator < (const Node& rhs) const {
return x * rhs.y < rhs.x * y;
}
bool operator == (const Node& rhs) const {
return x * rhs.y == rhs.x * y;
}
}; vector<Node> vc; int Power(int a, int b) {
int ans = ;
while(b) {
if(b & ) ans = ans * a;
a = a * a; b >>= ;
}
return ans;
}
int main() {
scanf("%d%d%d", &n, &l, &r);
if(n > ) {
puts("");
} else if(n == ) {
printf("%d\n", r - l + );
} else if(n == ) {
printf("%lld\n", 1ll * (r - l + ) * (r - l));
} else {
for(int i = ; i * i <= r; i++) {
for(int j = ; j * j <= r; j++) {
if(i == j) continue;
int x = i, y = j;
int gcd = __gcd(x, y);
vc.push_back(Node{x / gcd, y / gcd});
}
}
sort(vc.begin(), vc.end());
vc.erase(unique(vc.begin(), vc.end()), vc.end());
LL ans = ;
for(auto& t : vc) {
LL x = t.x, y = t.y;
bool flag = true;
for(int i = ; i <= n; i++) {
y = y * t.y;
if(y > r) {
flag = false;
break;
}
}
if(!flag) continue;
for(int i = ; i <= n; i++) {
x = x * t.x;
if(x > 10000000LL * y) {
flag = false;
break;
}
}
if(!flag) continue; int Ly = ((l - ) / y) + , Ry = r / y;
int Lx = ((l - ) / x) + , Rx = r / x;
if(Ly > Ry) continue;
if(Lx > Rx) continue;
if(Lx > Ry) continue;
if(Rx < Ly) continue;
Lx = max(Lx, Ly);
Rx = min(Rx, Ry);
ans += Rx - Lx + ;
}
printf("%lld\n", ans);
}
return ;
} /*
3 1 10000000
*/