Advertisement
rotti321

model 2022 SIII ex 1

Nov 4th, 2021
91
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ///VAR I SIII ex 1
  2. ///a<b<c
  3. ///a*b*c=[a,b,c]*(a,c)*(b,c), unde cmmmc(a,b)=[a,b], cmmdc(a,b)=(a,b)
  4.  
  5. #include <iostream>
  6. #include <cstring>
  7.  
  8. using namespace std;
  9. int cmmdc(int a,int b){
  10. int r;
  11. while(b!=0){
  12. r=a%b;
  13. a=b;
  14. b=r;
  15. }
  16. return a;
  17. }
  18. int mozaic(int x,int y ,int z){
  19. int a=x;
  20. int b=y;
  21. int r;
  22. int m;
  23. if(x>y){
  24. r=x; x=y; y=r;
  25. }
  26. if(y>z){
  27. r=y; y=z; z=r;
  28. }
  29. if(x>z){
  30. r=z;z=x;x=r;
  31. }
  32. a=x;
  33. b=z;
  34. m=x*y*z;
  35. return m/(cmmdc(x,z)*cmmdc(y,z));
  36. }
  37.  
  38. int main(){
  39. int x,y,z;
  40. cin>>x>>y>>z;
  41. cout<<mozaic(x,y,z);
  42. }
  43.  
  44. ///VAR II SIII ex 1
  45.  
  46. #include <iostream>
  47. #include <cstring>
  48.  
  49. using namespace std;
  50.  
  51. int mozaic(int x,int y ,int z){
  52. int d=2,e,rez=1;
  53. while(x>1 && y>1 && z>1){
  54. while(x%d==0 || y%d==0 || z%d==0){
  55. if(x%d==0) x=x/d;
  56. if(y%d==0) y=y/d;
  57. if(z%d==0) z=z/d;
  58. rez=rez*d;
  59. }
  60. d++;
  61. }
  62. return rez;
  63. }
  64.  
  65. int main(){
  66. int x,y,z;
  67. cin>>x>>y>>z;
  68. cout<<mozaic(x,y,z);
  69. }
Advertisement
RAW Paste Data Copied
Advertisement