Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1000010;
- int test,n,m,p,q;
- long long s,ans,ss,k,z,tmp;
- bool check(long long x,long long y,long long k){
- if (x>m||y>n) return 0;
- long long z=k-x-y*m+1+m;
- if (z&1LL) return 0;
- z/=2LL;
- if (z>1LL*n*m-1) return 0;
- int p,q;
- q=z%m;
- p=z/m;
- if (p+y<=n&&q+x<=m) return 1;
- return 0;
- }
- vector<long long> us;
- long long fa[N];
- int fb[N];
- int na = 0;
- void dfs(long long a, long long b, long long c), long long value) {
- if (a * b * c == value) {
- if (check(a, b, c))
- return ;
- }
- }
- int main(){
- scanf("%d",&test);
- while (test--){
- scanf("%d%d%I64d",&n,&m,&s);
- ans=1e15;
- s*=2LL;
- us.clear();
- na = 0;
- for (int i = 1;(long long)i * i <= s ; ++i)
- if (s % i == 0) {
- fa[na] =
- na++;
- }
- int sm = (int)us.size();
- for (int pi = 0; pi < sm; ++ pi){
- long long i = us[pi];
- ss=s/i;
- for (int pj=0; pj < sm; ++pj){
- long long j = us[pj];
- if (ss%j==0){
- k=ss/j;
- if (check(i,j,k)) ans=min(ans,1LL*i*j);
- if (check(j,i,k)) ans=min(ans,1LL*i*j);
- if (check(k,i,j)) ans=min(ans,1LL*i*k);
- if (check(i,k,j)) ans=min(ans,1LL*i*k);
- if (check(j,k,i)) ans=min(ans,1LL*k*j);
- if (check(k,j,i)) ans=min(ans,1LL*k*j);
- }
- }
- }
- if (ans==1e15) ans=-1;
- printf("%I64d\n",ans);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement