結果
問題 | No.889 素数! |
ユーザー |
![]() |
提出日時 | 2020-05-12 00:03:27 |
言語 | JavaScript (node v23.5.0) |
結果 |
AC
|
実行時間 | 67 ms / 2,000 ms |
コード長 | 3,249 bytes |
コンパイル時間 | 75 ms |
コンパイル使用メモリ | 5,376 KB |
実行使用メモリ | 39,424 KB |
最終ジャッジ日時 | 2024-10-13 01:51:29 |
合計ジャッジ時間 | 5,339 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 61 |
ソースコード
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"));