Problem:
みんなでジョギング
赤ベコ小学校では、生徒全員が参加する、ちょっと変わったジョギングをします。生徒は、それぞれ独自の周回コースを、自分のペースで走ります。それぞれ自分のコースを 1 周すると小学校に戻ってきます。全員が小学校を同時にスタートしてから、全員が同時に小学校で最初に出会うのは、それぞれ何周したときでしょうか?
生徒の人数
n
、各生徒のコースの 1 周の距離
d
(km)  、各生徒の走る速さ
v
(km/時間)を入力とし、全員が小学校を同時にスタートしてから次に同時に小学校に位置するのは、各生徒がそれぞれ何周したときかを出力するプログラムを作成してください。なお、各生徒は 2
31
-1 周を超えて走ることはありません。
Input
複数のデータセットの並びが入力として与えられます。入力の終わりはゼロひとつの行で示されます。
各データセットは以下の形式で与えられます。
n
d
1
v
1
d
2
v
2
:
d
n
v
n
1 行目に生徒の人数
n
(2 ≤
n
≤ 10) が与えられます。続く
n
行に
i
人目の生徒のコースの１周の距離
d
i
(1 ≤
d
i
≤ 10000) と走る速さ
v
i
(1 ≤
v
i
≤ 10000) が与えられます。
データセットの数は 2000 を超えません。
Output
入力データセットごとに、各生徒の周回数を出力します。各生徒の周回数は入力の順番に従ってそれぞれ１行に出力してください。
Sample Input
2
4 3
5 4
5
789 289
166 46
9 4
617 252
972 303
2
8 5
32 20
0
Output for the Sample Input
15
16
1598397732
1209243492
1939462992
1782294192
1360317793
1
1

Submitted solutions:

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

struct bigint {
    using ll = long long;
    constexpr static long long base = 1000000000;
    constexpr static long long base_digits = 9;
    vector<ll> a;
    ll sign;
    bigint():sign(1){}
    bigint(ll v){*this=v;}
    bigint(const string &s){read(s);}
    void operator=(ll v){
        sign=1;
        if(v<0) sign=-1,v=-v;
        for(;v>0;v=v/base) a.push_back(v%base);
    }
    bigint operator+(const bigint &v) const{
        if(sign==v.sign){
            bigint res=v;
            for(ll i=0,carry=0;i<(ll)max(a.size(),v.a.size())||carry;++i){
                if(i==(ll)res.a.size()) res.a.push_back(0);
                res.a[i]+=carry+(i<(ll)a.size()?a[i]:0);
                carry=res.a[i]>=base;
                if(carry) res.a[i]-=base;
            }
            return res;
        }
        return *this -(-v);
    }
    bigint operator-(const bigint &v) const{
        if(sign==v.sign){
            if(abs()>=v.abs()){
                bigint res=*this;
                for(ll i=0,carry=0;i<(ll)v.a.size()||carry;++i){
                res.a[i]-=carry+(i<(ll)v.a.size()?v.a[i]:0);
                carry=res.a[i]<0;
                if(carry) res.a[i]+=base;
                }
                res.trim();
                return res;
            }
            return -(v-*this);
        }
        return *this+(-v);
    }
    void operator*=(ll v){
        if(v<0) sign=-sign,v=-v;
        for(ll i=0,carry=0;i<(ll)a.size()|| carry;++i){
            if(i ==(ll)a.size()) a.push_back(0);
            ll cur=a[i] *(ll)v+carry;
            carry=(ll)(cur/base);
            a[i]=(ll)(cur%base);
        }
        trim();
    }
    bigint operator*(ll v) const{
        bigint res=*this;
        res *=v;
        return res;
    }
    friend pair<bigint,bigint> divmod(const bigint &a1,const bigint &b1){
        ll norm=base/(b1.a.back()+1);
        bigint a=a1.abs()*norm;
        bigint b=b1.abs()*norm;
        bigint q,r;
        q.a.resize(a.a.size());
        for(ll i=ll(a.a.size())-1;i>=0;i--){
            r *=base;
            r+=a.a[i];
            ll s1=r.a.size()<=b.a.size() ? 0 : r.a[b.a.size()];
            ll s2=r.a.size()<=b.a.size()-1 ? 0 : r.a[b.a.size()-1];
            ll d=((ll)base*s1+s2)/b.a.back();
            r-=b*d;
            while(!r.isZero()&&r<0) r+=b,--d;
            q.a[i]=d;
        }
        q.sign=a1.sign*b1.sign;
        r.sign=a1.sign;
        q.trim();
        r.trim();
        return make_pair(q,r/norm);
    }
    bigint operator/(const bigint &v) const{return divmod(*this,v).first;}
    bigint operator%(const bigint &v) const{return divmod(*this,v).second;}
    void operator/=(ll v){
        if(v<0) sign=-sign,v=-v;
        for(ll i=(ll)a.size()-1,rem=0;i>=0;--i){
        ll cur=a[i]+rem *(ll)base;
        a[i]=(ll)(cur/v);
        rem=(ll)(cur%v);
        }
        trim();
    }
    bigint operator/(ll v) const{bigint res=*this;res/=v;return res;}
    ll operator%(ll v) const{
        if(v<0) v=-v;
        ll m=0;
        for(ll i=ll(a.size())-1;i>=0;--i) m=(a[i]+m *(ll)base)%v;
        return m*sign;
    }
    void operator+=(const bigint &v){*this=*this+v;}
    void operator-=(const bigint &v){*this=*this-v;}
    void operator*=(const bigint &v){*this=*this*v;}
    void operator/=(const bigint &v){*this=*this/v;}
    bool operator<(const bigint &v) const{
        if(sign!=v.sign) return sign<v.sign;
        if(a.size()!=v.a.size()) return a.size()*sign<v.a.size()*v.sign;
        for(ll i=ll(a.size())-1;i>=0;i--){
            if(a[i]!=v.a[i]) return a[i]*sign<v.a[i]*sign;
        }
        return false;
    }
    bool operator>(const bigint &v) const{return v<*this;}
    bool operator<=(const bigint &v) const{return !(v<*this);}
    bool operator>=(const bigint &v) const{return !(*this<v);}
    bool operator==(const bigint &v) const{return !(*this<v)&&!(v<*this);}
    bool operator!=(const bigint &v) const{return *this<v|| v<*this;}
    void trim(){
        while(!a.empty()&&!a.back()) a.pop_back();
        if(a.empty()) sign=1;
    }
    bool isZero() const{return a.empty()||(a.size()==1&&!a[0]);}
    bigint operator-() const{bigint res=*this;res.sign=-sign;return res;}
    bigint abs() const{bigint res=*this;res.sign*=res.sign;return res;}
    ll longValue() const{ll res=0;for(ll i=ll(a.size())-1;i>=0;i--) res=res*base+a[i];return res*sign;}
    friend bigint gcd(const bigint &a,const bigint &b){return b.isZero() ? a : gcd(b,a%b);}
    friend bigint lcm(const bigint &a,const bigint &b){return a/gcd(a,b)*b;}
    void read(const string &s){
        sign=1;
        a.clear();
        ll pos=0;
        while(pos<(ll)s.size()&&(s[pos]=='-'|| s[pos]=='+')){
            if(s[pos]=='-') sign=-sign;
            ++pos;
        }
        for(ll i=s.size()-1;i>=pos;i-=base_digits){
            ll x=0;
            for(ll j=max(pos,i-base_digits+1);j<=i;j++) x=x*10+s[j]-'0';
            a.push_back(x);
        }
        trim();
    }
    friend istream &operator>>(istream &stream,bigint &v){
        string s;
        stream>>s;
        v.read(s);
        return stream;
    }
    friend ostream &operator<<(ostream &stream,const bigint &v){
        if(v.sign==-1) stream<<'-';
        stream<<(v.a.empty()?0:v.a.back());
        for(ll i=(ll)v.a.size()-2;i>=0;--i)
        stream<<setw(base_digits)<<setfill('0')<<v.a[i];
        return stream;
    }
    static vector<ll> convert_base(const vector<ll> &a,ll old_digits,ll new_digits){
        vector<ll> p(max(old_digits,new_digits)+1);
        p[0]=1;
        for(ll i=1;i<(ll)p.size();i++) p[i]=p[i-1]*10;
        vector<ll> res;
        ll cur=0;
        ll cur_digits=0;
        for(ll i=0;i<(ll)a.size();i++){
        cur+=a[i]*p[cur_digits];
        cur_digits+=old_digits;
        while(cur_digits>=new_digits){
            res.push_back(signed(cur%p[new_digits]));
            cur/=p[new_digits];
            cur_digits-=new_digits;
        }
        }
        res.push_back((signed)cur);
        while(!res.empty()&&!res.back()) res.pop_back();
        return res;
    }
    static vector<ll> karatsubaMultiply(const vector<ll> &a,const vector<ll> &b){
        ll n=a.size();
        vector<ll> res(n+n);
        if(n<=32){
        for(ll i=0;i<n;i++)
            for(ll j=0;j<n;j++)
            res[i+j]+=a[i]*b[j];
        return res;
        }
        ll k=n>>1;
        vector<ll> a1(a.begin(),a.begin()+k);
        vector<ll> a2(a.begin()+k,a.end());
        vector<ll> b1(b.begin(),b.begin()+k);
        vector<ll> b2(b.begin()+k,b.end());
        vector<ll> a1b1=karatsubaMultiply(a1,b1);
        vector<ll> a2b2=karatsubaMultiply(a2,b2);
        for(ll i=0;i<k;i++) a2[i]+=a1[i];
        for(ll i=0;i<k;i++) b2[i]+=b1[i];
        vector<ll> r=karatsubaMultiply(a2,b2);
        for(ll i=0;i<(ll)a1b1.size();i++) r[i]-=a1b1[i];
        for(ll i=0;i<(ll)a2b2.size();i++) r[i]-=a2b2[i];
        for(ll i=0;i<(ll)r.size();i++) res[i+k]+=r[i];
        for(ll i=0;i<(ll)a1b1.size();i++) res[i]+=a1b1[i];
        for(ll i=0;i<(ll)a2b2.size();i++) res[i+n]+=a2b2[i];
        return res;
    }
    bigint operator*(const bigint &v) const{
        constexpr static ll nbase = 10000;
        constexpr static ll nbase_digits = 4;
        vector<ll> a=convert_base(this->a,base_digits,nbase_digits);
        vector<ll> b=convert_base(v.a,base_digits,nbase_digits);
        while(a.size()<b.size()) a.push_back(0);
        while(b.size()<a.size()) b.push_back(0);
        while(a.size() &(ll(a.size())-1)) a.push_back(0),b.push_back(0);
        vector<ll> c=karatsubaMultiply(a,b);
        bigint res;
        res.sign=sign*v.sign;
        for(ll i=0,carry=0;i<(ll)c.size();i++){
            ll cur=c[i]+carry;
            res.a.push_back((ll)(cur%nbase));
            carry=(ll)(cur/nbase);
            if(i+1==(int)c.size()&&carry>0) c.push_back(0);
        }
        res.a=convert_base(res.a,nbase_digits,base_digits);
        res.trim();
        return res;
    }
};

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    using ll = bigint;
    while(cin >> n, n){
        ll v1 = 1, v2 = 1;
        vector<ll> d(n), v(n);
        for(int i = 0; i < n; i++){
            cin >> d[i] >> v[i];
            v2 = v2 / __gcd(v[i], v2) * v[i];
        }
        for(int i = 0; i < n; i++){
            d[i] *= v2 / v[i];
            v1 = v1 / __gcd(d[i], v1) * d[i];
        }
        for(int i = 0; i < n; i++){
            cout << v1 / d[i] << '\n';
        }
    }
}
accuracy: 1
time_ms: 30
memory_kb: 3420
final_rank: 20

code_snippet: /*
 * src.cpp
 *
 *  Created on: 2016/07/26
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

const int MAX_N=10;

int n;
int d[MAX_N],v[MAX_N];

typedef long long ll;

ll g[MAX_N];

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

ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}

int main(){
	do{
		cin>>n;
		if (n){
			REP(i,n){
				cin>>d[i]>>v[i];
			}
			REP(i,n-1){
				ll a,b;
				a=d[0]*v[i+1];
				b=d[i+1]*v[0];
				g[i]=b/gcd(a,b);
			}
			for (int i=n-3;i>=0;i--){
				g[i]=lcm(g[i],g[i+1]);
			}
			cout<<g[0]<<endl;
			FOR(i,1,n){
				cout<<d[0]*v[i]*g[0]/v[0]/d[i]<<endl;
			}
		}
	}while(n);
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 1

code_snippet: #include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
ll gcd(ll a,ll b){
	return (b==0?a:gcd(b,a%b));
}
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}
int main(){
	int n;
	while(cin>>n,n){
		vi a(n),b(n);
		rep(i,n)cin>>a[i]>>b[i];
		rep(i,n){
			ll t=gcd(a[i],b[i]);
			a[i]/=t;b[i]/=t;
		}
		ll g=b[0],l=a[0];
		loop(i,1,n){
			g=gcd(g,b[i]);
			l=lcm(l,a[i]);
		}
		rep(i,n)cout<<l/a[i]*(b[i]/g)<<endl;;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1196
final_rank: 11

code_snippet: #include <iostream>
#include <cmath>
#include <queue>
#include <vector>
#include <functional>

using namespace std;

long long int gcd(long long int a, long long int b) {
	if (b == 0) {
		return a;
	} else {
		return gcd(max(b, a%b), min(b, a%b));
	}
}

long long int lcm(long long int a, long long int b) {
	return a * b / gcd(a, b);
}

typedef pair<long long int, long long int> P;

int main() {
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		long long int t = 1;
		vector<long long int> d(n);
		vector<long long int> v(n);
		for (int i = 0; i < n; i++) {
			cin >> d[i] >> v[i];
			t = lcm(max(v[i]*t, d[i]), min(v[i]*t, d[i])) / v[i];
			//cout << t << endl;
		}
		long long int a = v[0]*t/d[0];
		for (int i = 0; i < n; i++) {
			a = gcd(a, v[i]*t/d[i]);
		}
		for (int i = 0; i < n; i++) {
			cout <<(v[i]*t/d[i])/a << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1196
final_rank: 11

code_snippet: #include<iostream>
using namespace std;
long long n,a[100],b[100],c[100];
long long gcd1;
long long gcd(long long a,long long b){
	if(b==0){return a;}
	return gcd(b,a%b);
}
int main(){
	while(true){
		cin>>n;
		if(n==0){break;}
		gcd1=1;
		for(int i=0;i<n;i++){
			cin>>a[i]>>b[i];
			long long GCD2=gcd(a[i],b[i]);
			a[i]/=GCD2;b[i]/=GCD2;
			long long GCD=gcd(gcd1,a[i]);
			gcd1=gcd1*a[i]/GCD;
		}
		for(int i=0;i<n;i++){
			c[i]=gcd1*b[i]/a[i];
		}
		long long gcd2=c[0];
		for(int i=1;i<n;i++){
			gcd2=gcd(gcd2,c[i]);
		}
		for(int i=0;i<n;i++){
			cout<<c[i]/gcd2<<endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 1

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>

using namespace std;

unsigned long long int GCD(unsigned long long int a, unsigned long long int b)
{
	if (b == 0)
	{
		return(a);
	}
	if (a < b)
	{
		return(GCD(b, a));
	}
	return(GCD(b, a % b));
}

unsigned long long int LCM(unsigned long long int a, unsigned long long int b)
{
	unsigned long long int gcd = GCD(a, b);
	return(a * b / gcd);
}

void solve()
{
	int n;
	while (cin >> n, n)
	{
		vector<unsigned long long int> d(n);
		vector<unsigned long long int> v(n);
		for (int i = 0; i < n; ++i)
		{
			cin >> d[i] >> v[i];
			unsigned long long int t = GCD(d[i], v[i]);
			d[i] /= t;
			v[i] /= t;
		}
		unsigned long long int dk = d[0];
		unsigned long long int vk = v[0];
		for (int i = 1; i < n; ++i)
		{
			dk = dk * d[i] / GCD(d[i], dk);
			vk = GCD(vk, v[i]);
		}
		for (int i = 0; i < n; ++i)
		{
			cout << (v[i] / vk) * (dk / d[i]) << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}
accuracy: 1
time_ms: 10
memory_kb: 1192
final_rank: 10

code_snippet: #include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
ll gcd(ll a,ll b){
      if(b==0)return a;
      return gcd(b,a%b);
}
ll lcm(ll a,ll b){
      return a/gcd(a,b)*b;
}
int main(){
      ll n,d[10],v[10];
      while(cin>>n&&n){
            REP(i,n){
                  cin>>d[i]>>v[i];
                  ll a=gcd(d[i],v[i]);
                  v[i]/=a;d[i]/=a;
            }
            ll c=1;
            REP(i,n)c=lcm(c,d[i]);
            REP(i,n)v[i]*=(c/d[i]);
            ll ans=v[0];
            REP(i,n)ans=gcd(ans,v[i]);
            REP(i,n)cout<<v[i]/ans<<endl;
      }
}
accuracy: 1
time_ms: 10
memory_kb: 1156
final_rank: 1

code_snippet: #include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <iterator>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <fstream>
#include <iomanip>
#include <cassert>
//#include <utility>
//#include <memory>
//#include <functional>
//#include <deque>
//#include <cctype>
//#include <ctime>
//#include <numeric>
//#include <list>
//#include <iomanip>

//#if __cplusplus >= 201103L
//#include <array>
//#include <tuple>
//#include <initializer_list>
//#include <forward_list>
//
//#define cauto const auto&
//#else

//#endif

using namespace std;


typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
    stringstream ss;
    ss << f;
    ss >> t;
}

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) reep((i),0,(n))
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define F first
#define S second
#define mkp make_pair
#define RALL(v) (v).rbegin(),(v).rend()
#define DEBUG
#ifdef DEBUG
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#else
#define dump(x) 
#define debug(x) 
#endif
#define LDcout(x,n) fixed<<setprecision(n)<<x

#define MOD 1000000007LL
#define EPS 1e-8
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)

ll lcm(ll a,ll b){
	return a/__gcd(a,b)*b;
}

void mainmain(){
	int n;
	while(cin>>n,n){
		vector<pll> v(n);
		rep(i,n) cin>>v[i].F>>v[i].S;
		ll t=1;
		rep(i,n){
			t=lcm(t,v[i].F);
		}
		vll w(n);
		rep(i,n){
			w[i]=t/v[i].F*v[i].S;
		}
		t=w[0];
		rep(i,n){
			t=__gcd(t,w[i]);
		}
		rep(i,n){
			cout<<w[i]/t<<endl;
		}
	}
}


signed main() {
	ios_base::sync_with_stdio(false);
    cin.tie(0);
  	cout<<fixed<<setprecision(20);
    mainmain();
}
accuracy: 1
time_ms: 10
memory_kb: 1204
final_rank: 14

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

typedef long long lint;

lint gcd(lint a, lint b) { return b != 0 ? gcd(b, a % b) : a; }

lint lcm(lint a, lint b) { return a / gcd(a, b) * b; }

int main() {
	int n;
	
	while (cin >> n, n) {
		vector< lint > d(n), v(n);
		
		cin >> d[0] >> v[0];
		
		lint dd = d[0], vv = v[0];
		
		for_(i,1,n) {
			cin >> d[i] >> v[i];
			lint _lcm_ = lcm(d[i] * vv, v[i] * dd);
			dd = _lcm_ / v[i];
		}
		
		for_(i,0,n) cout << dd * v[i] / (vv * d[i]) << endl;
	}
}
accuracy: 1
time_ms: 10
memory_kb: 1196
final_rank: 11

code_snippet: #include <iostream>
#include <utility>

using namespace std;

typedef unsigned long long BigInt;

BigInt gcd(BigInt a, BigInt b) {
  if (a < b) {
    swap(a, b);
  }
  while (b > 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}

BigInt lcm(BigInt a, BigInt b) {
  return a * b / gcd(a, b);
}

int main() {
  int n;
  BigInt dh, vh;
  BigInt d[10], v[10];
  while (true) {
    cin >> n;
    if (n == 0) {
      return 0;
    }
    for (int i = 0; i < n; ++i) {
      cin >> d[i] >> v[i];
    }
    dh = d[0];
    vh = v[0];
    for (int i = 1; i < n; ++i) {
      BigInt y = lcm(v[i] * dh, vh * d[i]);
      BigInt kh = y / (v[i] * dh);
      BigInt z = gcd(dh * kh, vh);
      dh = dh * kh / z;
      vh /= z;
    }
    for (int i = 0; i < n; ++i) {
      cout << dh * v[i] / (d[i] * vh) << endl;
    }
  }
}
accuracy: 1
time_ms: 10
memory_kb: 1160
final_rank: 4

code_snippet: #include <iostream>

typedef unsigned long long ll;

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

ll lcm(ll a, ll b){
	ll c = gcd(a, b);
	return c * (a / c) * (b / c);
}

int main(){
	int n;
	while (std::cin >> n, n){
		ll d[11], v[11];
		for (int i = 0; i < n; ++i){
			std::cin >> d[i] >> v[i];
			ll g = gcd(d[i], v[i]);
			d[i] /= g, v[i] /= g;
		}
		ll s = lcm(d[0], d[1]);
		for (int i = 2; i < n; ++i)s = lcm(s, d[i]);
		for (int i = 0; i < n; ++i)v[i] *= (s / d[i]);
		ll t = gcd(v[0], v[1]);
		for (int i = 2; i < n; ++i)t = gcd(t, v[i]);
		for (int i = 0; i < n; ++i)std::cout << v[i] / t << std::endl;
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1160
final_rank: 4

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

long long int gcd(long long int a, long long int b);
long long int lcm(long long int a, long long int b);

int main(){
  int n;
  while(cin >> n , n){
    long long int d[11],v[11];
    for(int i=0;i<n;i++){
      cin >> d[i] >> v[i];
      long long int G = gcd(d[i],v[i]);
      d[i] /= G;
      v[i] /= G;
    }
    long long int L = lcm(d[0],d[1]);
    for(int i=2;i<n;i++){
      L = lcm(L,d[i]);
    }
    long long int ans[11];
    for(int i=0;i<n;i++){
      ans[i] = v[i]*(L/d[i]);
    }
    long long int G = gcd(ans[0],ans[1]);
    for(int i=2;i<n;i++){
      G = gcd(G,ans[i]);
    }
    for(int i=0;i<n;i++){
      cout << ans[i] / G << endl;
    }
  }
}

long long int gcd(long long int a, long long int b){
  if(b == 0) return a;
  else return gcd(b,a%b);
}

long long int  lcm(long long int a, long long int b){
  if(b > a) swap(a,b);
  return a * b / gcd(a,b);
}
accuracy: 1
time_ms: 10
memory_kb: 1164
final_rank: 6

code_snippet: #include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
#include <string.h>
#include <complex>
using namespace std;
const int INF = 1<<29;
const double EPS = 1e-8;

int d[10],v[10];
int x[9],y[9];

int gcd(int x, int y){
    return y ? gcd(y, x%y): x;
}

int lca(int x, int y){
    long long int mul = (long long int)x*y;
    return mul/gcd(x,y);
}

int main(){
    while(1){
        int n;
        scanf("%d",&n);
        if(!n)break;

        for(int i=0;i<n;i++){
            scanf("%d%d",&d[i],&v[i]);
        }

        for(int i=0;i<n-1;i++){
            x[i] = d[i+1]*v[0];
            y[i] = d[0]*v[i+1];
            int g = gcd(x[i],y[i]);
            x[i] /= g;
            y[i] /= g;
            //cout << x[i] << " " << y[i] << endl;
        }

        if(n>2){
            int l = 1;
            for(int i=0;i<n-1;i++){
                l = lca(l, x[i]);
            }
            cout << l << endl;
            for(int i=0;i<n-1;i++){
                cout << l / x[i] * y[i] << endl;
            }
        }else{
            cout << x[0] << endl;
            cout << y[0] << endl;
        }

    }

    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1208
final_rank: 16

code_snippet: #include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define all(C) (C).begin(),(C).end()
const int MAX=10;
int n;
int d[MAX],v[MAX];

int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}

void solve(){
    rep(i,n){
        cin>>d[i]>>v[i];
        int g=gcd(d[i],v[i]);
        d[i]/=g;v[i]/=g;
    }
    int base=d[0];
    rep(i,n)base=lcm(base,d[i]);
    rep(i,n)v[i]*=(base/d[i]);
    base=v[0];
    rep(i,n)base=gcd(base,v[i]);
    rep(i,n)cout<<v[i]/base<<endl;
}
signed main(){
    cin.tie(0);ios_base::sync_with_stdio(0);
    while(cin>>n&&n)solve();
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1188
final_rank: 9

code_snippet: #include <iostream>
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
using namespace std;
#define ll long long
ll gcd(ll a, ll b) {
	if(b==0) return -1;
	if(a<b) swap(a,b);
	while(b) {
		ll t = a / b;
		swap(a-=t*b,b);
	}
	return a;
}
ll lcm(ll a, ll b) {
	ll c = gcd(a,b);
	return a * b / c;
}
int main(){
	int n;
	while(cin >> n, n) {
		ll d[10], v[10];
		rep(i,n) {
			cin >> d[i] >> v[i];
		}
		ll tr = d[0], td = v[0];
		rep2(i,1,n) {
			tr = lcm(tr * v[i], td * d[i]);
			td *= v[i];
			ll div = gcd(tr,td);
			tr /= div, td /= div;
		}
		rep(i,n) {
			cout << (tr*v[i]) /(d[i]*td) << endl;
		}
	}
}
accuracy: 1
time_ms: 20
memory_kb: 1164
final_rank: 17

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;
typedef long long ll;

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

ll lcm(ll a,ll b)
{
	if(a == 0 || b == 0) return 0;
	return ((a / gcd(a,b)*b));
}

int main()
{
	int n;
	while(cin >> n && n)
	{
		vector<pair<ll,ll> > v;
		
		rep(i,n)
		{
			ll a,b;
			cin >> a >> b;
			v.push_back(make_pair(a,b));
		}

		rep(i,n)
		{
			ll temp = gcd(v[i].first,v[i].second);
			v[i].first /= temp;
			v[i].second /= temp;
		}

		ll t,t2;
		rep(i,n)
		{
			if(i == 0)
			{
				t = v[i].first;
				t2 = v[i].second;
			}
			else
			{
				t = lcm(t,v[i].first);
				t2 = gcd(t2,v[i].second);
			}
		}

		rep(i,n)
		{
			ll ans = t * v[i].second;
			ans /= t2;
			ans /= v[i].first;
			cout << ans << endl;
		}
	}
	return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1204
final_rank: 14

code_snippet: #include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

long long gozyo(long long a,long long b){
  if(a<b){
    long long temp=a;
    a=b;
    b=temp;
  }
  while(a%b!=0){
    long long  temp=a%b;
    a=b;
    b=temp;
  }
  return b;
}

main(){
  int n;
  long long d[11];
  long long v[11];
  long long a[11];
  long long g;
  long long k1,k2,k3;
  long long t1,t2,t3;
  while( (cin >> n),n ){
    for(int i=0;i<n;i++){
      cin >> d[i] >> v[i];
      g= gozyo(d[i],v[i]);
      d[i]/=g;
      v[i]/=g;
    }



    k1=d[0];
    t1=d[0];
    for(int i=1;i<n;i++){
      k1 = gozyo(t1,d[i]);
      t1=t1*d[i]/k1;
    }

    for(int i=0;i<n;i++) a[i]=t1/d[i]*v[i];

    k2=a[0];
    for(int i=1;i<n;i++) k2 = gozyo(k2,a[i]);

    for(int i=0;i<n;i++){
      cout << a[i]/k2 << endl;
    }
    

  }
}
accuracy: 1
time_ms: 10
memory_kb: 1164
final_rank: 6

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

using namespace std;

typedef long long lint;

lint gcd(lint x, lint y){ return __gcd(x, y); }
lint lcm(lint x, lint y){ return x / gcd(x, y) * y; }

int main()
{
	int n;
	while (cin >> n, n){
		vector<pair<lint, lint> > ss;
		lint l = 1;
		for (int i = 0; i < n; i++){
			lint d, v;
			cin >> d >> v;
			lint g = gcd(d, v);
			l = lcm(l, d / g);
			ss.push_back(make_pair(d, v));
		}
		lint g = l * ss[0].second / ss[0].first;
		for (int i = 1; i < n; i++){
			g = gcd(l * ss[i].second / ss[i].first, g);
		}
		for (int i = 0; i < n; i++){
			cout << l * ss[i].second / ss[i].first / g << endl;
		}
	}
	return (0);
}
accuracy: 1
time_ms: 30
memory_kb: 1204
final_rank: 18

code_snippet: #include <iostream>
#include <vector>
using namespace std;
typedef long long int llf;
vector<int> p;
llf gcd(llf a,llf b){
	while(a!=b){
		if(max(a,b)%min(a,b)==0)
		return min(a,b);
		if(a>b)
		a-=b*(a/b);
		else
		b-=a*(b/a);
	}
	return a;
}
llf gcd(llf c[10],int n){
	llf d[10];
	for(int i=0;i<n;i++)
	d[i]=c[i];
	llf x=d[0];
	for(int i=1;i<n;i++)
	x=gcd(x,d[i]);
	return x;
}
llf lcm(llf c[10],int n){
	int d[10];
	for(int i=0;i<10;i++)
	d[i]=c[i];
	int times[10000]={};
	for(int i=0;i<n;i++){
		for(int j=0;j<p.size();j++){
			int k=0;
			while(d[i]%p[j]==0){
				d[i]/=p[j];
				k++;
			}
			times[p[j]]=max(times[p[j]],k);
		}
	}
	llf ans=1;
	for(int i=0;i<p.size();i++)
		for(int j=0;j<times[p[i]];j++)
			ans*=p[i];
	return ans;
}
int main() {
	// your code goes here
	p.push_back(2);
	for(int i=3;i<=10000;i++){
		for(int j=0;j<p.size();j++){
			if(i%p[j]==0)
			break;
			if(j==p.size()-1)
			p.push_back(i);
		}
	}
	int n;
	while(cin >> n && n!=0){
		llf d[10],v[10];
		for(int i=0;i<n;i++)
		cin >> d[i] >> v[i];
		llf times=lcm(d,n);
		for(int i=0;i<n;i++)
		v[i]*=(times/d[i]);
		llf c=gcd(v,n);
		for(int i=0;i<n;i++)
		cout << v[i]/c << endl;
	}
	return 0;
}
accuracy: 1
time_ms: 40
memory_kb: 1280
final_rank: 19

code_snippet: #include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

struct data{
  ll d,v;
  void c(){
    ll x = __gcd(d,v);
    d/=x;
    v/=x;
  }
};

int n;
data t[10];
ll u[10],size;

ll lcm(ll a,ll b){
  return a/ __gcd(a,b) * b;
}

ll gcd(ll a,ll b){
  return __gcd(a,b);
}

void change(){
  ll x = t[0].d;
  for(int j=1;j<n;j++)x=gcd(x,t[j].d);
  for(int j=0;j<n;j++)t[j].d/=x;
}
void de();

int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>t[i].d>>t[i].v;
      t[i].c();
    }
    change();
    for(int i=1;i<n;i++){
      for(int j=0;j<n;j++)t[j].d*=t[(j+i)%n].v;
      change();
    }//i

    
    for(int i=0;i<n;i++){
      //cout<<t[i].d<<endl;
      
      size=0;

      for(int j=1;j<n;j++){
	ll y = t[(j+i)%n].d;
	y = y / gcd(y,t[i].d);
	for(int k=0;k<size;k++)y=y/gcd(y,u[k]);
	if(y>1)u[size++]=y;
      }


      ll ans=1;
      for(int j=0;j<size;j++)ans*=u[j];
      cout<<ans<<endl;
    }
    
  }
  return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 1164
final_rank: 6