ademosh

Untitled

Mar 27th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. let testN=100;
  2.  
  3.  
  4. let roundCount=100;
  5.  
  6. const breakeNumber = number => {
  7. let buf=0;
  8. while (number%2===0) {
  9. buf++;
  10. number=number/2;
  11. }
  12. return [buf,number]; //buf - степень двойки s, t; number - t
  13. }
  14.  
  15.  
  16. const checkSimple = (n,roundCount) => {
  17. let buf=n-1;
  18. let flag=0;
  19. let s=breakeNumber(buf)[0];
  20. let d=breakeNumber(buf)[1];
  21. for (let i=0;i<roundCount;++i) {
  22. let a=Math.floor((Math.random()*(n-4))+2);
  23. if (Math.pow(a,d)%n===1) {
  24. return true;
  25. }
  26. for (let j=0;j<s-1;++j) {
  27. let buf=Math.pow(a,(d*Math.pow(2,j)));
  28. if (buf%n===-1) return true;
  29. }
  30. }
  31. return false;
  32. }
  33.  
  34. const checkIsPervSqrt = (A,numb) => {
  35. let buf=[];
  36. for (let i=1;i<numb;++i){
  37. let bufNumb=Math.pow(A,i)%numb;
  38. console.log(`${A}^${i}=${bufNumb}`);
  39. if (buf.includes(bufNumb)) { return false;}
  40. else {
  41. buf.push(bufNumb); }
  42. }
  43. return true;
  44. }
  45.  
  46. console.log(checkSimple(testN,roundCount));
  47. //checkSimple(testN,roundCount);
  48. console.log(checkIsPervSqrt(2,17));
Add Comment
Please, Sign In to add comment