fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. long long a, b; // ułamek a/b, gdzie b = 2^k
  6. cin >> a >> b;
  7.  
  8. // Rozwinięcie binarne ułamka właściwego
  9. cout << "0.";
  10.  
  11. long long x = a;
  12. while (x > 0) {
  13. x *= 2;
  14. if (x >= b) {
  15. cout << 1;
  16. x -= b;
  17. } else {
  18. cout << 0;
  19. }
  20. }
  21.  
  22. cout << endl;
  23. return 0;
  24. }
  25.  
Success #stdin #stdout 0.01s 5292KB
stdin
3 8
stdout
0.011