/*
* pro2.cpp
*
* Created on: 2016. 2. 24.
* Author: SeoYoungHak
*/
#include <stdio.h>
int gcd(int a,int b){ //최대공약수
if(b==0)return a;
return gcd(b,a%b);
}
int main(){
long long mode = 1000000007;
int m;
scanf("%d",&m);
long long N=0,S=0;//A : 약분전 분자,
int n[m],s[m];
for(int i=0;i<m;i++){
scanf("%d %d",&n[i],&s[i]);
}
if(m>1){
for(int i=1;i<m;i++){
N = n[i-1];
N = N*n[i]/gcd(N,n[i]);
}
// printf("%d",N);
for(int i=0;i<m;i++){
s[i]=s[i] * N/n[i];
S+=s[i];
}
}else{
S=s[0];
N=n[0];
}
int k=gcd(S,N);
S=S/k;
N=N/k;
long long i;
for(i=1; (i*mode+S)%N!=0;i++){
}
// printf("%lld %lld %d\n",S,N,i);
printf("%lld",(i*mode+S)/N);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1000 ms |
1080 KB |
Program timed out |
2 |
Halted |
0 ms |
0 KB |
- |