1017. A divided by B (20), 1017 divided

Source: Internet
Author: User

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 }

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.