gagantheroyal's blog

By gagantheroyal, history, 9 years ago, In English

I am new to using Far Manager (http://www.farmanager.com/). I found it very helpful for managing files and editing. But when it comes to compiling and running programs I think we have to do many things manually similar to as while running programs from command line (as compared to using suitable IDE). Also I could not find any good tutorial (in English) for compiling, running and debugging c/c++ programs using Far. Could any one please explain how I can do these tasks (compiling, running and debugging) easily? i.e. with very less manual efforts?

Also it would be great to get an explanation (steps) for running interactive programs (having user interaction in command line for giving inputs to the program). You can also post some good links to tutorials (in English) explaining all these.

Full text and comments »

  • Vote: I like it
  • +8
  • Vote: I do not like it

By gagantheroyal, history, 9 years ago, In English

I want to find number of integers from 1 to 19 (both included) which are divisible by 2 or 3 or 4. Lets denote it by N. So counting and enumerating them gives N = 12. Integers are 2, 3, 4, 6, 8, 9, 10, 12, 14, 15, 16 and 18.

I thought of applying inclusion-exclusion principle for finding N. Here is how I proceeded:

Lets denote the followings:

N1 = (Number of integers which are divisible by 2) + (Number of integers which are divisible by 3) + (Number of integers which are divisible by 4)

N2 = (Number of integers which are divisible by 2*3 = 6) + (Number of integers which are divisible by 3*4 = 12) + (Number of integers which are divisible by 2*4 = 8)

N3 = (Number of integers which are divisible by 2*3*4 = 24)

Then using inclusion-exclusion principle we have: N = N1 — N2 + N3

Finding N1, N2 and N3 (denoting Greatest Integer Function using floor function):

N1 = floor(19 / 2) + floor(19 / 3) + floor(19 / 4) = 9 + 6 + 4 = 19

N2 = floor(19 / 6) + floor(19 / 12) + floor(19 / 8) = 3 + 1 + 2 = 6

N3 = floor(19 / 24) = 0

Therefore, N = N1 — N2 + N3 = 19 — 6 + 0 = 13.

From here, I am getting N = 13 which is wrong as I counted them manually above (N = 12).

Can anyone point out the mistake I am making here and suggest the correct way of doing this using inclusion-exclusion principle?

Full text and comments »

  • Vote: I like it
  • +3
  • Vote: I do not like it