Problem:
Problem H: Squid Multiplication
Squid Eiko loves mathematics.
Especially she loves to think about integer.
One day, Eiko found a math problem from a website.
"A sequence
b
={
a
i
+
a
j
|
i
<
j
}  is generated from a sequence
a
={
a
0
, ... ,
a
n
|
a
i
is even if
i
is 0, otherwise
a
i
is odd}. Given the sequence
b
, find the sequence
a
."
This problem is easy for Eiko and she feels boring. So, she made a new problem by modifying this problem .
"A sequence
b
={
a
i
*
a
j
|
i
<
j
}  is generated from a sequence
a
={
a
0
, ... ,
a
n
|
a
i
is even if
i
is 0, otherwise
a
i
is odd}. Given the sequence
b
, find the sequence
a
."
Your task is to solve the problem made by Eiko.
Input
Input consists of multiple datasets.
Each dataset is given by following formats.
n
b
0
b
1
...
b
n*(n+1)/2-1
n
is the number of odd integers in the sequence
a
. The range of
n
is 2 ≤
n
≤ 250.
b
i
is separated by a space.
Each
b
i
is 1 ≤
b
i
≤ 2
63
-1.
The end of the input consists of a single 0.
Output
For each dataset, you should output two lines.
First line contains
a
0
, an even number in the sequence
a
.
The second line contains
n
odd elements separated by a space. The odd elements are sorted by increasing order.
You can assume that the result is greater than or equal to 1 and less than or equal to 2
31
-1.
Sample input
3
6 10 14 15 21 35
2
30 42 35
0
Sample output
2
3 5 7
6
5 7

Submitted solutions:

code_snippet: #include <stdio.h>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <algorithm>
using namespace std;
#define MAXN 450000
typedef long long LL;
LL b[MAXN];
LL a[MAXN];
LL gcd(LL aa,LL bb){
    if(!bb){
		return aa;
	}
    return gcd(bb,aa%bb);
}
LL solve(LL &X,LL &Y,LL up,int n){
	  LL tmp0 = gcd(b[0],b[n]);
      X = b[0]/tmp0;
	  Y = b[n]/tmp0;
	  LL tmp1;
	  tmp1 = b[1];
	  tmp1/=X;
	  tmp1/=Y;
	  LL g = (LL)sqrt(tmp1*1.0);
	  return g;
}
void output(int n){
	printf("%lld\n",a[0]);
	sort(a+1,a+1+n);
	printf("%lld",a[1]);
	for(int i=2;i<=n;++i)
		printf(" %lld",a[i]); 
	printf("\n");
}
int main(){
	  int n;
	  while(scanf("%d",&n)!=EOF){
		  if(!n)break;
		  int up = (n+1)*n/2;
		  for(int i=0;i<up;++i){
			scanf("%lld",&b[i]);
		  }
		  LL X,Y;
		  LL g = solve(X,Y,up,n);
		  a[0] = X*g;
		  for(int i=1;i<=n;++i){
			  a[i] = b[i-1]/a[0];
		  }
		  output(n);
	  }
  return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 5004
final_rank: 8

code_snippet: #include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#define eps 1e-8
#define MAXN 260
using namespace std;
long long odd[MAXN * MAXN], even[MAXN * MAXN];
int p1, p2;

int n;

long long gcd(long long a, long long b)
{
	long long c;
	while (a % b > 0)
	{
		c = a % b;
		a = b;
		b = c;
	}
	return b;
}

int main()
{
	int i;
	long long d;
	double tmp;
	long long a0, a1, g, p, q, r;
	while (scanf("%d", &n) && n != 0)
	{
		for (i = p1 = p2 = 0; i < (n + 1) * n / 2; i++)
		{
			cin >> d;
			if (d % 2 == 0)
				even[p2++] = d;
			else
				odd[p1++] = d;
		}
		sort (odd, odd + p1);
		sort (even, even + p2);
		g = gcd(even[0], even[1]);
		// cout << g << " " << even[0] << " " << even[1] << endl;
		p = even[0] / g;
		q = even[1] / g;
		r = odd[0];
		// cout << p << endl;
		// cout << q << endl;
		// cout << r << endl;
		tmp = 1.0 * r / q * p;
		a1 = (long long)(sqrt(tmp) + eps);
		//a1 = (long long)(sqrt((r / q) * p) + eps);
		// printf("a1: %lld\n", a1);
		a0 = even[0] / a1;
		cout << a0 << endl;
		for (i = 0; i < p2; i++)
		{
			cout << even[i] / a0;
			if (i == p2 - 1)
				cout << endl;
			else
				cout << " ";
		}
	}
	return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3748
final_rank: 15

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _max(a, b) ((a) > (b) ? (a) : (b))
#define R register
ll n, m;
ll x[10000010], odd;
void _Init() {
    m = n * (n + 1) / 2;
    ll cnt = 0;
    odd = 0x7fffffffffffffffLL;
    for(int i = 0; i < m; i++) {
        ll t;
        cin >> t;
        if((t % 2) == 0)
            x[cnt++] = t;
        else
            odd = min(odd, t);
    }
}

void solve() {
    sort(x, x + n);
    ll base = round(sqrt((double)x[0] * x[1] / odd));
    cout << base << endl;
    for(int i = 0; i < n; i++) {
        if(i)
            cout << " ";
        cout << x[i] / base;
    }
    cout << endl;
}
int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    while(cin >> n) {
        if(n == 0)
            break;
        _Init();
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3224
final_rank: 7

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _max(a, b) ((a) > (b) ? (a) : (b))
#define R register
ll n, m;
ll x[10000010], odd;
void _Init() {
    m = n * (n + 1) / 2;
    ll cnt = 0;
    odd = 0x7fffffffffffffffLL;
    for(int i = 0; i < m; i++) {
        ll t;
        cin >> t;
        if((t % 2) == 0)
            x[cnt++] = t;
        else
            odd = min(odd, t);
    }
}

void solve() {
    sort(x, x + n);
    ll base = (ll)(sqrt(x[0] * 1.0 * x[1] / odd) + 0.5);
    cout << base << endl;
    for(int i = 0; i < n; i++) {
        if(i)
            cout << " ";
        cout << x[i] / base;
    }
    cout << endl;
}
int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    while(cin >> n) {
        if(n == 0)
            break;
        _Init();
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3064
final_rank: 5

code_snippet: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _max(a, b) ((a) > (b) ? (a) : (b))
#define R register
ll n, m;
ll x[10000010], odd;
void _Init() {
    m = n * (n + 1) / 2;
    ll cnt = 0;
    odd = 0x7fffffffffffffffLL;
    for(int i = 0; i < m; i++) {
        ll t;
        cin >> t;
        if((t % 2) == 0)
            x[cnt++] = t;
        else
            odd = min(odd, t);
    }
}

void solve() {
    sort(x, x + n);
    ll base = (ll)(sqrtl(x[0] * 1.0 * x[1] / odd) + 0.5);
    cout << base << endl;
    for(int i = 0; i < n; i++) {
        if(i)
            cout << " ";
        cout << x[i] / base;
    }
    cout << endl;
}
int main() {
#ifdef LOCAL
    freopen("data.in", "r", stdin);
    freopen("data.out", "w", stdout);
#endif
    while(cin >> n) {
        if(n == 0)
            break;
        _Init();
        solve();
    }

    return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3112
final_rank: 6

code_snippet: #include<bits/stdc++.h>
using namespace std;

const int N = 500;
int n;
vector<long long> even;
vector<long long> odd;
long long x;

int main() {
	while(cin>>n && n) {
		even.clear();
		odd.clear();
		for(int i=0;i<n*(n+1)/2;i++) {
			cin>>x;
			if(x&1)
				odd.push_back(x);
			else 
				even.push_back(x);
		}
		sort(even.begin(),even.end());
		sort(odd.begin(),odd.end());

		long long a0 = sqrt((double)even[0]/(double)odd[0]*(double)even[1])+0.5;
		cout<<a0<<endl;
		for(int i=0;i<even.size();i++) {
			if(i) cout<<" ";
			cout<<even[i] / a0;
		}
		cout<<endl;
	}
}
accuracy: 1
time_ms: 200
memory_kb: 3284
final_rank: 14

code_snippet: #include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define X first
#define Y second
using namespace std;

typedef long long int ll;
typedef vector <int> vi;
typedef pair <int,int> pii;
const int Size=1e6+10;
const int INF=0x3f3f3f3f;

inline 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;
}


ll gcd(ll a,ll b)
{
    if (b==0) return a;
    return gcd(b,a%b);
}

ll n_gcd(vector<ll> a)
{
    ll res=a[0];
    int siz=a.size();
    for (int i=1;i<siz;++i) res=gcd(res,a[i]);
    return res;
}

int main()
{
    while (1)
    {
        int n=read();
        if (!n) break;

        vector<ll> odd,even;
        int N=n*(n+1)/2;
        ll t;
        for (int i=0;i<N;++i)
        {
            t=read();
            if (t%2==0) even.pb(t);
                else odd.pb(t);
        }
        sort(even.begin(),even.end());
        sort(odd.begin(),odd.end());

        ll gcd=n_gcd(even),gcd_odd;
        int siz=even.size();
        for (int i=0;i<siz;++i)
            even[i]/=gcd;
        gcd_odd=sqrt(odd[0]/even[0]/even[1]);

        ll e=gcd/gcd_odd;
        printf("%lld\n",e);
        for (int i=0;i<siz;++i)
        {
            if (i) printf(" ");
            printf("%lld",even[i]*gcd_odd);
        }
        puts("");
    }



    return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3692
final_rank: 2

code_snippet: #include<bits/stdc++.h>
using namespace std;
typedef long long ll;


int main(){
  ll n;
  while(cin>>n,n){
    vector<ll> e,o;
    for(ll i=0,x;i<n*(n+1)/2;i++){
      cin>>x;
      if(x%2)o.push_back(x);
      else e.push_back(x);
    }
    sort(e.begin(),e.end());
    sort(o.begin(),o.end());
    ll x=e[0],y=e[1],z=o[0];
    ll tp=__gcd(x,z);
    x/=tp,z/=tp,y/=z;
    ll an=sqrt(x*y+0.1);
    cout<<an<<endl;
    for(ll i=0;i<e.size();i++){
      if(i)cout<<' ';
      cout<<e[i]/an;
    }
    cout<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 3356
final_rank: 16

code_snippet: #include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <vector>
#include <stack>
#include <map>
#include <set>
#include <utility>
#define cs cout << "Wish You AC!" << endl;
#define js ios::sync_with_stdio(false); cin.tie(0);
#define MEM(a,x) memset(a,x,sizeof(a))
#define lowbit(x) (x&-x)
#define lson(x) x*2
#define rson(x) x*2 + 1
#define ll long long
#define ull unsigned long long
#define debug(x) std::cout << #x << " is " << (x) << '\n'
#define INF 1e8
#define pb push_back
#define pii pair<ll, ll>
using namespace std;
inline void read(ll &x){
    char c; int flag=0;
    while(!isdigit(c=getchar()))
        if(c=='-') flag=1;
    x=c-'0';
    while(isdigit(c=getchar()))
        x=x*10+c-'0';
    if(flag) x=-x;
}
const int N = 2e6 + 10;
ll a[N];
ll b[N];
int main()
{
    ll n;
    while(cin >> n)
    {
        if(!n) break;
        double t = 1;
        ll nn = n*(n+1)/2 - 1;
        for(ll i = 0; i <= nn; i++){
            cin >> b[i];
            if(b[i] % 2 == 0){
                t *= pow((double)b[i], 1.0/n);
            }
            else t *= pow((double)b[i], -1.0/n/(n-1));
        }
        ll aa = (ll)(t+0.5);
        ll cnt = 0;
        for(ll i = 0; i <= nn; i++){
            if(b[i] % 2 == 0){
                a[++cnt] = b[i] / aa;
            }
        }
        sort(a+1, a+cnt+1);
        cout << aa << endl;
        for(ll i = 1; i <= cnt; i++){
            if(i > 1) cout << ' ';
            cout << a[i];
        }
        cout << endl;
    }
    return 0;
}
accuracy: 1
time_ms: 210
memory_kb: 3604
final_rank: 17

code_snippet: #include<cstdio>
#include<algorithm>
#include<vector>
#include<cmath>

#define MAXX 65555

unsigned long long gcd(const unsigned long long &a,const unsigned long long &b)
{
    return b?gcd(b,a%b):a;
}

unsigned long long n,i,j,k,m;
unsigned long long num[MAXX],g;
std::vector<unsigned long long>ev,od;

int main()
{
    ev.reserve(MAXX);
    od.reserve(MAXX);
    while(scanf("%llu",&n),n)
    {
        m=n*(n+1)/2;
        ev.resize(0);
        od.resize(0);
        for(i=0;i<m;++i)
        {
            scanf("%llu",num+i);
            if(!(num[i]&1))
                ev.push_back(num[i]);
            else
                od.push_back(num[i]);
        }
        std::sort(ev.begin(),ev.end());
        std::sort(od.begin(),od.end());
        g=ev[0];
        for(i=1;i<ev.size();++i)
            g=gcd(g,ev[i]);
        k=od[0]/(ev[0]/g)/(ev[1]/g);
        g/=sqrt(k);
        printf("%llu\n%llu",g,ev[0]/g);
        for(i=1;i<ev.size();++i)
            printf(" %llu",ev[i]/g);
        puts("");
    }
    return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 2908
final_rank: 1

code_snippet: #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1069"

#include<bits/stdc++.h>
using namespace std;

#define call_from_test
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
/*
  multiprecision:
  #include <boost/multiprecision/cpp_int.hpp>
  using Int = boost::multiprecision::cpp_int;
*/
#endif
//BEGIN CUT HERE
__int128_t abs128(__int128_t val){return val<0?-val:val;}

ostream &operator<<(ostream &os,__int128_t val){
  if(ostream::sentry(os)){
    __uint128_t tmp=abs128(val);
    char buf[64];
    char *d=end(buf);
    do{
      --d;
      *d=char(tmp%10+'0');
      tmp/=10;
    }while(tmp);
    if(val<0) *--d='-';
    int len=end(buf)-d;
    if(os.rdbuf()->sputn(d,len)!=len){
      os.setstate(ios_base::badbit);
    }
  }
  return os;
}

istream &operator>>(istream &is,__int128_t &val){
  string s;
  is>>s;
  val=0;
  for(int i=0;i<(int)s.size();i++)
    if(isdigit(s[i])) val=val*10+s[i]-'0';
  if(s[0]=='-') val*=-1;
  return is;
}
//END CUT HERE
#ifndef call_from_test
//INSERT ABOVE HERE
signed main(){
  return 0;
}
#endif

#undef call_from_test

using ll = __int128_t;

ll sqrt(ll x){
  assert(x>=0);
  if(x<=1) return x;
  ll l=0,r=x;
  while(l+1<r){
    ll m=(l+r)>>1;
    if(m<=x/m&&m*m<=x) l=m;
    else r=m;
  }
  return l;
}

signed main(){
  int n;
  while(cin>>n,n){
    int m=n*(n+1)/2;

    vector<ll> bs(m),es,os;
    for(int i=0;i<m;i++) cin>>bs[i];
    for(ll b:bs)
      ((b&1)?os:es).emplace_back(b);

    sort(es.begin(),es.end());
    sort(os.begin(),os.end());

    ll a=sqrt(es[0]*es[1]/os[0]);
    cout<<a<<endl;
    for(int i=0;i<n;i++){
      if(i) cout<<" ";
      cout<<es[i]/a;
    }
    cout<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 4560
final_rank: 13

code_snippet: #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1069"

#include<bits/stdc++.h>
using namespace std;

#define call_from_test
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
#endif
//BEGIN CUT HERE
struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;
//END CUT HERE
#ifndef call_from_test
signed main(){
  return 0;
}
#endif

#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
/*
  multiprecision:
  #include <boost/multiprecision/cpp_int.hpp>
  using Int = boost::multiprecision::cpp_int;
*/
#endif
//BEGIN CUT HERE
using ll = __int128_t;
ll abs128(ll val){return val<0?-val:val;}

ostream &operator<<(ostream &os,ll val){
  if(ostream::sentry(os)){
    __uint128_t tmp=abs128(val);
    char buf[64];
    char *d=end(buf);
    do{
      --d;
      *d=char(tmp%10+'0');
      tmp/=10;
    }while(tmp);
    if(val<0) *--d='-';
    int len=end(buf)-d;
    if(os.rdbuf()->sputn(d,len)!=len){
      os.setstate(ios_base::badbit);
    }
  }
  return os;
}

istream &operator>>(istream &is,ll &val){
  string s;
  is>>s;
  val=0;
  for(int i=0;i<(int)s.size();i++)
    if(isdigit(s[i])) val=val*10+s[i]-'0';
  if(s[0]=='-') val*=-1;
  return is;
}
//END CUT HERE
#ifndef call_from_test

template<typename T>
T extgcd(T a,T b,T& x,T& y){
  T d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;y=0;
  }
  return d;
}

template<typename T>
T mod_inverse(T a,T mod){
  T x,y;
  extgcd(a,mod,x,y);
  return (x%mod+mod)%mod;
}

//INSERT ABOVE HERE
signed main(){
  ll n,R;
  ll cnt=0;
  while(cin>>n>>R,n){
    cout<<"Case #"<<++cnt<<":";
    ll r=R;
    vector<ll> v(n);
    for(ll i=0;i<n;i++){
      ll k;
      cin>>k;
      v[i]=k;
    }
    ll g=v[0];
    for(ll i=0;i<n;i++) g=__gcd(g,v[i]);
    if(abs128(r)%g){
      cout<<" Stupid keypad!"<<endl;
      continue;
    }
    vector<ll> ans(n,0);
    auto print=
      [&](){
        ll tmp=0;
        for(ll i=0;i<n;i++) tmp+=v[i]*ans[i];
        assert(tmp==r);
        for(ll i=0;i<n;i++) cout<<" "<<ans[i];
        cout<<endl;
      };

    bool f=0;
    for(ll i=0;i<n;i++){
      if(abs128(r)%v[i]==0){
        ans[i]=r/v[i];
        f=1;
        break;
      }
    }

    if(f){
      print();
      continue;
    }

    ll res=v[0];
    ans[0]=1;
    for(ll i=1;i<n;i++){
      ll k=__gcd(res,v[i]);
      if(k==res) continue;
      ll x,y;
      extgcd(res,v[i],x,y);
      for(ll j=0;j<i;j++) ans[j]*=x;
      ans[i]=y;
      res=k;
    }
    for(ll i=0;i<n;i++) ans[i]*=(r/res);
    print();
  }

  return 0;
}

/*
  verified on 2019/10/22
  https://vjudge.net/problem/UVA-12980
*/
#endif

#undef call_from_test

ll sqrt(ll x){
  assert(x>=0);
  if(x<=1) return x;
  ll l=0,r=x;
  while(l+1<r){
    ll m=(l+r)>>1;
    if(m<=x/m&&m*m<=x) l=m;
    else r=m;
  }
  return l;
}

signed main(){
  int n;
  while(cin>>n,n){
    int m=n*(n+1)/2;

    vector<ll> bs(m),es,os;
    for(int i=0;i<m;i++) cin>>bs[i];
    for(ll b:bs)
      ((b&1)?os:es).emplace_back(b);

    sort(es.begin(),es.end());
    sort(os.begin(),os.end());

    ll a=sqrt(es[0]*es[1]/os[0]);
    cout<<a<<endl;
    for(int i=0;i<n;i++){
      if(i) cout<<" ";
      cout<<es[i]/a;
    }
    cout<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 100
memory_kb: 4508
final_rank: 12

code_snippet: #define PROBLEM "http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1069"

#include<bits/stdc++.h>
using namespace std;

#define call_from_test
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
/*
  multiprecision:
  #include <boost/multiprecision/cpp_int.hpp>
  using Int = boost::multiprecision::cpp_int;
*/
#endif
//BEGIN CUT HERE
using ll = __int128_t;
ll abs128(ll val){return val<0?-val:val;}

ostream &operator<<(ostream &os,ll val){
  if(ostream::sentry(os)){
    __uint128_t tmp=abs128(val);
    char buf[64];
    char *d=end(buf);
    do{
      --d;
      *d=char(tmp%10+'0');
      tmp/=10;
    }while(tmp);
    if(val<0) *--d='-';
    int len=end(buf)-d;
    if(os.rdbuf()->sputn(d,len)!=len){
      os.setstate(ios_base::badbit);
    }
  }
  return os;
}

istream &operator>>(istream &is,ll &val){
  string s;
  is>>s;
  val=0;
  for(int i=0;i<(int)s.size();i++)
    if(isdigit(s[i])) val=val*10+s[i]-'0';
  if(s[0]=='-') val*=-1;
  return is;
}
//END CUT HERE
#ifndef call_from_test

template<typename T>
T extgcd(T a,T b,T& x,T& y){
  T d=a;
  if(b!=0){
    d=extgcd(b,a%b,y,x);
    y-=(a/b)*x;
  }else{
    x=1;y=0;
  }
  return d;
}

template<typename T>
T mod_inverse(T a,T mod){
  T x,y;
  extgcd(a,mod,x,y);
  return (x%mod+mod)%mod;
}

//INSERT ABOVE HERE
signed main(){
  ll n,R;
  ll cnt=0;
  while(cin>>n>>R,n){
    cout<<"Case #"<<++cnt<<":";
    ll r=R;
    vector<ll> v(n);
    for(ll i=0;i<n;i++){
      ll k;
      cin>>k;
      v[i]=k;
    }
    ll g=v[0];
    for(ll i=0;i<n;i++) g=__gcd(g,v[i]);
    if(abs128(r)%g){
      cout<<" Stupid keypad!"<<endl;
      continue;
    }
    vector<ll> ans(n,0);
    auto print=
      [&](){
        ll tmp=0;
        for(ll i=0;i<n;i++) tmp+=v[i]*ans[i];
        assert(tmp==r);
        for(ll i=0;i<n;i++) cout<<" "<<ans[i];
        cout<<endl;
      };

    bool f=0;
    for(ll i=0;i<n;i++){
      if(abs128(r)%v[i]==0){
        ans[i]=r/v[i];
        f=1;
        break;
      }
    }

    if(f){
      print();
      continue;
    }

    ll res=v[0];
    ans[0]=1;
    for(ll i=1;i<n;i++){
      ll k=__gcd(res,v[i]);
      if(k==res) continue;
      ll x,y;
      extgcd(res,v[i],x,y);
      for(ll j=0;j<i;j++) ans[j]*=x;
      ans[i]=y;
      res=k;
    }
    for(ll i=0;i<n;i++) ans[i]*=(r/res);
    print();
  }

  return 0;
}

/*
  verified on 2019/10/22
  https://vjudge.net/problem/UVA-12980
*/
#endif

#undef call_from_test

ll sqrt(ll x){
  assert(x>=0);
  if(x<=1) return x;
  ll l=0,r=x;
  while(l+1<r){
    ll m=(l+r)>>1;
    if(m<=x/m&&m*m<=x) l=m;
    else r=m;
  }
  return l;
}

signed main(){
  int n;
  while(cin>>n,n){
    int m=n*(n+1)/2;

    vector<ll> bs(m),es,os;
    for(int i=0;i<m;i++) cin>>bs[i];
    for(ll b:bs)
      ((b&1)?os:es).emplace_back(b);

    sort(es.begin(),es.end());
    sort(os.begin(),os.end());

    ll a=sqrt(es[0]*es[1]/os[0]);
    cout<<a<<endl;
    for(int i=0;i<n;i++){
      if(i) cout<<" ";
      cout<<es[i]/a;
    }
    cout<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 330
memory_kb: 4448
final_rank: 19

code_snippet: #include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>

long long int gcd(const long long int a, const long long int b) {
	return (b == 0) ? a : gcd(b, a % b);
}
int main() {
	while (true) {
		int n; std::cin >> n; if (n == 0) break;
		std::vector<long long int> numbers(n * (n + 1) / 2), even; for (auto& b : numbers) std::cin >> b;
		std::copy_if(numbers.begin(), numbers.end(), std::back_inserter(even), [](const long long int n) {return n % 2 == 0; });
		std::sort(even.begin(), even.end());
		long long int odd_min = LLONG_MAX;
		for (const auto& b : numbers) if (b % 2 == 1) odd_min = std::min(odd_min, b);
		const auto a0g = gcd(even[0], even[1]);
		const auto ab = (even[0] / a0g) * (even[1] / a0g);
		const auto gcd_square = odd_min / ab;
		const auto gcd = static_cast<int>(std::sqrt(gcd_square));
		const auto a0 = a0g / gcd;
		std::cout << a0 << '\n';
		for (auto i = 0; i < even.size(); ++i) {
			if (i != 0) std::cout << ' ';
			std::cout << even[i] / a0;
		}
		std::cout << '\n';
	}
}
accuracy: 1
time_ms: 180
memory_kb: 3356
final_rank: 10

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

using L = __int128;

int main(){
    int n;
    while(scanf(" %d", &n),n){
        vector<vector<ll>> b(n+1, vector<ll>(n+1));
        rep(i,n+1){
            for(int j=i+1; j<n+1; ++j) scanf(" %lld", &b[i][j]);
        }

        L sq_a0 = (L)b[0][1]*b[0][2];
        sq_a0 /= b[1][2];

        ll ng=0, ok=(1LL<<31)-1;
        while(ok-ng>1){
            ll mid = (ng+ok)/2;
            if(sq_a0 <= mid*mid) ok = mid;
            else ng = mid;
        }

        ll a0 = ok;
        printf("%lld\n", a0);

        vector<ll> a;
        for(int i=1; i<=n; ++i) a.pb(b[0][i]/a0);
        sort(all(a));
        rep(i,n) printf("%lld%c", a[i], " \n"[i==n-1]);
    }
    return 0;
}
accuracy: 1
time_ms: 50
memory_kb: 3488
final_rank: 3

code_snippet: #include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
long long gcd(long long a, long long b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int main() {
	int N;
	while (cin >> N, N) {
		int S = N * (N + 1) / 2;
		vector<long long> v(S);
		for (int i = 0; i < S; ++i) cin >> v[i];
		long long G = -1;
		vector<long long> evens;
		long long oddmin = ~(1LL << 63);
		for (int i = 0; i < S; ++i) {
			if (v[i] % 2 == 0) {
				if (G == -1) G = v[i];
				else G = gcd(G, v[i]);
				evens.push_back(v[i]);
			}
			else {
				oddmin = min(oddmin, v[i]);
			}
		}
		sort(evens.begin(), evens.end());
		for (int i = 0; i < N; ++i) evens[i] /= G;
		long long coeff = oddmin / evens[0] / evens[1];
		long long sqcoeff = sqrt(coeff + 0.5);
		cout << G / sqcoeff << endl;
		for (int i = 0; i < N; ++i) {
			if (i) cout << ' ';
			cout << evens[i] * sqcoeff;
		}
		cout << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 170
memory_kb: 3320
final_rank: 9

code_snippet: #include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

#include<unordered_map>



const int mod = 998244353;
struct Mod {
public:
	int num;
	Mod() : Mod(0) { ; }
	Mod(long long int n) : num((n % mod + mod) % mod) {
		static_assert(mod<INT_MAX / 2, "mod is too big, please make num 'long long int' from 'int'");
	}
	Mod(int n) : Mod(static_cast<long long int>(n)) { ; }
	operator int() { return num; }
};

Mod operator+(const Mod a, const Mod b) { return Mod((a.num + b.num) % mod); }
Mod operator+(const long long int a, const Mod b) { return Mod(a) + b; }
Mod operator+(const Mod a, const long long int  b) { return b + a; }
Mod operator++(Mod &a) { return a + Mod(1); }
Mod operator-(const Mod a, const Mod b) { return Mod((mod + a.num - b.num) % mod); }
Mod operator-(const long long int a, const Mod b) { return Mod(a) - b; }
Mod operator--(Mod &a) { return a - Mod(1); }
Mod operator*(const Mod a, const Mod b) { return Mod(((long long)a.num * b.num) % mod); }
Mod operator*(const long long int a, const Mod b) { return Mod(a)*b; }
Mod operator*(const Mod a, const long long int b) { return Mod(b)*a; }
Mod operator*(const Mod a, const int b) { return Mod(b)*a; }
Mod operator+=(Mod &a, const Mod b) { return a = a + b; }
Mod operator+=(long long int &a, const Mod b) { return a = a + b; }
Mod operator-=(Mod &a, const Mod b) { return a = a - b; }
Mod operator-=(long long int &a, const Mod b) { return a = a - b; }
Mod operator*=(Mod &a, const Mod b) { return a = a * b; }
Mod operator*=(long long int &a, const Mod b) { return a = a * b; }
Mod operator*=(Mod& a, const long long int &b) { return a = a * b; }
Mod operator^(const Mod a, const int n) {
	if (n == 0) return Mod(1);
	Mod res = (a * a) ^ (n / 2);
	if (n % 2) res = res * a;
	return res;
}
Mod mod_pow(const Mod a, const long long  int n) {
	if (n == 0) return Mod(1);
	Mod res = mod_pow((a * a), (n / 2));
	if (n % 2) res = res * a;
	return res;
}

Mod inv(const Mod a) { return a ^ (mod - 2); }
Mod operator/(const Mod a, const Mod b) {
	assert(b.num != 0);
	return a * inv(b);
}
Mod operator/(const long long int a, const Mod b) {
	return Mod(a) / b;
}
Mod operator/=(Mod &a, const Mod b) {
	return a = a / b;
}

#define MAX_MOD_N 10240

Mod fact[MAX_MOD_N], factinv[MAX_MOD_N];
void init(const int amax = MAX_MOD_N) {
	fact[0] = Mod(1); factinv[0] = 1;
	for (int i = 0; i < amax - 1; ++i) {
		fact[i + 1] = fact[i] * Mod(i + 1);
		factinv[i + 1] = factinv[i] / Mod(i + 1);
	}
}
Mod comb(const int a, const int b) {
	return fact[a] * factinv[b] * factinv[a - b];
}

vector<vector<int>>flag(1001,vector<int>(1001));

Mod solve(int rest, int now,vector<vector<Mod>>&memo,const vector<int>&nums) {
	if (!flag[rest][now]) {
		flag[rest][now]=true;
		if (now == 1) {
			return memo[rest][now] = 1;
		}
		else {

			Mod ans = 0;
			Mod mo = 1;
			for (int k = 0; k <= rest / now; ++k) {

				ans += solve(rest - k*now + nums[now - 1], now - 1, memo, nums)*mo;
				mo = mo*comb(rest - k*now, now);
				mo = mo / Mod(k + 1);
			}

			return memo[rest][now] = ans;
		}
	}
	else {
		return memo[rest][now];
	}
}
int main() {
	while (true) {

		int N; cin >> N;
		if(!N)break;
		vector<long long int>odds, as;
		for (int i = 0; i < N*(N + 1)/2; ++i) {
			long long int a; cin >> a;
			if (a % 2)odds.push_back(a);
			else as.push_back(a);
		}
		sort(odds.begin(), odds.end());
		sort(as.begin(), as.end());

		long long int ans = round(sqrt(ld(as[as.size() - 1])*as[as.size() - 2] / odds.back()) + eps);

		vector<long long int>ans2;
		for (int i = 0; i < N; ++i) {
			ans2.push_back(as[i] / ans);
		}
		cout << ans << endl;
		for (int i = 0; i < N; ++i) {
			cout << ans2[i];
			if(i==N-1)cout<<endl;
			else cout<<" ";
		}
	}
	
	return 0;

}
accuracy: 1
time_ms: 210
memory_kb: 7484
final_rank: 20

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int n, N;
vector<int> even_b, odd_b;

bool check(double x) {
  vector<double> a(2);
  Rep(i, 2) a[i] = (double)even_b[i] / x;
  if ( a[0]*a[1] > (double)odd_b[0] ) return false;  
  else return true;
}

signed main() {  
  while ( cin >> n, n ) {
    N = n * (n+1) / 2;
    even_b.clear();
    odd_b.clear();
    
    Rep(i, N) {
      int b;
      cin >> b;
      if ( b % 2 ) odd_b.pb(b);
      else even_b.pb(b);
    }

    sort(All(even_b));
    sort(All(odd_b));
    
    double l = 1.0, r = (1 << 31)-1;
    int cnt = 100;
    while ( cnt-- ) {
      double mid = (r + l) / 2.0;      
      if ( check(mid) ) r = mid;
      else l = mid;
    }
    
    int ans = (double)r;
        
    cout << ans << endl;
    Rep(i, n) {
      if ( i ) cout << " ";
      cout << even_b[i] / ans;
    }
    cout << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 200
memory_kb: 3148
final_rank: 11

code_snippet: #include<bits/stdc++.h>
using namespace std;

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i, n) for ( int i = 0 ; i < (n); i++ )
#define All(v) v.begin(), v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int n, N;
vector<int> even_b, odd_b;

bool check(double x) {
  vector<double> a(2);
  Rep(i, 2) a[i] = (double)even_b[i] / x;
  if ( a[0]*a[1] > (double)odd_b[0] ) return false;  
  else return true;
}

bool check_last(int x) {
  vector<int> a(2);
  Rep(i, 2) {
    if ( even_b[i] % x ) return false;
    a[i] = even_b[i] / x;
  }
  if ( a[0]*a[1] == odd_b[0] ) return true;  
  else return false;
}

signed main() {  
  while ( cin >> n, n ) {
    N = n * (n+1) / 2;
    even_b.clear();
    odd_b.clear();
    
    Rep(i, N) {
      int b;
      cin >> b;
      if ( b % 2 ) odd_b.pb(b);
      else even_b.pb(b);
    }

    sort(All(even_b));
    sort(All(odd_b));
    
    double l = 1.0, r = (1 << 31)-1;
    int cnt = 100;
    while ( cnt-- ) {
      double mid = (r + l) / 2.0;      
      if ( check(mid) ) r = mid;
      else l = mid;
    }

    //cout << r << endl;
    int ans = (double)r-1;
    while ( 1 ) {
      if ( ans % 2 ) ans++;
      if ( check_last(ans) ) break;
    }
        
    cout << ans << endl;
    Rep(i, n) {
      if ( i ) cout << " ";
      cout << even_b[i] / ans;
    }
    cout << endl;
  }

  return 0;
}
accuracy: 1
time_ms: 370
memory_kb: 3228
final_rank: 18

code_snippet: #include<bits/stdc++.h>
using namespace std;
using Int = long long;
using Int2 = __int128_t;
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  Int n;
  while(cin>>n,n){
    vector<Int> b(n*(n+1)/2),e,o;
    for(Int i=0;i<(Int)b.size();i++) cin>>b[i];
    for(Int i=0;i<(Int)b.size();i++)
      if(b[i]%2==0) e.push_back(b[i]);
      else o.push_back(b[i]);
    sort(e.begin(),e.end());
    sort(o.begin(),o.end());
    Int a=sqrt((Int)((Int2)e[0]*e[1]/o[0]));
    cout<<a<<endl;
    for(Int i=0;i<n;i++){
      if(i) cout<<" ";
      cout<<e[i]/a;
    }
    cout<<endl;
  }
  return 0;
}
accuracy: 1
time_ms: 70
memory_kb: 3580
final_rank: 4