結果

問題 No.280 歯車の問題(1)
ユーザー 37zigen
提出日時 2016-05-18 20:36:27
言語 Java
(openjdk 23)
結果
AC  
実行時間 163 ms / 1,000 ms
コード長 717 bytes
コンパイル時間 3,728 ms
コンパイル使用メモリ 76,244 KB
実行使用メモリ 56,568 KB
最終ジャッジ日時 2024-10-06 05:37:58
合計ジャッジ時間 9,055 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 31
権限があれば一括ダウンロードができます

ソースコード

diff #

package yukicoder;
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		new Main().solve();
	}
	void solve(){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		long[] z=new long[n];
		for(int i=0;i<n;i++)z[i]=sc.nextLong();
		long gcd=gcd(z[0],z[n-1]);
		System.out.println(z[n-1]/gcd+"/"+z[0]/gcd);
		/*
		 *θ1 = z2/z1 * θ2
		 * 	 = z2/z1 * z3/2 * θ3
		 *   = z3/z1 * θ3
		 *...
		 *=zn/z1 * θn
		 *
		 *gr=θ1/θn=zn/z1
		 */
	}
	long lcm(long t1,long t2){
		long a=gcd(t1,t2);
		long tt1=t1/a;
		long tt2=t2/a;
		return tt1*tt2*a;
	}
	long gcd(long t1,long t2){
		if(t1<t2){
			long d=t2;
			t2=t1;
			t1=d;
		}
		if(t2==0)return t1;
		return gcd(t2,t1%t2);
	}
}
0