<html>
<head>
<title>JavaSctipt</title>
<meta charset="utf-8">
</head>
<body>
请输入一个大于2的整数:<input id="input_demo"/>
<input type="button" onclick="myFunction();" value="然后点这儿">
<p>点击计算整数的全部质合数组成。</p>
<script>
function acFunc(n) {
if ((typeof n) != Number) {
var m = 2;
var r = "1";
while (true) {
if (n == m) {
r += "*" + m;
break
}else if ((n % m) == 0) {
n = parseInt(n / m);
console.log(n)
r += "*" + m;
m = 2;
}else {
m += 1;
}
}
console.log(r)
return r;
}
alert("不是数字!")
}
function myFunction() {
var n = document.getElementById("input_demo").value;
console.log(typeof Number(n))
if ((n != null) && (n != '1') && (Number(n) != NaN)) {
console.log("111")
document.getElementById("demo").innerHTML = acFunc(n);
}else {
console.log("重新输入!")
alert("请输入一个大于2的整数!")
}
}
</script>
<p id="demo">www</p>
</body>
</html> 大神求带 666 {:5_102:} var num = prompt("请输入一个整数:");
var p = num;
var arr = [];
while(1){
for (var i=2; i <= num ; i++){
if (num%i == 0){
num /= i;
arr.push(i);
break;
}
}
if(i > num){
break;
}
}
alert(p + "=" + arr.join("*")); ggggg 记不起什么是因子了
var number = parseInt(prompt("输入一个整数"));
var number1;
var string = "";
new String(string);
number1 = number;
if (!number) {
alert("请输入一个整数");
}
for (var j = 0; j <= (number); j++) {
for (var i = 2; i <= (number); i++) {
if (number % i == 0) {
number = number / i;
string = string + (i + "*");
break;
}
}
}
string = string.slice(0, string.length - 1);
console.log(number1 + "=" + string); function getPrimeFactor (num) {
let num_1 = num
let a = 2;
let b = `${num_1}=`;
while (true) {
if(num_1 % a == 0) {
if(num_1 / a == 1) {
return b+ a;
}
num_1 = num_1 / a;
b+= a + '*';
a = 2
}else {
a++
}
}
}
console.log(getPrimeFactor(90)) 学习一下 ◉‿◉
◉‿◉
◉‿◉
◉‿◉
◉‿◉ 66 look 1 看好了什么叫做简洁优雅
<script>
var x=parseInt(prompt("请输入所要分解的数:"));
var pr="90=";
for(var i=2;i<Math.sqrt(x);i++){
if(x%i===0){
x=x/i;
pr+=i+"*";
i=2;
continue
}
}
pr+=x
alert(pr);
</script> 666 看看
页:
1
[2]