Divide Two Numbers Using Long Division Your challenge is to divide two numbers using long division. The method we used to use in old days of school to divide two numbers.  

Example here
You should NOT use / or any other division operator in your code.

Also, this is not ascii-art  

Example:  

Input  : 4 2 (4 divided by 2)  

Output : 2 0 (here 2 is quotient and 0 is remainder)  


Another example  

Input  : 7182 15 (7182 divided by 15)  

Output : 478 12 (7170 is quotient and 12 is remainder)


The answer with most up-votes after 24 hours wins because this is a popularity contest.
C

Not exactly a long division - this answer uses the method used in the real old days.

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
int main() {
    int a,b;
    scanf("%d %d", &amp;a, &amp;b);
    int *p=calloc(b, sizeof(int));
    int *q=p;
    while(a--) {
        (*p)++;
        if(p-q&lt;b-1) p++;
        else p-=b-1;
    }
    p=q;
    int r=0, i;
    for(i=0; i&lt;b; i++) r+=p[i]-p[b-1];
    printf("%d %d\n", p[b-1], r);
    return 0;
}


Explanation:

Suppose you are given a number of sheep and you need to split them up into b number of groups. The method used here is to assign each sheep into a different group until the total number of groups reaches b, then start from the first group again. This repeats until there are no more sheep. Then, the quotient will be the number of sheep in the last group, and the remainder will be the sum of the differences between each group and the last group.

An illustration for 8/3:

       |Group 1 | Group 2 | Group 3
-------------------------------------
       | 1      | 2       | 3        // first sheep in group 1, second sheep in group 2, etc
       | 4      | 5       | 6
       | 7      | 8       |
-------------------------------------
total: | 3      | 3       | 2


So the quotient is 2 and the remainder is (3-2)+(3-2)=2.