Go: package main

import (
	"bufio"
	"os"
	"strconv"
	"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		d, v := make([]int, 0), make([]int, 0)
		for i := 0; i < n; i++ {
			scanner.Scan()
			buf := strings.Split(scanner.Text(), " ")
			a, _ := strconv.Atoi(buf[0])
			b, _ := strconv.Atoi(buf[1])
			g := _gcd(a, b)
			a /= g
			b /= g
			d = append(d, a)
			v = append(v, b)
		}
		g := lcm(n, d)
		for i := 0; i < n; i++ {
			d[i] = (g/d[i])*v[i]
		}
		g = gcd(n, d)
		for i := 0; i < n; i++ {
			fmt.Println(d[i]/g)
		}
	}
}

func _gcd(a, b int) int {
	for b != 0 {
		r := a % b
		a, b = b, r
	}
	return a
}

func gcd(n int, a []int) int {
	if n == 1 {
		return a[0]
	}
	g := _gcd(a[0], a[1])
	for i := 2; i < n; i++ {
		if g == 1 {
			break
		}
		g = _gcd(g, a[i])
	}
	return g
}

func lcm(n int, a []int) int {
	if n == 1 {
		return a[0]
	}
	g := _gcd(a[0], a[1])
	c := a[0] / g * a[1]
	for i := 2; i < n; i++ {
		g = _gcd(c, a[i])
		c = c / g * a[i]
	}
	return c
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

using namespace std;

typedef pair<int,int> pii;

int main(){

  int n;
  while(true){
    scanf("%d", &n);

    if(n == 0) break;

    vector<int> d(n), v(n);
    REP(i,n){
      scanf("%d %d", &d[i], &v[i]);
      FOR(j,2,10001){
        while(d[i] % j == 0 && v[i] % j == 0){
          d[i] /= j; v[i] /= j;
        }
      }
    }

    map<llong, int> mp;
    REP(i,n){
      map<llong, int> a, b;
      int tmp = v[i];
      for(int j = 2; j <= v[i]; ++j){
        while(tmp % j == 0){
          a[j]++;
          tmp /= j;
        }
      }
      tmp = d[i];
      for(int j = 2; j <= d[i]; ++j){
        while(tmp % j == 0){
          b[j]++;
          tmp /= j;
        }
      }

      REPI(itr,b){
        itr->second = max(0, itr->second - a[itr->first]);
        if(mp.find(itr->first) != mp.end()){
          mp[itr->first] = itr->second;
        }else{
          mp[itr->first] = max(mp[itr->first], itr->second);
        }
      }
    }
    bool f = true;
    FOR(i,1,n){
      if(d[i] != d[0] || v[i] != v[0]){
        f = false;
        break;
      }  
    }
    if(f){
      REP(i,n){
        printf("1\n");
      }
      continue;
    }

    llong D = 1;
    REPI(itr,mp){
      cout << itr->first << " " << itr->second <<  endl;
      D *= pow(itr->first, itr->second);
    }
    
    REP(i,n){
      printf("%lld\n", D / d[i] * v[i]);
    }
  }

  return 0;
}

C++: /*
 * 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;
}

C++: #include <iostream>
using namespace std;
long long int n,L,d[10],v[10],G,f[10],G1,L1;

long long int gcd(long long int x,long long int y) {
  if(y==0) return x;
  return gcd(y ,x%y);
}

long long int lcm(long long int x,long long int y) {
  return x * y / gcd(x,y);
}

int main() {
  while(cin >> n) {
    if(n==0) break;
    for(int i=0;i<n;i++) {
      cin >> d[i] >> v[i];
      long long int a = gcd(d[i],v[i]); //yakubun
      d[i] /= a;
      v[i] /= a;
    }

    G = gcd(d[0],d[1]);
    L = lcm(d[0],d[1]);
    for(int i=2;i<n;i++) {
      G = gcd(G,d[i]);
      L = lcm(L,d[i]);
    }
    G1 = gcd(v[0],v[1]);
    L1 = lcm(v[0],v[1]);
    for(int i=2;i<n;i++) {
      G1 = gcd(G,v[i]);
      L1 = lcm(L,v[i]);
    }
    /*
    for(int i=0;i<n;i++) {
      d[i] /= G;
    }
*/
    for(int i=0;i<n;i++) {
      f[i] = L * v[i] / (d[i] * G1);
      cout << f[i] << endl;
    }
  }
}

C++: #include <stdio.h>
#include <stack>
#include <math.h>

using namespace std;

long long calc(long long x,long long y){
	if(y == 0){
		return x;
	}else{
		return calc(y,x%y);
	}
}

struct Student{
	long long int distance,speed;
};

int main(){

	int n;
	long long int c_speed,c_distance,work;
	Student students[10];

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		for(int i= 0; i < n; i++){
			scanf("%lld %lld",&students[i].distance,&students[i].speed);
			//?´??????????
			if(students[i].distance > students[i].speed){
				work = calc(students[i].distance,students[i].speed);
			}else{
				work = calc(students[i].speed,students[i].distance);
			}
			students[i].distance /= work;
			students[i].speed /= work;
		}

		//?????????????°???¬?????°????±???????

		//?????????????????§?????????????????????????????????????????????????°???¬?????°????±???????
		for(int i=0; i < n; i++){
			if(i == 0){
				c_speed = students[i].speed;
			}else{
				if(c_speed >= students[i].speed){
					work = calc(c_speed,students[i].speed);
					c_speed = ((c_speed/work)*students[i].speed);
				}else{
					work = calc(students[i].speed,c_speed);
					c_speed = (c_speed*(students[i].speed/work));
				}
			}
		}

		//??????????????????????????????????????????
		for(int i=0; i < n; i++){
			students[i].distance *= (c_speed/students[i].speed);
		}

		//?¬?????????????????°???¬?????°????±???????
		for(int i=0; i < n; i++){
			if(i == 0){
				c_distance = students[i].distance;
			}else{
				if(c_distance >= students[i].distance){
					work = calc(c_distance,students[i].distance);
					c_distance = (c_distance*(students[i].distance/work));
				}else{
					work = calc(students[i].distance,c_distance);
					c_distance = (c_distance*(students[i].distance/work));
				}
			}
		}

		//???????????¨???????±?????????????
		for(int i = 0; i < n; i++){
			students[i].distance = c_distance/students[i].distance;
		}



		//????????????????????§??¬?´???°????±???????
		for(int i=0; i < n; i++){
			if(i == 0){
				work = students[i].distance;
			}else{
				if(work > students[i].distance){
					work = calc(work,students[i].distance);
				}else{
					work = calc(students[i].distance,work);
				}
			}
		}

		for(int i=0; i < n; i++){
			printf("%lld\n",students[i].distance/work);
		}
	}

    return 0;
}