Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. unsigned long NWW(unsigned long, unsigned long);
  6. unsigned long NWD(int, int);
  7. unsigned long NWWmax(const std::vector<unsigned long>, int, int);
  8. int main()
  9. {
  10. unsigned short z = 0;
  11. std::cin >> z;
  12. unsigned long liczba;
  13. for(int i = 0; i < z; i++){
  14. std::cin >> liczba;
  15. WYNIK(liczba);
  16. }
  17. return 0;
  18. }
  19.  
  20.  
  21.  
  22. unsigned long NWD(int liczba1, int liczba2){
  23. if(liczba1%liczba2 == 0){
  24. return liczba2;
  25. } else {
  26. int b = liczba1%liczba2;
  27. return NWD(liczba2,b);
  28. }
  29. }
  30.  
  31. unsigned long NWWmax(const std::vector<unsigned long> &dzielniki,int start, int end){
  32. unsigned long liczba = NWW(dzielniki[start],dzielniki[start+1]);
  33. for(int i = start+2; i < end; i++){
  34. unsigned long ed = dzielniki[i];
  35. liczba = NWW(ed, liczba);
  36. }
  37. return liczba;
  38.  
  39. }
  40. unsigned long NWW(unsigned long liczba1, unsigned long liczba2){
  41. return (liczba1 * liczba2) / NWD(liczba1, liczba2);
  42. }
  43.  
  44. void WYNIK(unsigned long liczba){
  45. std::vector<unsigned long> dzielnik;
  46. k = liczba;
  47. if(liczba % 2 == 0){
  48. k = liczba / 2;
  49. dzielnik.push_back(k);
  50. } else {
  51. k = liczba / 2 + 1;
  52. }
  53. while(k != 0){
  54. k--;
  55. if(liczba % k == 0){
  56. dzielnik.push_back(k);
  57. }
  58. reverse(dzielnik.begin(), dzielnik.end());
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement