Untitled

 avatar
unknown
plain_text
a month ago
5.5 kB
3
Indexable
<noscript>
    <style>
        .outer {display: none}
    </style>
    <div class="b c" style="background:mistyrose;color:brown;font-size:24px;border-radius:4px;margin:10px 0">
        Google ID <strong>rbisir1</strong>
    </div>
</noscript>
<div class="b c outer">
    <div class="b c">
        <h1><strong>[RBISIR]FACTORISES</strong></h1></div>
    <div class="b c output" id=out_fac>[RBISIR]OUTPUTS</div>
    <div class="b c input">
        <div class="b c">
            <p class="b c">INSERT INTEGERS[RBISIR]</p>
            <input type=number max=9999999999 min=-9999999999 step=1 class="b c inp" id=inp_int placeholder="TYPE NUMBER[RBISIR]" title="Type the input here">
        </div>
    </div>
</div>
<style>
body {
    background: #888;
    color: #fff;
}

.b,
.inp {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    font-family: consolas, monaco, menlo, courier, monospace;
    font-size: 16px;
    color: #000;
}

.c {
    text-align: center;
    margin: auto;
}

.c > h1 {}

.outer {
    padding: 10px;
}

.input,
.output {
    padding: 10px;
    background: #ccc;
    box-shadow: 1px 1px 2px #222 inset;
    margin: 10px 0;
}

.inp {
    padding: 10px;
    width: 360px;
    max-width: 100%;
    background: lemonchiffon;
    margin-top: 10px;
}

.inp,
.input,
.output {
    border-radius: 5px;
}

.inp:focus {
    background: ghostwhite;
    outline: 0;
}

.pres,
.err {
    font-size: 20px;
}

.err {
    color: brown;
}
</style>
<script>
(function run(z) {
    "use strict";
    function getFactors(a) {
        var primeTest = function (b) {
            var limit = Math.floor(Math.sqrt(b));
            var mod = 2;
            var primeOrNot = 1;
            while (mod <= limit) {
                if (b % mod === 0) {
                    primeOrNot = 0;
                    break;
                }
                mod += 1;
            }
            return primeOrNot;
        };
        // -----------------------------------------------
        var ne = function (c) { // to convert positive to negative
            return (-1 * c);
        };
        // -----------------------------------------------
        var checkElm = function (d, e) {
            var k = 0;
            var l = e.length;
            var r = 1;
            while (k < l) {
                if (e[k][0] === d[1] && e[k][1] === d[0]) {
                    r = 0;
                    break;
                }
                k += 1;
            }
            return r;
        };
        // -----------------------------------------------
        var result = [];
        var i;
        var div;
        var buff;
        // -----------------------------------------------
        var sign = 0; // negative flag
        var resultSign = [];
        var buffSign;
        // -----------------------------------------------
        if (typeof a === "number" && a % 1 === 0 && a !== 0 && a < 1e9) {
            if (a < 0) {
                sign = 1;
                a = Math.abs(a);
            }
            if (primeTest(a)) {
                if (!sign) {
                    result = [[1, a], [ne(1), ne(a)]];
                } else {
                    if (a !== 1) {
                        result = [[ne(1), a], [ne(a), 1]];
                    } else {
                        result = [[-1, 1]];
                    }
                }
            } else {
                i = a;
                while (i > 0) {
                    if (a % i === 0) {
                        div = a / i;
                        if (!sign) {
                            buff = [div, i];
                            buffSign = [ne(div), ne(i)];
                            if (i < a) {
                                if (checkElm(buff, result)) {
                                    result.push(buff);
                                }
                                if (checkElm(buffSign, resultSign)) {
                                    resultSign.push(buffSign);
                                }
                            } else {
                                result.push(buff);
                                resultSign.push(buffSign);
                            }
                        } else {
                            resultSign.push([ne(div), i]);
                        }
                    }
                    i -= 1;
                }
                if (sign) {
                    result = resultSign;
                } else {
                    result = result.concat(resultSign);
                }
            }
        }
        // -----------------------------------------------
        return result;
    }

    // -----------------------------------------------
    // INTERFACE CONTROLLER
    function calculate(a, b) {
        var v = a.value;
        var o;
        var res;
        if (/-?[0-9]+/.test(v)) {
            o = getFactors(Number(v));
            res = "";
            if (o.length) {
                o.forEach(function (va) {
                    res += "<p class='pres'>" + va[0] + " × " + va[1] + "</p>";
                });
                b.innerHTML = res;
            } else {
                b.innerHTML = "<p class='err'>INPUT NON-ZERO[RBISIR]</p>";
            }
        } else {
            b.innerHTML = "OUTPUT";
        }
    }
    var g = function (a) {
        return z.getElementById(a);
    };
    var inp = g("inp_int");
    var out = g("out_fac");
    inp.oninput = function () {
        calculate(inp, out);
    };
}(document));
</script>
Editor is loading...
Leave a Comment