Advertisement
Guest User

Untitled

a guest
Jan 18th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4.  
  5. using namespace std;
  6.  
  7. int main()
  8. {
  9. int A, PomA, sumaA = 0; //inty do A
  10. int B, PomB, sumaB = 0; //inty do B
  11.  
  12. cout<<"Podaj liczbe A: "; cin>>A; //Podanie liczby A
  13.  
  14. if(A < 1)//Zabezpieczenie
  15. {
  16. cout<<"Blad!"<<endl;
  17. return 0;
  18. }
  19.  
  20. PomA = A;
  21.  
  22. cout<<"Dzielniki liczby A: ";
  23.  
  24. for(int i = 2; i <= A; i++)
  25. {
  26. if(PomA%i == 0)
  27. {
  28. PomA /= i;
  29. sumaA = sumaA + PomA;
  30. cout<<PomA<<" ";
  31. }
  32. PomA = A;
  33. }
  34. cout<<endl;
  35. cout<<"Suma dzielnikow A to: "<<sumaA<<" lub tez: "<<sumaA-1<<"+1"<<endl;
  36. cout<<endl;
  37. cout<<"Podaj liczbe B: "; cin>>B; //Podanie liczby B
  38.  
  39. if(B < 1)//Zabezpieczenie
  40. {
  41. cout<<"Blad!"<<endl;
  42. return 0;
  43. }
  44.  
  45. PomB = B;
  46.  
  47. cout<<"Dzielniki liczby B: ";
  48.  
  49. for(int i = 2; i <= B; i++)
  50. {
  51. if(PomB%i == 0)
  52. {
  53. PomB /= i;
  54. sumaB = sumaB + PomB;
  55. cout<<PomB<<" ";
  56. }
  57. PomB = B;
  58. }
  59. cout<<endl;
  60. cout<<"Suma dzielnikow B to: "<<sumaB<<" lub tez: "<<sumaB-1<<"+1"<<endl;
  61. cout<<endl;
  62. cout<<endl;
  63. cout<<"Podsumowanie: "<<endl;
  64. cout<<"Liczba A: "<<A<<" do sumy dzielnikow B: "<<sumaB<<" lub "<<sumaB-1<<"+1"<<endl;
  65. cout<<"Liczba B: "<<B<<" do sumy dzielnikow A: "<<sumaA<<" lub "<<sumaA-1<<"+1"<<endl;
  66. cout<<endl;
  67. cout<<endl;
  68. cout<<"Odpowiedz:"<<endl;
  69.  
  70. if((sumaB-1 == A) && (sumaA-1 == B))
  71. {
  72. cout<<"Liczby sa skojarzone!"<<endl;
  73. }
  74. else
  75. {
  76. cout<<"Liczby nie sa skojarzone"<<endl;
  77. }
  78.  
  79. return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement