# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
19423 | inspire12 | Σ (kriii4_P2) | C++98 | 6 ms | 1084 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
* 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(){
int mode = 1000000007;
int m;
scanf("%d",&m);
int 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;
int i;
for(i=1; (i*mode+S)%N!=0;i++){
}
// printf("%d %d\n",S,N);
printf("%d",(i*mode+S)/N%mode);
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |