The subject requires a A/b, where A is a positive integer that does not exceed 1000 bits, and B is a 1-bit positive integer. You need to output the quotient Q and the remainder r so that a = B * Q + R is set up.
Input format:
The input is given a and B in 1 rows, and the middle is separated by 1 spaces.
Output format:
In 1 rows, output Q and R in turn, separated by 1 spaces in the middle.
Input Sample:
123456789050987654321 7
Sample output:
17636684150141093474 3
Large numbers are modeled, and large numbers are in addition to a decimal.
One-by-one modulo (except).
#include <iostream>#include<algorithm>#include<cstring>#include<cstdio>#include<cctype>#include<cstdlib>#include<stack>#include<cmath>#include<string>#include<queue>#defineINF 65535using namespacestd;intMain () {Chara[1100], q[1100]; intB, R, I, j, length, sum; scanf ("%s", A); scanf ("%d", &B); Length=strlen (A); Sum=0; for(i =0, j =0; i < length; i + +) {sum=Ten* sum + a[i]-'0'; if(i = =0&& Sum < B && length >1) { } Else{q[j+ +] = sum/b +'0'; } Sum= Sum%B; } R=sum; Q[J]=' /'; printf ("%s%d", Q, R); return 0;}
ACM Topic ———— A divided by B