• Loading...

Problem 4: Multiplication

The task is simple. Given 2 integers A and B, find A*B.


Input:

The first line of input contains the number of test cases T.
Each of the next T lines contains two integers A and B separated by spaces.


Output:

For each of the T cases, output A*B in a new line.


Constraints:

T<30
A=32-bit integer
0<=B<=20


Sample Input:



2

3 4

1 0


Output:



12

0


Score:

C: Number of non-whitespace characters
M: Number of * and / characters
L: Number of loops i.e. for, while and do-while
I: Number of if-else, ternary and goto

T=30000/(C + 3000*M + L^10 + 1000*I)


Solution:

The easy task of multiplication A and B can be performed by:

  1. Directly using A*B.
  2. B times addition of A.
    1. B times addition can be performed by a loop.
    2. Or, by use of a recursion:
      a,b,s=0;
      multiply()
      {
      	switch(b) case 0 :return;
      	s+=a;
      	b--;
      	multiply();
      }

      Here, a*b is stored in s.
  3. Small loops can be replaced with switch statements, like if s=some int, and we know b<=4, then:
    switch(b)
    {
      case 4:s+=a;
      case 3:s+=a;
      case 2:s+=a;
      case 1:s+=a;
    }

    Since, no break have been used in case statements. So, whenever 'b' matches with a case, then all case statements following are executed.

Solutions through 2(ii) and 3 score better for the given constraints.

Submit your solution

You need to be logged in to submit a solution.

discussions


There is no discussion yet. Feel free to ask an question you might have regarding this problem


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