結果

問題 No.889 素数!
ユーザー jp_stejp_ste
提出日時 2020-05-12 00:03:27
言語 JavaScript
(node v21.7.1)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 3,249 bytes
コンパイル時間 203 ms
コンパイル使用メモリ 7,004 KB
実行使用メモリ 44,360 KB
最終ジャッジ日時 2023-08-03 04:01:25
合計ジャッジ時間 8,281 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
42,304 KB
testcase_01 AC 76 ms
42,128 KB
testcase_02 AC 78 ms
42,112 KB
testcase_03 AC 78 ms
42,308 KB
testcase_04 AC 82 ms
42,360 KB
testcase_05 AC 76 ms
42,212 KB
testcase_06 AC 79 ms
42,216 KB
testcase_07 AC 77 ms
42,200 KB
testcase_08 AC 76 ms
42,160 KB
testcase_09 AC 76 ms
42,160 KB
testcase_10 AC 75 ms
42,220 KB
testcase_11 AC 77 ms
42,216 KB
testcase_12 AC 76 ms
42,156 KB
testcase_13 AC 76 ms
42,184 KB
testcase_14 AC 75 ms
42,264 KB
testcase_15 AC 77 ms
42,380 KB
testcase_16 AC 77 ms
42,104 KB
testcase_17 AC 76 ms
42,388 KB
testcase_18 AC 75 ms
42,372 KB
testcase_19 AC 76 ms
42,220 KB
testcase_20 AC 76 ms
42,224 KB
testcase_21 AC 76 ms
42,188 KB
testcase_22 AC 76 ms
42,228 KB
testcase_23 AC 77 ms
42,292 KB
testcase_24 AC 76 ms
42,228 KB
testcase_25 AC 79 ms
42,300 KB
testcase_26 AC 77 ms
42,108 KB
testcase_27 AC 76 ms
42,220 KB
testcase_28 AC 76 ms
42,156 KB
testcase_29 AC 78 ms
44,360 KB
testcase_30 AC 76 ms
42,120 KB
testcase_31 AC 78 ms
42,236 KB
testcase_32 AC 76 ms
42,108 KB
testcase_33 AC 77 ms
42,284 KB
testcase_34 AC 77 ms
42,224 KB
testcase_35 AC 76 ms
42,220 KB
testcase_36 AC 77 ms
42,232 KB
testcase_37 AC 77 ms
42,212 KB
testcase_38 AC 78 ms
42,128 KB
testcase_39 AC 77 ms
42,304 KB
testcase_40 AC 78 ms
42,124 KB
testcase_41 AC 78 ms
42,108 KB
testcase_42 AC 78 ms
42,120 KB
testcase_43 AC 77 ms
42,164 KB
testcase_44 AC 79 ms
42,132 KB
testcase_45 AC 79 ms
42,372 KB
testcase_46 AC 77 ms
42,232 KB
testcase_47 AC 78 ms
42,368 KB
testcase_48 AC 80 ms
42,368 KB
testcase_49 AC 75 ms
42,200 KB
testcase_50 AC 77 ms
42,228 KB
testcase_51 AC 76 ms
42,232 KB
testcase_52 AC 76 ms
42,236 KB
testcase_53 AC 78 ms
42,340 KB
testcase_54 AC 79 ms
42,232 KB
testcase_55 AC 77 ms
42,228 KB
testcase_56 AC 78 ms
42,144 KB
testcase_57 AC 77 ms
42,292 KB
testcase_58 AC 76 ms
42,304 KB
testcase_59 AC 77 ms
42,216 KB
testcase_60 AC 79 ms
42,312 KB
testcase_61 AC 76 ms
42,344 KB
testcase_62 AC 77 ms
42,220 KB
testcase_63 AC 78 ms
42,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

function main(input) {
  let [N] = getIntegers(input, " ");
  if(N <= 1) {
    console.log(N);
  } else if(isSosu(N)) {
    console.log("Sosu!");
  } else if(isHeiho(N)) {
    console.log("Heihosu!");
  } else if(isRipo(N)) {
    console.log("Ripposu!");
  } else if(isKan(N)) {
    console.log("Kanzensu!");
  } else {
    console.log(N);
  }
}

function isSosu(n) {
  if(n == 2) return true;
  for(let i=2; i<=Math.sqrt(n); i++) {
    if(n % i == 0) return false;
  }
  return true;
}

function isHeiho(n) {
  let tmp = Math.floor(Math.pow(n, 1/2));
  return Math.pow(tmp, 2) == n;
}

function isRipo(n) {
  let tmp = Math.floor(Math.pow(n, 1/3));
  return Math.pow(tmp, 3) == n;
}

function isKan(n) {
  let sum = 0;
  for(let i=1; i<n; i++) {
    if(n % i == 0) sum+=i;
  }
  return sum == n;
}

//-- functions ------------------------------------

function getIntegers(lines, sep) {
  if(sep === undefined) {
    return lines.map(function(e) {
      return Number(e);
    });  
  } else {
    return lines.shift().split(sep).map(function(e) {
      return Number(e);
    });  
  }
}

function getStrings(lines, sep=" ") {
  return lines.shift().split(sep);
}

function twoDimenArrayByValue(h, w, value) {
  const list = new Array(h);
  for(let i=0; i<h; i++) {
    list[i] = new Array(w).fill().map(function(e) {
      return value.constructor == Array ? Array.from(value) : value;
    });
  }
  return list;
}

function twoDimenArrayByStrings(h, strings) {
  const list = new Array(h);
  for(let i=0; i<h; i++) {
    list[i] = strings.shift().split("");
  }
  return list;
}

function distance(x1, y1, x2, y2) {
  return Math.sqrt((x2-x1) * (x2-x1) + (y2-y1) * (y2-y1));
}

function gcd(a, b) {
  return b === 0 ? a : gcd(b, a % b);
}

//-- Array -------------------------------------------

Array.prototype.sortByIntegerA = function() {
  this.sort(function(a, b) { return a - b; });
};

Array.prototype.sortByIntegerD = function() {
  this.sort(function(a, b) { return b - a; });
};

Array.prototype.orLess = function(V, l=0, r=this.length) {
  l--;
  while(r - l > 1) {
    let x = Math.floor((r + l) / 2);
    this[x] > V ? r = x : l = x;
  }
  return r;
};

Array.prototype.lessThen = function(V, l=0, r=this.length) {
  l--;
  while(r - l > 1) {
    let x = Math.floor((r + l) / 2);
    this[x] >= V ? r = x : l = x;
  }
  return r;
};

Array.prototype.orHigher = function(V, l, r) {
  return this.length - this.lessThen(V, l, r);
};

Array.prototype.greaterThan = function(V, l, r) {
  return this.length - this.orLess(V, l, r);
};

Array.prototype.deepCopy = function(list) {
  let retList = [];
  for(let i=0; i<list.length; i++) {
    retList[i] = list[i].constructor == Array ? Array.from(list[i]) : list[i];
  }
  return retList;
};

Array.prototype.out = function() {
  let outList = [];
  if(this[0].constructor == Array) {
    for(let i=0; i<this.length; i++) {
      outList.push(this[i].join(" "));
    } 
  } else {
    outList.push(this.join(" "));
  }
  console.log(outList.join("\n"));
};

Array.prototype.pushNoSameValue = function(...values) {
  values.forEach(function(e) {
    if(!this.includes(e)) {
      this.push(e);
    }
  }, this);
};

main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));
0