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<iostream>
#include<algorithm>
#include<vector>
#define PB push_back
using namespace std;

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

vector<long long int> ggg(vector<long long int> v){
    vector<long long int> ret;
    for(int i=0;i<v.size()-1;i++){
	ret.PB(gcd(v[i],v[i+1]));
    }
    return ret;
}

vector<long long int> lcm(vector<long long int> v){
    vector<long long int> ret;
    for(int i=0;i<v.size()-1;i++){
	ret.PB(v[i]*v[i+1]/gcd(v[i],v[i+1]));
    }
    return ret;
}
int main(){
    while(true){
        long long int p = 1;
        long long  int d[11];
        long long int v[11];
	vector<long long int> lc;
        int n;
        cin >> n;
        if(!n) break;
        for(int i=0;i<n;i++){
            cin >> d[i] >> v[i];
	    lc.PB(d[i]/gcd(d[i],v[i]));
        }
	while(lc.size()>1){
	    lc = lcm(lc);
	}
	p = lc[0];
	vector<long long int> ans;
	bool flg = true;
	for(int i=0;i<n;i++){
	    ans.PB(v[i]*p/d[i]);
	}
	vector<long long int> a = ans;
	while(a.size()>1){
	    a = ggg(a);
	}
	for(int i=0;i<n;i++){
	    cout << ans[i] / a[0] << endl;
	}
    }
    return 0;
}

C++: #include<iostream>

typedef unsigned long long int ll;

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

int main(){
	ll d[10], v[10], m = 1, c = 1;
	int n;
	while(std::cin >> n, n){
		m = c = 1;
		for(int i=0;i<n;i++){
			std::cin >> d[i] >> v[i];
			int g = gcd(m, v[i]);
			m = (m * v[i]) / g;
		}
		for(int i=0;i<n;i++){
			d[i] *= m / v[i];
			int g = gcd(c, d[i]);
			c *= d[i] / g;
		}
		for(int i=0;i<n;i++){
			std::cout << c / d[i] << std::endl;
		}
	}
}

C++: #include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

ll d[10], v[10];

int main()
{
	int n;
	
	while (scanf("%d", &n), n){
		ll m = 1ll;
		rep(i, n){
			scanf("%lld %lld", &d[i], &v[i]);
			m = lcm(m, v[i]);
		}
		rep(i, n){
			d[i] *= (m / v[i]);
		}
		m = d[0];
		rep(i, n){
			m = lcm(m, d[i]);
		}
		rep(i, n){
			printf("%lld\n", m / d[i]);
		}
	}
}

C++: #include <iostream>
#include <vector>

using namespace std;

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

int gcm();
int lcm();

// 最大公約数
ll gcm(ll a, ll b) {
	if (a < b) swap(a, b);
	if (b == 0) return 0;
	while (b) {
		a %= b;
		swap(a, b);
	}
	return a;
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a / gcm(a, b) * b;
}

// 約分
P reduction(P a) {
	ll g = gcm(a.first, a.second);

	a.first /= g;
	a.second /= g;

	return a;
}

int main() {
	int n;

	while (cin >> n, n) {
		vector<P> data;
		for (int i = 0; i < n; ++i) {
			int d, v; cin >> d >> v;
			data.push_back( P(d, v) );
		}

		// 約分
		for (int i = 0; i < n; ++i)
			data[i] = reduction(data[i]);

		// 時間計算
		P now = data[0];
		for (int i = 1; i < n; ++i) {
			P next = data[i];

			ll l = lcm(now.second, next.second);
			now.first *= l / now.second;
			next.first *= l / next.second;
			now.second = l;

			now.first = lcm(now.first, next.first);

			now = reduction(now);
		}

		// 出力
		for (int i = 0; i < n; ++i) {
			cout << (now.first * data[i].second / now.second / data[i].first) << endl;
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <cstring>
#include <cstdio>
#define rep(i,n) for(int i = 0 ; i < n ; i++)
using namespace std;

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

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

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	
	while(cin >> n && n){
		long long A[10],B[10] = {};
		long long l = 1;
		for(int i = 0 ; i < n ; i++){
			long long a,b,g;
			cin >> a >> b;
			g = gcd(a,b);
			a/=g;b/=g;
			l = lcm(l,b);
			A[i] = a;
			B[i] = b;
		}
		long long L = 1;
		for(int i = 0 ; i < n ; i++){
			long long a = A[i]*l/B[i];
			//cout << a << endl;
			B[i] = l;
			A[i] = a;
			L = lcm(a,L);
		}
		for(int i = 0 ; i < n ; i++){
			cout << L/A[i] << endl;
		}
		
	}
}

C++: #include <iostream>
using namespace std;

typedef long long int LLI;

int n;
LLI d[10];
int v[10];

bool input() {
  cin >> n;
  if (!n) {
    return false;
  }
  for (int i = 0; i < n; ++i) {
    cin >> d[i] >> v[i];
  }
  return true;
}

LLI gcd(LLI a, LLI b) {
  if (a < b) {
    return gcd(b, a);
  }

  while (b) {
    LLI t = a % b;
    a = b;
    b = t;
  }
  return a;
}

LLI lcm(LLI a, LLI b) {
  LLI g = gcd(a, b);
  return a / g * b;
}

void solve() {
  LLI g = 1;
  for (int i = 0; i < n; ++i) {
    LLI k = gcd(v[i], d[i]);
    v[i] /= k;
    d[i] /= k;
  }
  for (int i = 0; i < n; ++i) {
    g = lcm(v[i], g);
  }
  for (int i = 0; i < n; ++i) {
    d[i] *= g / v[i];
  }
  LLI m = gcd(d[0], d[1]);
  for (int i = 2; i < n; ++i) {
    m = gcd(d[i], m);
  }
  for (int i = 0; i < n; ++i) {
    d[i] /= m;
  }
  g = 1;
  for (int i = 0; i < n; ++i) {
    g = lcm(d[i], g);
  }
  for (int i = 0; i < n; ++i) {
    cout << g / d[i] << endl;
  }
}

int main() {
  while (input()) {
    solve();
  }
  return 0;
}

C++: #include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;

struct NODE{
	int to,cost,ticket;
	NODE(int to,int cost,int ticket) : to(to) , cost(cost) , ticket(ticket) {}
	NODE(){}
};


bool operator < (const NODE &a,const NODE &b){
	return a.cost > b.cost;
}

int main(){
	int c,n,m,s,d;
	while(cin >> c >> n >> m >> s >> d && n){
		s--,d--;
		vector<NODE> e[100];
		for(int i = 0 ; i < m ; i++){
			int a,b,f;
			cin >> a >> b >> f;
			a--,b--;
			e[a].push_back(NODE(b,f,-1));
			e[b].push_back(NODE(a,f,-1));
		}
		int done[110][15] = {};
		priority_queue<NODE> Q;
		Q.push(NODE(s,0,c));
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if( done[q.to][q.ticket]++ ) continue;
			else done[q.to][q.ticket] = true;
			if( q.to == d){
				cout << q.cost << endl;
				break;
			}
			for(int i = 0 ; i < e[q.to].size() ; i++){
				Q.push(NODE(e[q.to][i].to,q.cost+e[q.to][i].cost,q.ticket));
				if( q.ticket ) Q.push(NODE(e[q.to][i].to,q.cost+e[q.to][i].cost/2,q.ticket-1));
			}
		}
	}
}