Home  >  Article  >  Backend Development  >  Find whether two numbers are mutually prime (coprime)

Find whether two numbers are mutually prime (coprime)

WBOY
WBOYOriginal
2016-07-25 08:48:271642browse
Use the euclidean method to find out whether two numbers are prime numbers (prime numbers)
  1. $a=200;
  2. $b=13;
  3. //Euclidean division method
  4. if($b>$a){
  5. $x=$a;$a=$b;$ b=$x;
  6. }
  7. while(1){
  8. //echo "a=".$a." b=".$b;echo "n";
  9. if($b==1){echo " Reciprocally prime";break;}
  10. if($b==0){echo "Not reciprocally prime";break;}
  11. if($a-$b > $b){
  12. $a=$a-$b ;
  13. }else{
  14. $a=$a-$b;
  15. $x=$a;$a=$b;$b=$x;
  16. }
  17. }
  18. ?>
Copy code


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn