Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let testN=100;
- let roundCount=100;
- const breakeNumber = number => {
- let buf=0;
- while (number%2===0) {
- buf++;
- number=number/2;
- }
- return [buf,number]; //buf - степень двойки s, t; number - t
- }
- const checkSimple = (n,roundCount) => {
- let buf=n-1;
- let flag=0;
- let s=breakeNumber(buf)[0];
- let d=breakeNumber(buf)[1];
- for (let i=0;i<roundCount;++i) {
- let a=Math.floor((Math.random()*(n-4))+2);
- if (Math.pow(a,d)%n===1) {
- return true;
- }
- for (let j=0;j<s-1;++j) {
- let buf=Math.pow(a,(d*Math.pow(2,j)));
- if (buf%n===-1) return true;
- }
- }
- return false;
- }
- const checkIsPervSqrt = (A,numb) => {
- let buf=[];
- for (let i=1;i<numb;++i){
- let bufNumb=Math.pow(A,i)%numb;
- console.log(`${A}^${i}=${bufNumb}`);
- if (buf.includes(bufNumb)) { return false;}
- else {
- buf.push(bufNumb); }
- }
- return true;
- }
- console.log(checkSimple(testN,roundCount));
- //checkSimple(testN,roundCount);
- console.log(checkIsPervSqrt(2,17));
Add Comment
Please, Sign In to add comment