• Loading...

Problem 1: Remainder

Find the remainder, when A is divided by B.


Input:

First line contains the number of test cases T.
Then T test cases follow. Each test case consists of two integers A and B separated by a single blank space character.


Output:

For each test case, output the remainder when A is divided by B in a new line.


Constraints:

T<15
0<A,B<=1000000


Sample Input:

4

1 4

23 5

44 10

24 4

Sample Output:


1

3

4

0

Score:

C: Total number of non-whitespace characters
P: Number of modulus operators
D: Number of * and /
N: Number of -

T= 15000/( C + 2000*P + 1000*D + 500*N)


Solution:

To get the remainder, when A is divided by B where both are positive integers, we can :

  1. Use modulus operator(%) to directly find the remainder. Ex:- A%B
  2. Subtract B from A till the value of A becomes less than B.
    1. Subtraction can be performed directly through '-' as A-B.
    2. Or, we can use '~' as A+(~B+1).
  3. First get the integral value of quotient, Q = A/B. Then remainder is A-Q*B.
  4. Use fmod(A,B) which returns the remainder when A is divided by B.

In the given problem, the solution through b(ii) and d suit the most to avoid constraints.
Check the Best Solutions

Submit your solution

You need to be logged in to submit a solution.

discussions


gurunglaxman0output?
Q:we hav to store d output in a file or just to show on scree?
A:YOu need to print the output on stdout. eg: using printf
shoubhikdnsolution?
Q:Should we submit the code as a normal C++ program starting from header file...If not can i have mock program???\\n
A:Only C files are acceptable. You are not allowed to include any header file. for eg:\r\nint main()\r\n{\r\nprintf(\"%d\\n\",2);\r\n}
anshulguptainclude files
Q:how can u write a program without using header files?
A:You don\'t need to use the header files.Compiling the code gives warnings which are being ignored.If the output is correct,the code is being accepted.
chiranjeevmodulus operators
Q:What is modulus operator ?
A:Modulus operators are those which give remainder when an integer is divided by another.\r\nIn C,the modulus operator is \"%\"
1989gauravModulo operator
Q:does % in %d or %c would be counted as modulo operator?
A:No,it won\'t be.
greedScoring?
Q:Which rule will be used for scoring?The one mentioned here or the one given at the home page of contest under \'rules\'?
A:The scoring mentioned on the rules page is just sample case. The scoring on problem page is the valid one.

post a question

Loading...

Trial 1
Trial 2
Trial 3
Trial 4
Submissions
Multipurpose
1000 pt
You are not logged in
0 / 170

Datatype
1000 pt
You are not logged in
0 / 308

No Bitwise
1000 pt
You are not logged in
0 / 78

Cuboid
1000 pt
You are not logged in
0 / 166

Evaluate the function
1000 pt
You are not logged in
0 / 94

Largest in the set
1000 pt
You are not logged in
0 / 69

2 to N
1000 pt
You are not logged in
0 / 144