CF1996D 题解
2024/9/26:将 更改为 ,感谢 @5t0_0r2。
先枚举 ,再枚举 ,然后求出 的范围就可以统计答案了。
看似会超时,但是这个 ,所以时间过得去。
对于确定的 ,就能求出
代码
#include<bits/stdc++.h>
using namespace std;
inline void ri(int &_a){
int res=0,f=1;
char c;
for(;(c=getchar())<'0'||c>'9';c=='-'?f=-f:0);
while(c>='0' && c<='9') res=(res<<1) + (res<<3) + c-'0',c=getchar();
_a=res*f;
}
inline void rll(long long &_a){
long long res=0ll,f=1;
char c;
for(;(c=getchar())<'0'||c>'9';c=='-'?f=-f:0);
while(c>='0' && c<='9') res=(res<<1) + (res<<3) + c-'0',c=getchar();
_a=res*f;
}
/*-----------------*/
int t,n,x;
int main(){
ri(t);
while(t--){
ri(n),ri(x);
long long ans=0;
for(int i=1;i<=x;i++){
for(int j=1;1ll*j*i<=n&&i+j<=x;j++){
int p=(n-i*j)/(i+j),q=x-i-j;
ans+=min(p,q);
}
}
printf("%lld\n",ans);
}
return 0;
}

浙公网安备 33010602011771号