题解
再结合代码应该就能看得懂了吧。。。
至于赛时怎么想出来的。我是观察样例得出来的
时间复杂度 \(O(2·t·\sqrt{n})\)
code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
inline void read(ll &x) {
x = 0;
ll flag = 1;
char c = getchar();
while(c < '0' || c > '9'){
if(c == '-') flag = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + (c ^ 48);
c = getchar();
}
x *= flag;
}
inline void write(ll x)
{
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
int main()
{
ll t;
read(t);
while(t--)
{
ll n,x;
read(n); read(x);
set<ll> q;
ll a=n+x-2, b=n-x;
for(ll i=1; i*i<=a; i++)
{
ll j=a/i;
if(a%i==0 && i%2==0 && ((i+2)>>1) >= x)
{
q.insert((i+2)>>1);
}
if(a%j==0 && j%2==0 && ((j+2)>>1) >= x)
{
q.insert((j+2)>>1);
}
}
for(ll i=1; i*i<=b; i++)
{
ll j=b/i;
if(b%i==0 && i%2==0 && ((i+2)>>1) >= x)
{
q.insert((i+2)>>1);
}
if(b%j==0 && j%2==0 && ((j+2)>>1) >= x)
{
q.insert((j+2)>>1);
}
}
write(q.size());
putchar('\n');
}
return 0;
}
标签:insert,read,ll,while,&&,j%,Lesson,Education,Physical
From: https://www.cnblogs.com/pure4knowledge/p/18014000