結果

問題 No.2821 A[i] ← 2A[j] - A[i]
ユーザー viral8
提出日時 2024-04-07 00:53:43
言語 Java
(openjdk 23)
結果
AC  
実行時間 1,142 ms / 1,500 ms
コード長 553 bytes
コンパイル時間 2,730 ms
コンパイル使用メモリ 84,040 KB
実行使用メモリ 73,928 KB
最終ジャッジ日時 2024-07-26 20:51:16
合計ジャッジ時間 20,849 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A = sc.nextLong();
		long gcd = 0;
		StringBuilder ans = new StringBuilder();
		while(--N>0){
			ans.append(gcd).append('\n');
			long nextA = sc.nextLong();
			gcd = gcd(gcd,Math.abs(A-nextA));
		}
		ans.append(gcd);
		System.out.println(ans.toString());
	}
	private static long gcd(long a,long b){
		if(b==0)
			return a;
		long temp;
		while((temp=a%b)!=0){
			a = b;
			b = temp;
		}
		return b;
	}
}
0