Find the number of integer solutions satisfying the inequality:

A < B*x + C ≤ D 
 (0 ≤ A, B, C, D ≤ 10¹⁸, B ≠ 0) 

Closed due to the fact that the essence of the question is incomprehensible by the participants of Artem Konovalov , Vladimir Martyanov , fori1ton , Streletz , Kromster 14 Oct '16 at 10:57 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • one
    Find. What's the question? ) - Kromster

2 answers 2

 A < B*x + C ≤ D => (A - C) < B*x ≤ (D - C) => (A - C)/B < x ≤ (D - C)/B => [x - целое] => ⌈(A - C)/B⌉ ≤ x ≤ ⌊(D - C)/B⌋ => #x = max (⌊(D - C)/B⌋ - ⌈(A - C)/B⌉ + 1, 0). 

    @pavel has already described the algorithm for you. If you are interested in java , then I give the option.

     //Исходные данные double A = 10.5; double B = 10; double C = 5; double D = 1000; double xleft = Math.ceil((AC)/B); double xright = Math.floor((DC)/B); int xcount = (int)(xright - xleft + 1); if (xcount < 0) xcount = 0; 

    The variant is primitive, but I think should help.

    • in double / int you can't do this, just long ... - pavel
    • I do not argue that the option is not the most successful, it was necessary to leave already when I wrote. In addition, the author did not indicate to which set A, B, C, D belong to him, I decided that these are real numbers. As for the rest, yes, long is needed. - Evgenii Izhboldin