using namespace std;.
You can, however, in a CPP file (not H file) or inside a function put individual
using std::string; etc. (See SF.7.)
n change? I think not; you are just looping through all values of
i, right? Put the work in a separate function, and these parameters can be
const. That will make it easier to read and understand.
In general, separate out input, the real work, and output.
Division (and modulo) is dog slow on most CPUs. On the x86 chips, for example, you can look at Agner Fog's charts on the internal resources used for each operation. Besides having a long latency and taking a lot of cycles, on the chips I looked at (e.g. Broadwell) it uses a great many of the dispatch ports. So, it also clogs up the internal resources and prevents instruction-level parallelism from filling in the long latency.
Since you are incrementing
i, incrementally adjust the result of the modulo as well. That would be about a hundred times faster than the
% I would think (ballpark).
((min(m, n)) / 2) + 1 each time through. Does the optimizer figure out that this never changes? If you used
const (see above) I think it would have a better chance of doing so for you. But, you should just precalculate
end yourself and it makes the loop more readable too.