fork download
  1. #include <iostream>
  2. #include <cmath>
  3. using namespace std;
  4.  
  5. int main() {
  6. // your code goes here
  7.  
  8. double diff = 1e300, l2 = log(2), l3 = log(3);
  9. int M = 2000, bi = -1, bj = -1;
  10. for (int i = 1; i < M; ++i)
  11. for (int j = 1; j < M; ++j) {
  12. if (abs(l2 * i - l3 * j) < diff) {
  13. diff = abs(l2 * i - l3 * j);
  14. bi = i;
  15. bj = j;
  16. }
  17. }
  18.  
  19. printf("The difference between %.5lf * %d and %.5lf * %d is %.10lf\n", l2, bi, l3, bj, diff);
  20.  
  21. return 0;
  22. }
Success #stdin #stdout 0.02s 3412KB
stdin
Standard input is empty
stdout
The difference between 0.69315 * 1054 and 1.09861 * 665 is 0.0000436541