链接:https://ac.nowcoder.com/acm/contest/11254/E
来源:牛客网
题目描述
Given n, count the number of pairs of positive integers (x, y), such that xy+1∣x2+y2,1≤x≤y≤nxy+1|x^2+y^2, 1\le x\le y \le nxy+1∣x2+y2,1≤x≤y≤n.
There're t test cases in total.
输入描述:
First line contains an integer t(1≤t≤105)t (1\le t\le 10^5)t(1≤t≤105). Next t lines each contains one integer n (1≤n≤1018)(1\le n \le 10^{18})(1≤n≤1018).
输出描述:
Output t lines, denoting the answer of each testcase.
示例1
输入
10 10 100 1000 10000 100000 114514 1919810 20190104 123123123123 10000001000000
输出
2 5 14 31 65 67 158 326 5226 22091
题解
题目说了这么 久就是一个意思
1~ n 中 有多少个整数对(x,y),
满足 (x^2 + y^2) /(x*y+1) 是一个平方数令f(x,y)= (x^2 + y^2) /(x*y+1)
f(i,i^3)=(i^2+i^6)/(i^4+1)=i^2
绝对成立的
还有种情况是 f(y,ky-x)
这也是成立的
比如f(i,i^3)转变成 f(y,ky-x)
就是f(i^3,i^5-i)=(i^6+(i^5-i)^2)/(i^8-i^3+1)=(i^10-i^6-i^2)/(i^8-i^3+1)=i^2
就一直这样可以循环下去
由于y是大于x的用类似打表方式把y存在数组中
由小到大排列
题目问1~n就只要
输出数组小于或者等于n就可以了
#include<bits/stdc++.h> using namespace std; #define ll long long const ll maxn = 1e18; int t; ll n , m = 0,v[5000010]; int main(){ v[m++] = 1; for(ll i = 2;i * i * i <= maxn;i++){ ll x = i, y = i * i * i; v[m++] = y; while(y <= (maxn + x) / i / i){ x = i * i * y - x; swap(x, y); v[m++] = y; } } sort(v, v + m); cin >> t; while(t--){ scanf("%lld",&n); printf("%lld\n",upper_bound(v, v + m, n) - v); } }