1017. A divided by B (20), 1017 divided
Calculate A/B, where A is A positive integer of no more than 1000 bits and B is A positive integer of 1 bits. You need to output the quotient Q and remainder R so that A = B * Q + R is established.
Input Format:
Enter A and B in the first line, and separate them with 1 space.
Output Format:
Output Q and R in one row, separated by 1 space in the middle.
Input example:
123456789050987654321 7
Output example:
17636684150141093474 3
1 #include <stdio.h> 2 #include <string.h> 3 int main(){ 4 char a[1000]={}; 5 int b=7; 6 int q[1000]={}; 7 int qn; 8 int r; 9 int yu=0;10 11 scanf("%s%d",a,&b);12 if(b<1||b>9 || a[0]=='0'){13 return 0;14 }15 for(int i=0;i<strlen(a);i++){16 if(i!=0 || ((a[i]-'0')/b)!=0){ 17 printf("%d",((a[i]-'0')+yu*10)/b); 18 }19 yu=((a[i]-'0')+yu*10)%b; 20 }21 if(strlen(a)==1 && (a[0]-'0')<b)22 printf("0");23 24 25 printf(" %d",yu);26 return 0;27 }