https://www.acmicpc.net/problem/17433
const input = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n');
for (let i = 0; i < input.length; i++) input[i] = input[i].split(/\s/).map(v=>+v);
const gcd = (x , y) => {
while (y) {
let t = x % y;
x = y;
y = t;
}
return x;
}
let tmp, res;
for (let i = 1; i <= input[0][0]; i++) {
tmp = Array.from({length: input[2 * i - 1][0]}, (undefined, i) => 0);
for (let j = 1; j < input[2 * i - 1][0]; j++) tmp[j] = Math.abs(input[2 * i][j] - input[2 * i][j - 1]);
res = tmp[0];
for (let j = 1; j < input[2 * i - 1][0]; j++) res = gcd(res, tmp[j]);
console.log(res = (res ? res : "INFINITY"));
}
|
cs |
'그 밖의 방법들' 카테고리의 다른 글
파이썬으로 피보나치 수열을 구하는 여러가지 방법 (0) | 2022.06.02 |
---|---|
백준 10814 나이순 정렬, 안정 정렬 (0) | 2022.06.02 |
SQL/MySQL의 기초 - WHERE, SubQuery (0) | 2022.05.25 |
빠른 입출력 [node JS] 백준 15552번 - 빠른 A+B, 최대한 다양하게 (0) | 2022.05.25 |
빠른 입출력 [C#] 백준 15552번 - 빠른 A+B, 최대한 다양하게 (0) | 2022.05.25 |