「CFgym100541」Pencil Game
题解
我是傻逼T T
如果确定了矩形的长宽,就比较容易判是否可行
然后考虑枚举面积K
K一定是2L的约数,且K不会超过根号L级别
然后再枚举一条边,同样只要根号K
我是傻逼T T
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
#include<iostream> #include<cstdio> #include<cstring> #include<cstdlib> #include<set> #include<ctime> #include<vector> #include<queue> #include<algorithm> #include<map> #include<cmath> #define eps 1e-6 #define inf 1000000000 #define mod 1000000009 #define pa pair<int,int> #define ll long long using namespace std; ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int T; ll n,m,tot; ll L,sum[2000005]; bool cal(int x,int y) { tot++; if(x>n||y>m)return 0; int t1=n-x,t2=m-y; ll tmp=sum[x-1]*y+x*sum[y-1]*n; if(tmp>L)return 0; tmp=L-tmp; ll k=x*y;if(tmp%k!=0)return 0; tmp/=k; if(t2*n+t1<tmp)return 0; if(t1<tmp%n)return 0; return 1; } int main() { for(int i=1;i<=2000000;i++)sum[i]=sum[i-1]+i; T=read(); while(T--) { m=read();n=read();L=read(); bool flag=0; for(ll x=1;sum[x-1]<=L;x++) if(L*2%x==0) { for(ll i=1;i*i<=x;i++) if(x%i==0) { flag|=cal(i,x/i); flag|=cal(x/i,i); if(flag)break; } if(flag) { cout<<x<<endl; break; } } if(!flag)puts("-1"); } return 0; } |
Subscribe