Submission #19429

#TimeUsernameProblemLanguageResultExecution timeMemory
19429inspire12Σ (kriii4_P2)C++98
0 / 100
1000 ms1080 KiB
/* * 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); }
#Verdict Execution timeMemoryGrader output
Fetching results...