大意: 定义m-free矩阵: 所有$m*m$的子矩阵至少有一个$0$的$01$矩阵.

定义一个函数$f(n,m)=n*n$的m-free矩阵最大$1$的个数.

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

给出$t$个询问, 每个询问给出$x$, 求输出$f(n,m)=x$的任意一组$(n,m)$.

 

显然可以得到$f(n,m)=n^2-\lfloor\frac{n}{m}\rfloor ^2$

 

#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <string.h>
#include <bitset>
#include <unordered_map>
#define REP(i,a,n) for(int i=a;i<=n;++i)
#define PER(i,a,n) for(int i=n;i>=a;--i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(a) ({REP(__i,1,n) cout<<a[__i]<<' ';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 4e4+10;
int sqr(int x) {return x*x;}
int f(int x, int y) {
	if (y>x||y<=0) return -1;
	return sqr(x)-sqr(x/y);
}

int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		int x;
		scanf("%d", &x);
		if (!x) {puts("1 1");continue;}
		int n=0,m=0;
		REP(i,1,N) if (i*i>x) {
			int j = i/sqrt(i*i-x);
			REP(k,j-10,j+10) if (f(i,k)==x) n=i,m=k;
		}
		if (n) printf("%d %d\n",n,m);
		else puts("-1");
	}
}

 

 

 

 

 

 

 

 

 

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄