Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. std::vector<unsigned long> obliczUlamekLancuchowy(unsigned long liczba) {
  5.     unsigned long r = floor(sqrt(liczba));
  6.     unsigned long a = r;
  7.     unsigned long p = 0;
  8.     unsigned long q = 1;
  9.     std::vector<unsigned long> vector;
  10.  
  11.     vector.push_back(r);
  12.  
  13.     do {
  14.         p = a * q - p;
  15.         q = (liczba - p * p) / q;
  16.         a = (r + p) / q;
  17.         vector.push_back(a);
  18.     } while (q != 1);
  19.  
  20.     return vector;
  21. }
  22.  
  23.  
  24. int main(int argc, char* argv[])
  25. {
  26.     long liczba;
  27.     std::cin >> liczba;
  28.     std::vector<unsigned long> vector = obliczUlamekLancuchowy(liczba);
  29.     for (unsigned long numer : vector)
  30.     {
  31.         printf("%lu ", numer);
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement