Skip to content

Instantly share code, notes, and snippets.

@akahana-1
Created October 27, 2014 08:58
Show Gist options
  • Save akahana-1/6a79d4a5ccccf4a2a16c to your computer and use it in GitHub Desktop.
Save akahana-1/6a79d4a5ccccf4a2a16c to your computer and use it in GitHub Desktop.
周回距離と速度の最小公倍数から周回距離を割ったものが全て同一であればいいはず……(しかしWA
#include <iostream>
#include <utility>
#include <algorithm>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
bool alldiv(ll t, ll* nums, ll n){
bool f = true;
for(int i = 0;i < n;++i){
f = f && (t % nums[i] == 0);
}
return f;
}
ll gcd(ll n, ll m){
ll mod;
if(n == m) return n;
if(n == 0 || m == 0) return 0;
while(m != 0){
mod = n % m;
n = m;
m = mod;
}
return n;
}
ll lcm(ll n, ll m){
return n / gcd(n, m) * m;
}
int main(){
ll n, dist[10], v[10], divisor, ans;
vector<P> comb;
//bool f;
while(cin >> n, n){
//f = true;
comb.reserve(n);
for(int i = 0;i < n;++i){
cin >> dist[i] >> v[i];
divisor = gcd(dist[i], v[i]);
dist[i] /= divisor;
v[i] /= divisor;
comb[i] = make_pair(dist[i], lcm(dist[i], v[i]));
//cout << comb[i].first << " " << comb[i].second << endl;
}
sort(comb.begin(), comb.end());
for(int i = 0;i < n;++i){
//cout << comb[n - i - 1].first << comb[n - i - 1].second << endl;
cout << comb[i].second * comb[n - i - 1].first / dist[i] << endl;
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment