fork download
  1. #include <bits/stdc++.h>
  2. int number_of_iterations(const int n) {
  3. int answ(0);
  4. for (int x = 2, low; x <= n; x++) {
  5. for (low = 2; low * low <= x && x % low != 0; low++);
  6. answ += low - 2 + 1;
  7. }
  8. return answ;
  9. }
  10. int main() {
  11. for (int n = 2; n <= (1 << 22); n *= 2) {
  12. std::cout << "n = " << n << ", ";
  13. std::cout << "log(n) = " << std::ilogb(n) << ", n*sqrt(n) / number_of_iter = ";
  14. std::cout << std::sqrt(n) * n / number_of_iterations(n) << std::endl;
  15. }
  16. return 0;
  17. }
Success #stdin #stdout 2.28s 4436KB
stdin
Standard input is empty
stdout
n = 2, log(n) = 1, n*sqrt(n) / number_of_iter = 2.82843
n = 4, log(n) = 2, n*sqrt(n) / number_of_iter = 2.66667
n = 8, log(n) = 3, n*sqrt(n) / number_of_iter = 2.51416
n = 16, log(n) = 4, n*sqrt(n) / number_of_iter = 2.78261
n = 32, log(n) = 5, n*sqrt(n) / number_of_iter = 2.96753
n = 64, log(n) = 6, n*sqrt(n) / number_of_iter = 3.45946
n = 128, log(n) = 7, n*sqrt(n) / number_of_iter = 3.9352
n = 256, log(n) = 8, n*sqrt(n) / number_of_iter = 4.49123
n = 512, log(n) = 9, n*sqrt(n) / number_of_iter = 5.09914
n = 1024, log(n) = 10, n*sqrt(n) / number_of_iter = 5.80581
n = 2048, log(n) = 11, n*sqrt(n) / number_of_iter = 6.55923
n = 4096, log(n) = 12, n*sqrt(n) / number_of_iter = 7.3368
n = 8192, log(n) = 13, n*sqrt(n) / number_of_iter = 8.18049
n = 16384, log(n) = 14, n*sqrt(n) / number_of_iter = 9.04506
n = 32768, log(n) = 15, n*sqrt(n) / number_of_iter = 9.97587
n = 65536, log(n) = 16, n*sqrt(n) / number_of_iter = 10.908
n = 131072, log(n) = 17, n*sqrt(n) / number_of_iter = 11.8584
n = 262144, log(n) = 18, n*sqrt(n) / number_of_iter = 12.8345
n = 524288, log(n) = 19, n*sqrt(n) / number_of_iter = 13.8089
n = 1048576, log(n) = 20, n*sqrt(n) / number_of_iter = 14.8113
n = 2097152, log(n) = 21, n*sqrt(n) / number_of_iter = 15.8137
n = 4194304, log(n) = 22, n*sqrt(n) / number_of_iter = 16.8264