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 :
- Use modulus operator(%) to directly find the remainder. Ex:- A%B
- Subtract B from A till the value of A becomes less than B.
- Subtraction can be performed directly through '-' as A-B.
- Or, we can use '~' as A+(~B+1).
- First get the integral value of quotient, Q = A/B. Then remainder is A-Q*B.
- 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
| gurunglaxman0 | output? |
| 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 |
| shoubhikdn | solution? |
| 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} |
| anshulgupta | include 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. |
| chiranjeev | modulus 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 \"%\" |
| 1989gaurav | Modulo operator |
| Q: | does % in %d or %c would be counted as modulo operator? |
| A: | No,it won\'t be. |
| greed | Scoring? |
| 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...



