Submission #19423

# Submission time Handle Problem Language Result Execution time Memory
19423 2016-02-24T12:03:06 Z inspire12 Σ (kriii4_P2) C++
0 / 100
6 ms 1084 KB
/*
 * 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
1 Incorrect 6 ms 1084 KB Output isn't correct
2 Halted 0 ms 0 KB -