Discover companies you will love

Personal Achievements

Personal Achievements

Personal Achievements

  • 2以上の任意の自然数Nを素因数分解するコードです。このコードはJavaScriptで書かれています。

    const N = ; let s = new Set(); let f = new Set(); var m = N; for(var p = 2; p <= m; p = (p + 1)) { if(s.has(p) === true) { continue; } else { if((m % p) === 0) { var t = 0; do { var t = (t + 1); var m = (m / p); } while((m % p) === 0); f.add(p + '^' + t); for(var d = 1; (d * p) < m; d = (d + 1)) { s.add(d * p); }; } else { for(var d = 1; (d * p) < m; d = (d + 1)) { s.add(d * p); }; }; }; if(m === 1) { if(f.size === 1) { console.log(N + ' = ' + p + '^' + t); break; } else { var ary = []; for(let value of f.values()) { ary.push(value); }; var solution = ary[0]; for(var z = 1; z < ary.length; z = (z + 1)) { var solution = (N + ' = ' + solution + ' * ' + ary[z]); }; console.log(solution); break; }; } else { continue; }; };

  • 2以上の任意の自然数Nを素因数分解するコードです。このコードはJavaScriptで書かれています。

    var N = ; var passed_p_memory = []; var p_memory = []; var t_memory = []; function mod_p(v1) { if (v1 === 2) { return ; } else { for (var n1 = 0; n1 < passed_p_memory.length; n1 = (n1 + 1)) { if ((v1 % passed_p_memory[n1]) === 0) { return 0; break; } else { if (n1 === (passed_p_memory.length - 1)) { return ; break; } else { continue; }; }; }; }; }; function p_recoder(v1) { if (p_memory.includes(v1) === true) { } else { p_memory.push(v1); }; return ; }; function t_recoder(v1) { if (t_memory[p_memory.indexOf(v1)] === undefined) { t_memory.push(1); } else { t_memory[p_memory.indexOf(v1)] = (t_memory[p_memory.indexOf(v1)] + 1); }; return ; }; var re_N = N; for (var n2 = 2; n2 <= re_N; n2 = (n2 + 1)) { if (mod_p(n2) === 0) { continue; } else { passed_p_memory.push(n2); while ((re_N % n2) === 0) { p_recoder(n2); t_recoder(n2); var re_N = (re_N / n2); }; continue; }; }; var answer = (p_memory[0] + '^' + t_memory[0]); if (p_memory.length === 1) { console.log(N + ' = ' + answer); } else { for (var n3 = 1; n3 < p_memory.length; n3 = (n3 + 1)) { var answer = (answer + ' * ' + p_memory[n3] + '^' + t_memory[n3]); }; console.log(N + ' = ' + answer); };

  • 任意の2つの自然数XとYの最大公約数GCD(X, Y)を求めるコードです。XにはYより大きい自然数を代入してください。このコードはJavaScriptで書かれています。

    const X = ; const Y = ; var y = X; var z = Y; do { var x = y; var y = z; var z = (x % y); } while(z > 1); if(z === 1) { console.log('GCD(' + X + ', ' + Y + ') = ' + 1); } else { console.log('GCD(' + X + ', ' + Y + ') = ' + y); };

  • 2以上の任意の自然数Pが素数か否かを判定するコードです。このコードはJavaScriptで書かれています。

    const P = ; if ((P % 2) === 0) { if (P === 2) { console.log('P is a Prime number.') } else { console.log('P is not a Prime number.') } } else { for (var k = 1; ((2 * k) + 1) <= (P / 2); k = (k + 1)) { var c = ((2 * k) + 1) if (c === 3) { if ((P % c) === 0) { if (P === 3) { console.log('P is a Prime number.') break } else { console.log('P is not a Prime number.') break } } else { continue } } else { for (var l = 1; ((2 * l) + 1) <= (c / 2); l = (l + 1)) { var d = ((2 * l) + 1) if ((c % d) === 0) { break } else { continue } if (d >= ((c / 2) - (3 / 2))) { if ((P % c) === 0) { console.log('P is not a Prime number.') break break } else { continue } } else { continue } } if (c >= ((P / 2) - (3 / 2))) { console.log('P is a Prime number.') break } else { continue } } } };



言語

  • English - Conversational
  • Japanese - Native

Receive Scouts from companies