题目链接:传送门
题意:找出1 <= x <= y <= n 内x2 + y2 成xy + 1倍数的数对个数。
思路:
代码:
#include<bits/stdc++.h>
using namespace std;
#define ll __int128
#define pb push_back
#define all(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof a)
const ll N = 1e6, M = 1e18;
vector<ll> v;
int t;
ll n;
ll read(){
ll x = 0, f = 1;
char c = 0;
while(!isdigit(c)) { if(c == '-') f = -1; c = getchar();}
while(isdigit(c)) { x = x * 10 + c - '0'; c = getchar();}
return x * f;
}
void init(){
v.pb(1LL);
for(ll i = 2; i <= N; i ++){
ll x = i, y = i * i * i, k = i * i;
while(y <= M){
v.pb(y);
ll tmp = x;
x = y;
y = x * k - tmp;
}
}
sort(all(v));
}
signed main(){
init();
t = read();
while(t --){
n = read();
int pos = upper_bound(all(v), n) - v.begin();
cout << pos << endl;
}
}
注意要__int128, 不然在初始化的时候就爆了